Files
DP44/Common/DTS.Common.Serialization/File.Writer.cs
2026-04-17 14:55:32 -04:00

80 lines
2.7 KiB
C#

/*
* File.Writer.cs
*
* Copyright © 2009
* Diversified Technical Systems, Inc.
* All Rights Reserved
*/
using System.Text;
using DTS.Common.Utilities;
using DTS.Common.Utilities.DotNetProgrammingConstructs;
namespace DTS.Serialization
{
// *** see File.cs ***
public abstract partial class File
{ ///
/// <summary>
/// A class framework for a file writer. There can (and should) be several Write methods, one for
/// each type that can be written into the file format. But it must have at least one,
/// and that's what's outlined by this base implementation.
/// </summary>
///
/// <typeparam name="T">
/// The file type that this writer belongs to.
/// </typeparam>
///
public abstract partial class Writer<T> : Exceptional, IWriter
where T : File
{
protected int _defaultEncoding = Encoding.UTF8.CodePage;
public virtual int DefaultEncoding
{
get => _defaultEncoding;
set => _defaultEncoding = value;
}
///
/// <summary>
/// Initialize an instance of the DTS.Serialization.File.Writer class. This one-and-only
/// constructor is marked as "internal", implying that these types of object should only
/// be created by some factory method (intended to be in the hosting File object) and
/// then passed to the user.
/// </summary>
///
/// <param name="fileType">
/// The associated <see cref="DTS.Serialization.File"/>-based class.
/// </param>
///
public Writer(T fileType, int encoding)
{
try
{
FileType = fileType;
DefaultEncoding = encoding;
}
catch (System.Exception ex)
{
throw new Exception("encountered problem constructing " + GetType().FullName, ex);
}
}
/// <summary>
/// Get the <see cref="DTS.Serialization.File"/>-type associated with this reader.
/// </summary>
protected T FileType
{
get => _FileType.Value;
private set => _FileType.Value = value;
}
private readonly Property<T> _FileType
= new Property<T>(
typeof(Reader<T>).Namespace + ".File.Reader.FileType",
null,
false
);
}
}
}