Clean up and comment code
This commit is contained in:
parent
e597cf0450
commit
1352eaae0d
@ -32,6 +32,9 @@ namespace UniversalEditor
|
||||
/// </summary>
|
||||
public class Association
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a collection of <see cref="Association" />s.
|
||||
/// </summary>
|
||||
public class AssociationCollection
|
||||
: System.Collections.ObjectModel.Collection<Association>
|
||||
{
|
||||
@ -40,24 +43,42 @@ namespace UniversalEditor
|
||||
|
||||
private static List<Association> _associations = new List<Association>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Registers the specified <see cref="Association" /> if it is not already registered.
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> if the <see cref="Association" /> is not already registered and has been added; <c>false</c> otherwise.</returns>
|
||||
/// <param name="assoc">The <see cref="Association" /> to register.</param>
|
||||
public static bool Register(Association assoc)
|
||||
{
|
||||
if (_associations.Contains(assoc)) return false;
|
||||
_associations.Add(assoc);
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Unregisters the specified <see cref="Association" /> if it has been registered.
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> if the given <see cref="Association" /> has been unregistered; <c>false</c> if the given <see cref="Association" /> has not been registered.</returns>
|
||||
/// <param name="assoc">The <see cref="Association" /> to unregister.</param>
|
||||
public static bool Unregister(Association assoc)
|
||||
{
|
||||
if (!_associations.Contains(assoc)) return false;
|
||||
_associations.Remove(assoc);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an array of all known <see cref="Association" />s.
|
||||
/// </summary>
|
||||
/// <returns>The all associations.</returns>
|
||||
public static Association[] GetAllAssociations()
|
||||
{
|
||||
return _associations.ToArray();
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets an array of <see cref="Association" />s that match the given <see cref="ObjectModelReference" /> or <see cref="DataFormatReference" />.
|
||||
/// </summary>
|
||||
/// <returns>An array of <see cref="Association" />s that match the given <see cref="ObjectModelReference" /> or <see cref="DataFormatReference" />.</returns>
|
||||
/// <param name="objectModel">The <see cref="ObjectModelReference" /> to compare.</param>
|
||||
/// <param name="dataFormat">The <see cref="DataformatReference" /> to compare.</param>
|
||||
public static Association[] FromObjectModelOrDataFormat(ObjectModelReference objectModel = null, DataFormatReference dataFormat = null)
|
||||
{
|
||||
Association[] _associations = Association.GetAllAssociations();
|
||||
@ -71,11 +92,18 @@ namespace UniversalEditor
|
||||
}
|
||||
return associations.ToArray();
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets an array of <see cref="Association" />s that match the given <see cref="Accessor" /> or file name filters.
|
||||
/// </summary>
|
||||
/// <returns>An array of <see cref="Association" />s that match the given <see cref="Accessor" /> or file name filters.</returns>
|
||||
/// <param name="accessor">The <see cref="Accessor" /> to compare.</param>
|
||||
/// <param name="fileNameFilter">Not implemented.</param>
|
||||
public static Association[] FromAccessor(Accessor accessor = null, string fileNameFilter = null)
|
||||
{
|
||||
Association[] assocs = Association.GetAllAssociations();
|
||||
List<Association> associations = new List<Association>();
|
||||
|
||||
// FIXME: the fileNameFilter parameter is not referenced in this method body
|
||||
// stopwatch diagnostics determined a nested for loop is 0.0547024 ms faster than foreach
|
||||
for (int i = 0; i < assocs.Length; i++)
|
||||
{
|
||||
@ -120,6 +148,10 @@ namespace UniversalEditor
|
||||
/// </summary>
|
||||
public DataFormatReference.DataFormatReferenceCollection DataFormats { get { return mvarDataFormats; } }
|
||||
|
||||
/// <summary>
|
||||
/// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:UniversalEditor.Association"/>.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="T:System.String"/> that represents the current <see cref="T:UniversalEditor.Association"/>.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@ -149,6 +181,11 @@ namespace UniversalEditor
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an array of <see cref="Association" />s that satisfy the given <see cref="AssociationCriteria" />.
|
||||
/// </summary>
|
||||
/// <returns>An array of <see cref="Association" />s that match the specified criteria.</returns>
|
||||
/// <param name="ac">The <see cref="AssociationCriteria" /> that define the criteria to match when searching for <see cref="Association"/>s.</param>
|
||||
public static Association[] FromCriteria(AssociationCriteria ac)
|
||||
{
|
||||
List<Association> associations = new List<Association>();
|
||||
|
||||
@ -28,8 +28,14 @@ using UniversalEditor.IO;
|
||||
|
||||
namespace UniversalEditor
|
||||
{
|
||||
/// <summary>
|
||||
/// The on-disk representation of data stored in an <see cref="ObjectModel" /> and accessed by an <see cref="Accessor" />.
|
||||
/// </summary>
|
||||
public abstract class DataFormat : References<DataFormatReference>
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a collection of <see cref="DataFormat" /> objects.
|
||||
/// </summary>
|
||||
public class DataFormatCollection
|
||||
: System.Collections.ObjectModel.Collection<DataFormat>
|
||||
{
|
||||
@ -45,20 +51,34 @@ namespace UniversalEditor
|
||||
get { return mvarReference; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="DataFormatReference" /> for this <see cref="DataFormat" /> and registers it for future use.
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="DataFormatReference" /> that provides metadata and other information about this <see cref="DataFormat" />.</returns>
|
||||
public DataFormatReference MakeReference()
|
||||
{
|
||||
DataFormatReference dfr = MakeReferenceInternal();
|
||||
DataFormatReference.Register(dfr);
|
||||
return dfr;
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="DataFormatReference" />. The returned <see cref="DataFormatReference" /> is not cached. It is recommended that subclasses
|
||||
/// override this method and cache their own personal instances of <see cref="DataFormatReference" /> containing the appropriate metadata for their
|
||||
/// subclassed implementations.
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="DataFormatReference" /> that provides metadata and other information about this <see cref="DataFormat" />.</returns>
|
||||
protected virtual DataFormatReference MakeReferenceInternal()
|
||||
{
|
||||
DataFormatReference dfr = new DataFormatReference(GetType());
|
||||
return dfr;
|
||||
}
|
||||
|
||||
private Accessor mvarAccessor = null;
|
||||
protected internal Accessor Accessor { get { return mvarAccessor; } set { mvarAccessor = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="Accessor" /> used to read and write data.
|
||||
/// </summary>
|
||||
/// <value>The <see cref="Accessor" /> used to read and write data.</value>
|
||||
[Obsolete("In next version, Accessor will be a parameter passed into LoadInternal / SaveInternal methods")]
|
||||
protected internal Accessor Accessor { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Continues loading the file into the specified <see cref="ObjectModel" /> with a different
|
||||
@ -68,10 +88,15 @@ namespace UniversalEditor
|
||||
/// <param name="otherDataFormat">The <see cref="DataFormat" /> used to parse the document.</param>
|
||||
protected void ContinueLoading(ref ObjectModel objectModel, DataFormat otherDataFormat)
|
||||
{
|
||||
otherDataFormat.Accessor = mvarAccessor;
|
||||
otherDataFormat.Accessor = Accessor;
|
||||
otherDataFormat.Load(ref objectModel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the given <see cref="ObjectModel" /> is supported by this <see cref="DataFormat" />.
|
||||
/// </summary>
|
||||
/// <returns><c>true</c>, if the specified <see cref="ObjectModel" /> is supported by this <see cref="DataFormat" />, <c>false</c> otherwise.</returns>
|
||||
/// <param name="objectModel">The <see cref="ObjectModel" /> whose support should be checked.</param>
|
||||
protected virtual bool IsObjectModelSupported(ObjectModel objectModel)
|
||||
{
|
||||
DataFormatReference dfr = MakeReferenceInternal();
|
||||
@ -79,6 +104,26 @@ namespace UniversalEditor
|
||||
return dfr.Capabilities.Contains(omr.Type) || dfr.Capabilities.Contains(omr.ID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the contents of the specified <see cref="ObjectModel" /> from the <see cref="Accessor" /> using this <see cref="DataFormat" />.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// Before the actual content is read using this <see cref="DataFormat" />'s <see cref="LoadInternal" /> method, a <see cref="Stack{ObjectModel}" /> is
|
||||
/// created and the specified <see cref="ObjectModel" /> is pushed onto the stack. The <see cref="BeforeLoadInternal" /> method is then called, with the
|
||||
/// stack as its only parameter. A single <see cref="ObjectModel" /> is then popped off the stack, and the <see cref="LoadInternal" /> method is called
|
||||
/// with this <see cref="ObjectModel"/> as its only parameter. After the actual content is read, the <see cref="AfterLoadInternal" /> method is called,
|
||||
/// again passing in the stack as its only parameter.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Note that the <see cref="ObjectModel" /> passed into the <see cref="Load" /> method may not necessarily be the same as the <see cref="ObjectModel" />
|
||||
/// that is eventually passed into the <see cref="LoadInternal" /> method. It is possible to subclass <see cref="DataFormat" />s to create new formats
|
||||
/// based on existing ones. XML, ZIP, and RIFF are a few good examples of <see cref="DataFormat" />s that serve as the base for others. For more
|
||||
/// information, refer to the documentation for the <see cref="BeforeLoadInternal" />, <see cref="AfterLoadInternal" />, and
|
||||
/// <see cref="BeforeSaveInternal" /> methods.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <param name="objectModel">The <see cref="ObjectModel" /> whose content should be written using this <see cref="DataFormat" />.</param>
|
||||
[DebuggerNonUserCode()]
|
||||
public void Load(ref ObjectModel objectModel)
|
||||
{
|
||||
@ -99,9 +144,29 @@ namespace UniversalEditor
|
||||
*/
|
||||
AfterLoadInternal(stack);
|
||||
}
|
||||
/// <summary>
|
||||
/// Writes the contents of the specified <see cref="ObjectModel" /> to the <see cref="Accessor" /> using this <see cref="DataFormat" />.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// Before the actual content is written using this <see cref="DataFormat" />'s <see cref="SaveInternal" /> method, a <see cref="Stack{ObjectModel}" /> is
|
||||
/// created and the specified <see cref="ObjectModel" /> is pushed onto the stack. The <see cref="BeforeSaveInternal" /> method is then called, with the
|
||||
/// stack as its only parameter. A single <see cref="ObjectModel" /> is then popped off the stack, and the <see cref="SaveInternal" /> method is called
|
||||
/// with this <see cref="ObjectModel"/> as its only parameter. After the actual content is written, the <see cref="AfterSaveInternal" /> method is called,
|
||||
/// again passing in the stack as its only parameter.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Note that the <see cref="ObjectModel" /> passed into the <see cref="Save" /> method may not necessarily be the same as the <see cref="ObjectModel" />
|
||||
/// that is eventually passed into the <see cref="SaveInternal" /> method. It is possible to subclass <see cref="DataFormat" />s to create new formats
|
||||
/// based on existing ones. XML, ZIP, and RIFF are a few good examples of <see cref="DataFormat" />s that serve as the base for others. For more
|
||||
/// information, refer to the documentation for the <see cref="BeforeLoadInternal" />, <see cref="AfterLoadInternal" />, and
|
||||
/// <see cref="BeforeSaveInternal" /> methods.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <param name="objectModel">The <see cref="ObjectModel" /> whose content should be written using this <see cref="DataFormat" />.</param>
|
||||
public void Save(ObjectModel objectModel)
|
||||
{
|
||||
if (objectModel == null) throw new ArgumentNullException("objectModel", "objectModel cannot be null");
|
||||
if (objectModel == null) throw new ArgumentNullException(nameof(objectModel), "objectModel cannot be null");
|
||||
|
||||
Stack<ObjectModel> stack = new Stack<ObjectModel>();
|
||||
stack.Push(objectModel);
|
||||
@ -114,18 +179,83 @@ namespace UniversalEditor
|
||||
AfterSaveInternal(stack);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the data from the <see cref="Accessor" /> into the specified <see cref="ObjectModel" />.
|
||||
/// </summary>
|
||||
/// <param name="objectModel">The <see cref="ObjectModel" /> into which to load data.</param>
|
||||
protected abstract void LoadInternal(ref ObjectModel objectModel);
|
||||
/// <summary>
|
||||
/// Writes the contents of the specified <see cref="ObjectModel" /> to the <see cref="Accessor" />.
|
||||
/// </summary>
|
||||
/// <param name="objectModel">The <see cref="ObjectModel" /> from which to save data.</param>
|
||||
protected abstract void SaveInternal(ObjectModel objectModel);
|
||||
|
||||
/// <summary>
|
||||
/// Method called BEFORE the <see cref="LoadInternal" /> method is called on the original <see cref="DataFormat" />'s subclass.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// When inheriting from a
|
||||
/// <see cref="DataFormat" /> subclass (e.g. XMLDataFormat), you need to create a new instance of the appropriate <see cref="ObjectModel" /> that the
|
||||
/// subclass expects, and push that onto the <paramref name="objectModels"/> stack, i.e. <code>objectModels.Push(new MarkupObjectModel());</code> This is
|
||||
/// usually the only line of code in the overridden <see cref="BeforeLoadInternal" /> method's body.
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// objectModels.Push(new BaseObjectModel()); // this is all we need to do
|
||||
/// </example>
|
||||
/// <param name="objectModels">The stack of <see cref="ObjectModel"/>s used by this <see cref="DataFormat" />.</param>
|
||||
protected virtual void BeforeLoadInternal(Stack<ObjectModel> objectModels)
|
||||
{
|
||||
}
|
||||
/// <summary>
|
||||
/// Method called AFTER the <see cref="LoadInternal"/> method is called on the original <see cref="DataFormat" />'s subclass.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// When inheriting from a <see cref="DataFormat" /> subclass (e.g. XMLDataFormat), you need to first pop the <see cref="ObjectModel" /> that you pushed
|
||||
/// onto the <paramref name="objectModels"/> stack in your <see cref="BeforeLoadInternal" /> implementation, then pop the <see cref="ObjectModel" /> that
|
||||
/// your class expects to get passed. Now you can read data from the original <see cref="ObjectModel" /> and modify the second <see cref="ObjectModel" />.
|
||||
/// Because these objects are passed by reference, you do not need to push them back onto the stack for them to get properly loaded.
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// BaseObjectModel bom = (objectModels.Pop() as BaseObjectModel); // base object model comes first
|
||||
/// MyVerySpecificObjectModel myOM = (objectModels.Pop() as MyVerySpecificObjectModel);
|
||||
///
|
||||
/// // populate MyVerySpecificObjectModel... and we're done. nothing else needs to be pushed back onto the stack.
|
||||
/// </example>
|
||||
/// <param name="objectModels">The stack of <see cref="ObjectModel"/>s used by this <see cref="DataFormat" />.</param>
|
||||
protected virtual void AfterLoadInternal(Stack<ObjectModel> objectModels)
|
||||
{
|
||||
}
|
||||
/// <summary>
|
||||
/// Method called BEFORE the <see cref="SaveInternal"/> method is called on the original <see cref="DataFormat" />'s subclass.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// When inheriting from a <see cref="DataFormat" /> subclass (e.g. XMLDataFormat), you need to first pop the <see cref="ObjectModel" /> that your class
|
||||
/// expects to get passed, then create a new instance of the proper type of <see cref="ObjectModel" /> the base class is expecting. Now you can retrieve
|
||||
/// data from the <see cref="ObjectModel" /> that your class expects and properly format it for the <see cref="ObjectModel" /> the base class expects.
|
||||
/// When you're done, you need to push the newly-created <see cref="ObjectModel" /> onto the stack so that the underlying <see cref="SaveInternal" />
|
||||
/// method will be able to see it.
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// MyVerySpecificObjectModel myOM = (objectModels.Pop() as MyVerySpecificObjectModel);
|
||||
/// BaseObjectModel bom = new BaseObjectModel();
|
||||
///
|
||||
/// // populate BaseObjectModel...
|
||||
///
|
||||
/// objectModels.Push(bom); // aaand we're done
|
||||
/// </example>
|
||||
/// <param name="objectModels">The stack of <see cref="ObjectModel"/>s used by this <see cref="DataFormat" />.</param>
|
||||
protected virtual void BeforeSaveInternal(Stack<ObjectModel> objectModels)
|
||||
{
|
||||
}
|
||||
/// <summary>
|
||||
/// Method called AFTER the <see cref="SaveInternal"/> method is called on the original <see cref="DataFormat" />'s subclass.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Although this method does get called after the <see cref="SaveInternal" /> method is called, there does not seem to be any reason to actually use it.
|
||||
/// The standard practice of inheriting <see cref="DataFormat" />s utilizes the <see cref="BeforeLoadInternal" />, <see cref="AfterLoadInternal" />, and
|
||||
/// <see cref="BeforeSaveInternal" /> methods.
|
||||
/// </remarks>
|
||||
/// <param name="objectModels">The stack of <see cref="ObjectModel"/>s used by this <see cref="DataFormat" />.</param>
|
||||
protected virtual void AfterSaveInternal(Stack<ObjectModel> objectModels)
|
||||
{
|
||||
}
|
||||
|
||||
@ -25,45 +25,95 @@ using System.Text;
|
||||
|
||||
namespace UniversalEditor
|
||||
{
|
||||
/// <summary>
|
||||
/// The in-memory representation of data serialized to and from an <see cref="Accessor" /> using a particular <see cref="DataFormat" />.
|
||||
/// </summary>
|
||||
public abstract class ObjectModel : ICloneable, References<ObjectModelReference>
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a collection of <see cref="ObjectModel" /> objects.
|
||||
/// </summary>
|
||||
public class ObjectModelCollection
|
||||
: System.Collections.ObjectModel.Collection<ObjectModel>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="ObjectModelReference" /> for this <see cref="ObjectModel" /> and registers it for future use.
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="ObjectModelReference" /> that provides metadata and other information about this <see cref="ObjectModel" />.</returns>
|
||||
public ObjectModelReference MakeReference()
|
||||
{
|
||||
ObjectModelReference omr = MakeReferenceInternal();
|
||||
ObjectModelReference.Register(omr);
|
||||
return omr;
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ObjectModelReference" />. The returned <see cref="ObjectModelReference" /> is not cached. It is recommended that subclasses
|
||||
/// override this method and cache their own personal instances of <see cref="ObjectModelReference" /> containing the appropriate metadata for their
|
||||
/// subclassed implementations.
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="ObjectModelReference" /> that provides metadata and other information about this <see cref="ObjectModel" />.</returns>
|
||||
protected virtual ObjectModelReference MakeReferenceInternal()
|
||||
{
|
||||
ObjectModelReference omr = new ObjectModelReference(GetType());
|
||||
return omr;
|
||||
}
|
||||
|
||||
private Accessor mvarAccessor = null;
|
||||
public Accessor Accessor { get { return mvarAccessor; } internal set { mvarAccessor = value; } }
|
||||
/// <summary>
|
||||
/// The <see cref="Accessor" /> that was last used to read or write this <see cref="ObjectModel" />.
|
||||
/// </summary>
|
||||
/// <value>The accessor.</value>
|
||||
[Obsolete("ObjectModels should be Accessor-agnostic and not rely on being able to communicate with the Accessor")]
|
||||
public Accessor Accessor { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Clears all data from this <see cref="ObjectModel" /> and returns it to a pristine state.
|
||||
/// </summary>
|
||||
public abstract void Clear();
|
||||
/// <summary>
|
||||
/// Copies all data from this <see cref="ObjectModel" /> to the specified <see cref="ObjectModel" />.
|
||||
/// </summary>
|
||||
/// <param name="where">The <see cref="ObjectModel" /> into which to copy the data of this <see cref="ObjectModel" />.</param>
|
||||
/// <exception cref="ObjectModelNotSupportedException">The conversion between this <see cref="ObjectModel" /> and the given <see cref="ObjectModel" /> is not supported.</exception>
|
||||
public abstract void CopyTo(ObjectModel where);
|
||||
/// <summary>
|
||||
/// Copies all data from this <see cref="ObjectModel" /> to the specified <see cref="ObjectModel" />.
|
||||
/// </summary>
|
||||
/// <param name="where">The <see cref="ObjectModel" /> into which to copy the data of this <see cref="ObjectModel" />.</param>
|
||||
/// <param name="append">When <c>false</c>, the <see cref="Clear" /> method is called on the destination <see cref="ObjectModel" /> before the copy is performed.</param>
|
||||
/// <exception cref="ObjectModelNotSupportedException">The conversion between this <see cref="ObjectModel" /> and the given <see cref="ObjectModel" /> is not supported.</exception>
|
||||
public void CopyTo(ObjectModel where, bool append)
|
||||
{
|
||||
if (!append) where.Clear();
|
||||
CopyTo(where);
|
||||
}
|
||||
/// <summary>
|
||||
/// Copies all data from the given <see cref="ObjectModel" /> into this <see cref="ObjectModel" />.
|
||||
/// </summary>
|
||||
/// <param name="where">The <see cref="ObjectModel" /> from which to copy the data.</param>
|
||||
/// <exception cref="ObjectModelNotSupportedException">The conversion between this <see cref="ObjectModel" /> and the given <see cref="ObjectModel" /> is not supported.</exception>
|
||||
public void CopyFrom(ObjectModel where)
|
||||
{
|
||||
where.CopyTo(this);
|
||||
}
|
||||
/// <summary>
|
||||
/// Copies all data from the given <see cref="ObjectModel" /> into this <see cref="ObjectModel" />.
|
||||
/// </summary>
|
||||
/// <param name="where">The <see cref="ObjectModel" /> from which to copy the data.</param>
|
||||
/// <param name="append">When <c>false</c>, the <see cref="Clear" /> method is called on this <see cref="ObjectModel" /> before the copy is performed.</param>
|
||||
/// <exception cref="ObjectModelNotSupportedException">The conversion between this <see cref="ObjectModel" /> and the given <see cref="ObjectModel" /> is not supported.</exception>
|
||||
public void CopyFrom(ObjectModel where, bool append)
|
||||
{
|
||||
if (!append) Clear();
|
||||
CopyFrom(where);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates a clone of this <see cref="ObjectModel" /> and returns it. This is normally implemented as creating a new instance of this
|
||||
/// <see cref="ObjectModel" />, then calling the original instance's <see cref="CopyTo(ObjectModel)" /> method passing in the new instance as the target.
|
||||
/// </summary>
|
||||
/// <returns>The cloned <see cref="ObjectModel" />.</returns>
|
||||
public object Clone()
|
||||
{
|
||||
Type type = this.GetType();
|
||||
@ -72,6 +122,12 @@ namespace UniversalEditor
|
||||
return clone;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs a simple find and replace on the public properties of this <see cref="ObjectModel" /> using reflection. For a more in-depth find and replace
|
||||
/// solution, individual <see cref="ObjectModel" /> authors should annotate individual parameters that should participate in the find-and-replace feature.
|
||||
/// </summary>
|
||||
/// <param name="FindWhat">The string to search for.</param>
|
||||
/// <param name="ReplaceWith">The string with which the found string should be replaced.</param>
|
||||
public virtual void Replace(string FindWhat, string ReplaceWith)
|
||||
{
|
||||
Type type = GetType();
|
||||
@ -88,6 +144,17 @@ namespace UniversalEditor
|
||||
}
|
||||
|
||||
private Dictionary<DataFormatReference, Dictionary<string, object>> _customProperties = new Dictionary<DataFormatReference, Dictionary<string, object>>();
|
||||
|
||||
// TODO: should this use the MBS.Framework "ISupportsExtraData" interface? Or is this specifically UE functionality (with DataFormatReference)?
|
||||
/// <summary>
|
||||
/// Gets the value of the custom property with the specified name for the given <see cref="DataFormatReference" />. If no custom property with the given
|
||||
/// name is registered for the specified <see cref="DataFormatReference" />, return the value specified as <paramref name="defaultValue" />.
|
||||
/// </summary>
|
||||
/// <returns>The value of the custom property with the specified name for the given <see cref="DataFormatReference" />.</returns>
|
||||
/// <param name="dfr">The <see cref="DataFormatReference" /> for which to look up custom properties.</param>
|
||||
/// <param name="name">The name of the custom property to search for.</param>
|
||||
/// <param name="defaultValue">The value that should be returned if no custom property with the given name is registered for the specified <see cref="DataFormatReference" />.</param>
|
||||
/// <typeparam name="T">The type of custom property that should be returned.</typeparam>
|
||||
public T GetCustomProperty<T>(DataFormatReference dfr, string name, T defaultValue = default(T))
|
||||
{
|
||||
if (_customProperties.ContainsKey(dfr))
|
||||
@ -99,10 +166,26 @@ namespace UniversalEditor
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the value of the custom property with the specified name for the given <see cref="DataFormatReference" />. If no custom property with the given
|
||||
/// name is registered for the specified <see cref="DataFormatReference" />, return the value specified as <paramref name="defaultValue" />.
|
||||
/// </summary>
|
||||
/// <returns>The value of the custom property with the specified name for the given <see cref="DataFormatReference" />.</returns>
|
||||
/// <param name="dfr">The <see cref="DataFormatReference" /> for which to look up custom properties.</param>
|
||||
/// <param name="name">The name of the custom property to search for.</param>
|
||||
/// <param name="defaultValue">The value that should be returned if no custom property with the given name is registered for the specified <see cref="DataFormatReference" />.</param>
|
||||
public object GetCustomProperty(DataFormatReference dfr, string name, object defaultValue = null)
|
||||
{
|
||||
return GetCustomProperty<object>(dfr, name, defaultValue);
|
||||
}
|
||||
/// <summary>
|
||||
/// Sets the value of the custom property with the specified name for the given <see cref="DataFormatReference" />. If no custom property with the given
|
||||
/// name is registered for the specified <see cref="DataFormatReference" />, a new property is registered.
|
||||
/// </summary>
|
||||
/// <param name="dfr">The <see cref="DataFormatReference" /> for which to look up or register custom properties.</param>
|
||||
/// <param name="name">The name of the custom property to set.</param>
|
||||
/// <param name="value">The value that should be assigned to the property.</param>
|
||||
/// <typeparam name="T">The type of custom property that should be set.</typeparam>
|
||||
public void SetCustomProperty<T>(DataFormatReference dfr, string name, T value)
|
||||
{
|
||||
if (!_customProperties.ContainsKey(dfr))
|
||||
@ -111,6 +194,13 @@ namespace UniversalEditor
|
||||
}
|
||||
_customProperties[dfr][name] = value;
|
||||
}
|
||||
/// <summary>
|
||||
/// Sets the value of the custom property with the specified name for the given <see cref="DataFormatReference" />. If no custom property with the given
|
||||
/// name is registered for the specified <see cref="DataFormatReference" />, a new property is registered.
|
||||
/// </summary>
|
||||
/// <param name="dfr">The <see cref="DataFormatReference" /> for which to look up or register custom properties.</param>
|
||||
/// <param name="name">The name of the custom property to set.</param>
|
||||
/// <param name="value">The value that should be assigned to the property.</param>
|
||||
public void SetCustomProperty(DataFormatReference dfr, string name, object value)
|
||||
{
|
||||
SetCustomProperty<object>(dfr, name, value);
|
||||
|
||||
@ -6,19 +6,35 @@ using System.Text;
|
||||
|
||||
namespace UniversalEditor.UserInterface
|
||||
{
|
||||
/// <summary>
|
||||
/// The event handler that is raised when an <see cref="ObjectModel" /> is changed, e.g. on an <see cref="Editor" />.
|
||||
/// </summary>
|
||||
public delegate void ObjectModelChangingEventHandler(object sender, ObjectModelChangingEventArgs e);
|
||||
/// <summary>
|
||||
/// The <see cref="EventArgs" /> used with the <see cref="ObjectModelChangingEventHandler" />.
|
||||
/// </summary>
|
||||
public class ObjectModelChangingEventArgs : CancelEventArgs
|
||||
{
|
||||
private ObjectModel mvarOldObjectModel = null;
|
||||
public ObjectModel OldObjectModel { get { return mvarOldObjectModel; } }
|
||||
|
||||
private ObjectModel mvarNewObjectModel = null;
|
||||
public ObjectModel NewObjectModel { get { return mvarNewObjectModel; } set { mvarNewObjectModel = value; } }
|
||||
/// <summary>
|
||||
/// The original <see cref="ObjectModel" /> before the change occurs.
|
||||
/// </summary>
|
||||
/// <value>The original <see cref="ObjectModel" /> before the change occurs.</value>
|
||||
public ObjectModel OldObjectModel { get; private set; }
|
||||
/// <summary>
|
||||
/// The current <see cref="ObjectModel" /> after the change occurs.
|
||||
/// </summary>
|
||||
/// <value>The current <see cref="ObjectModel" /> after the change occurs.</value>
|
||||
public ObjectModel NewObjectModel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ObjectModelChangingEventArgs"/> class with the given old <see cref="ObjectModel" /> and new <see cref="ObjectModel" />.
|
||||
/// </summary>
|
||||
/// <param name="oldObjectModel">The original <see cref="ObjectModel" /> before the change occurs.</param>
|
||||
/// <param name="newObjectModel">The current <see cref="ObjectModel" /> after the change occurs.</param>
|
||||
public ObjectModelChangingEventArgs(ObjectModel oldObjectModel, ObjectModel newObjectModel)
|
||||
{
|
||||
mvarOldObjectModel = oldObjectModel;
|
||||
mvarNewObjectModel = newObjectModel;
|
||||
OldObjectModel = oldObjectModel;
|
||||
NewObjectModel = newObjectModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user