using System;
using System.Runtime.Serialization;
namespace Neo.Afx.ComponentModel
{
///
/// An object that represents a file.
///
[Serializable]
public class FileObject : ISerializable
{
long _id = -1;
string _name;
string _extension;
string _fullName;
long _length;
byte[] _content;
string _mimeType;
string _uri;
#region Initialization
///
/// Initializes a new instance of the class.
///
public FileObject()
{
}
///
/// Initializes a new instance of the class.
///
/// The SerializationInfo to populate with data.
/// The destination for this serialization.
public FileObject(SerializationInfo info, StreamingContext context)
{
_id = info.GetInt64("ID");
_name = info.GetString("Name");
_extension = info.GetString("Extension");
_fullName = info.GetString("FullName");
_length = info.GetInt64("Length");
_content = (byte[])info.GetValue("Content", typeof(byte[]));
_mimeType = info.GetString("MimeType");
_uri = info.GetString("Uri");
}
#endregion
#region ISerializable Members
///
/// Populates a SerializationInfo with the data needed to serialize the target object.
///
/// The SerializationInfo to populate with data.
/// The destination for this serialization.
/// The caller does not have the required permission.
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("ID", ID);
info.AddValue("Name", Name);
info.AddValue("Extension", Extension);
info.AddValue("FullName", FullName);
info.AddValue("Length", Length);
info.AddValue("Content", Content);
info.AddValue("MimeType", MimeType);
info.AddValue("Uri", Uri);
}
#endregion
#region Custom Properties
///
/// Gets or sets the ID of the file.
///
public long ID
{
get
{
return _id;
}
set
{
_id = value;
}
}
///
/// Gets or sets the full path of the file.
///
public string FullName
{
get
{
return _fullName;
}
set
{
_fullName = value;
}
}
///
/// Gets or sets the name of the file.
///
public string Name
{
get
{
return _name;
}
set
{
_name = value;
}
}
///
/// Gets or sets the string representing the extension part of the file.
///
public string Extension
{
get
{
return _extension;
}
set
{
_extension = value;
}
}
///
/// Gets or sets the size of the file.
///
public long Length
{
get
{
return _length;
}
set
{
_length = value;
}
}
///
/// Gets or sets the MIME type of the file.
///
public string MimeType
{
get
{
return _mimeType;
}
set
{
_mimeType = value;
}
}
///
/// Gets or sets a byte array containing the contents of the file.
///
public byte[] Content
{
get
{
return _content;
}
set
{
_content = value;
}
}
///
/// Gets or sets the Uri containing the path of the file.
///
public string Uri
{
get
{
return _uri;
}
set
{
_uri = value;
}
}
#endregion
}
}