From 52042fbacd672accf65fd370591b760e7072a24c Mon Sep 17 00:00:00 2001 From: alcexhim Date: Tue, 30 Sep 2014 20:33:48 -0400 Subject: [PATCH] Moved ObjectModelReference into separate code file --- .../UniversalEditor.Core/ObjectModel.cs | 170 ----------------- .../ObjectModelReference.cs | 178 ++++++++++++++++++ 2 files changed, 178 insertions(+), 170 deletions(-) create mode 100644 CSharp/Libraries/UniversalEditor.Core/ObjectModelReference.cs diff --git a/CSharp/Libraries/UniversalEditor.Core/ObjectModel.cs b/CSharp/Libraries/UniversalEditor.Core/ObjectModel.cs index afd6c574..6df65256 100644 --- a/CSharp/Libraries/UniversalEditor.Core/ObjectModel.cs +++ b/CSharp/Libraries/UniversalEditor.Core/ObjectModel.cs @@ -54,174 +54,4 @@ namespace UniversalEditor } } } - public class ObjectModelReference - { - public class ObjectModelReferenceCollection - : System.Collections.ObjectModel.Collection - { - private Dictionary refsByID = new Dictionary(); - private Dictionary refsByType = new Dictionary(); - - public ObjectModelReference Add(Guid ID) - { - if (refsByID.ContainsKey(ID)) return refsByID[ID]; - - ObjectModelReference omr = new ObjectModelReference(ID); - refsByID.Add(ID, omr); - Add(omr); - return omr; - } - public ObjectModelReference Add(Type type) - { - if (refsByType.ContainsKey(type)) return refsByType[type]; - - ObjectModelReference omr = new ObjectModelReference(type); - refsByType.Add(type, omr); - Add(omr); - return omr; - } - - public ObjectModelReference this[Guid ID] - { - get - { - if (refsByID.ContainsKey(ID)) return refsByID[ID]; - return null; - } - } - public ObjectModelReference this[Type type] - { - get - { - if (refsByType.ContainsKey(type)) return refsByType[type]; - return null; - } - } - - public bool Contains(Guid ID) - { - return (refsByID.ContainsKey(ID)); - } - public bool Contains(Type type) - { - if (refsByType.Count == 0) - { - foreach (ObjectModelReference omr in this) - { - if (omr.ObjectModelType != null) - { - refsByType.Add(omr.ObjectModelType, omr); - } - } - } - return (refsByType.ContainsKey(type)); - } - } - - private string mvarObjectModelTypeName = null; - public string ObjectModelTypeName - { - get - { - if (mvarObjectModelTypeName != null) - { - return mvarObjectModelTypeName; - } - else if (mvarObjectModelType != null) - { - return mvarObjectModelType.FullName; - } - return null; - } - } - - private Type mvarObjectModelType = null; - public Type ObjectModelType { get { return mvarObjectModelType; } } - - private Guid mvarObjectModelID = Guid.Empty; - public Guid ObjectModelID { get { return mvarObjectModelID; } } - - private string mvarTitle = null; - public string Title { get { return mvarTitle; } set { mvarTitle = value; } } - - public string GetTitle() - { - if (mvarTitle != null) return mvarTitle; - if (mvarObjectModelType != null) return mvarObjectModelType.FullName; - return mvarObjectModelID.ToString("B"); - } - - private string[] mvarPath = null; - public string[] Path - { - get - { - if (mvarPath == null && mvarObjectModelType != null) - { - string[] sz = mvarObjectModelType.FullName.Split(new char[] { '.' }); - if (mvarTitle != null) - { - sz[sz.Length - 1] = mvarTitle; - } - return sz; - } - return mvarPath; - } - set { mvarPath = value; } - } - - public ObjectModelReference(Guid ID) - { - mvarObjectModelID = ID; - } - public ObjectModelReference(string TypeName) - { - mvarObjectModelTypeName = TypeName; - } - public ObjectModelReference(Type type) - { - if (!type.IsSubclassOf(typeof(ObjectModel))) - { - throw new InvalidCastException("Cannot create an object model reference to a non-ObjectModel type"); - } - else if (type.IsAbstract) - { - throw new InvalidOperationException("Cannot create an object model reference to an abstract type"); - } - - mvarObjectModelType = type; - mvarObjectModelTypeName = mvarObjectModelType.FullName; - } - public ObjectModelReference(Type type, Guid ID) - { - if (!type.IsSubclassOf(typeof(ObjectModel))) - { - throw new InvalidCastException("Cannot create an object model reference to a non-ObjectModel type"); - } - else if (type.IsAbstract) - { - throw new InvalidOperationException("Cannot create an object model reference to an abstract type"); - } - - mvarObjectModelType = type; - mvarObjectModelTypeName = mvarObjectModelType.FullName; - mvarObjectModelID = ID; - } - - public ObjectModel Create() - { - if (mvarObjectModelType == null && mvarObjectModelTypeName != null) - { - mvarObjectModelType = Type.GetType(mvarObjectModelTypeName); - } - if (mvarObjectModelType != null) - { - return (mvarObjectModelType.Assembly.CreateInstance(mvarObjectModelType.FullName) as ObjectModel); - } - return null; - } - - private string mvarDescription = String.Empty; - public string Description { get { return mvarDescription; } set { mvarDescription = value; } } - } } diff --git a/CSharp/Libraries/UniversalEditor.Core/ObjectModelReference.cs b/CSharp/Libraries/UniversalEditor.Core/ObjectModelReference.cs new file mode 100644 index 00000000..3e83c852 --- /dev/null +++ b/CSharp/Libraries/UniversalEditor.Core/ObjectModelReference.cs @@ -0,0 +1,178 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor +{ + public class ObjectModelReference + { + public class ObjectModelReferenceCollection + : System.Collections.ObjectModel.Collection + { + private Dictionary refsByID = new Dictionary(); + private Dictionary refsByType = new Dictionary(); + + public ObjectModelReference Add(Guid ID) + { + if (refsByID.ContainsKey(ID)) return refsByID[ID]; + + ObjectModelReference omr = new ObjectModelReference(ID); + refsByID.Add(ID, omr); + Add(omr); + return omr; + } + public ObjectModelReference Add(Type type) + { + if (refsByType.ContainsKey(type)) return refsByType[type]; + + ObjectModelReference omr = new ObjectModelReference(type); + refsByType.Add(type, omr); + Add(omr); + return omr; + } + + public ObjectModelReference this[Guid ID] + { + get + { + if (refsByID.ContainsKey(ID)) return refsByID[ID]; + return null; + } + } + public ObjectModelReference this[Type type] + { + get + { + if (refsByType.ContainsKey(type)) return refsByType[type]; + return null; + } + } + + public bool Contains(Guid ID) + { + return (refsByID.ContainsKey(ID)); + } + public bool Contains(Type type) + { + if (refsByType.Count == 0) + { + foreach (ObjectModelReference omr in this) + { + if (omr.ObjectModelType != null) + { + refsByType.Add(omr.ObjectModelType, omr); + } + } + } + return (refsByType.ContainsKey(type)); + } + } + + private string mvarObjectModelTypeName = null; + public string ObjectModelTypeName + { + get + { + if (mvarObjectModelTypeName != null) + { + return mvarObjectModelTypeName; + } + else if (mvarObjectModelType != null) + { + return mvarObjectModelType.FullName; + } + return null; + } + } + + private Type mvarObjectModelType = null; + public Type ObjectModelType { get { return mvarObjectModelType; } } + + private Guid mvarObjectModelID = Guid.Empty; + public Guid ObjectModelID { get { return mvarObjectModelID; } } + + private string mvarTitle = null; + public string Title { get { return mvarTitle; } set { mvarTitle = value; } } + + public string GetTitle() + { + if (mvarTitle != null) return mvarTitle; + if (mvarObjectModelType != null) return mvarObjectModelType.FullName; + return mvarObjectModelID.ToString("B"); + } + + private string[] mvarPath = null; + public string[] Path + { + get + { + if (mvarPath == null && mvarObjectModelType != null) + { + string[] sz = mvarObjectModelType.FullName.Split(new char[] { '.' }); + if (mvarTitle != null) + { + sz[sz.Length - 1] = mvarTitle; + } + return sz; + } + return mvarPath; + } + set { mvarPath = value; } + } + + public ObjectModelReference(Guid ID) + { + mvarObjectModelID = ID; + } + public ObjectModelReference(string TypeName) + { + mvarObjectModelTypeName = TypeName; + } + public ObjectModelReference(Type type) + { + if (!type.IsSubclassOf(typeof(ObjectModel))) + { + throw new InvalidCastException("Cannot create an object model reference to a non-ObjectModel type"); + } + else if (type.IsAbstract) + { + throw new InvalidOperationException("Cannot create an object model reference to an abstract type"); + } + + mvarObjectModelType = type; + mvarObjectModelTypeName = mvarObjectModelType.FullName; + } + public ObjectModelReference(Type type, Guid ID) + { + if (!type.IsSubclassOf(typeof(ObjectModel))) + { + throw new InvalidCastException("Cannot create an object model reference to a non-ObjectModel type"); + } + else if (type.IsAbstract) + { + throw new InvalidOperationException("Cannot create an object model reference to an abstract type"); + } + + mvarObjectModelType = type; + mvarObjectModelTypeName = mvarObjectModelType.FullName; + mvarObjectModelID = ID; + } + + public ObjectModel Create() + { + if (mvarObjectModelType == null && mvarObjectModelTypeName != null) + { + mvarObjectModelType = Type.GetType(mvarObjectModelTypeName); + } + if (mvarObjectModelType != null) + { + return (mvarObjectModelType.Assembly.CreateInstance(mvarObjectModelType.FullName) as ObjectModel); + } + return null; + } + + private string mvarDescription = String.Empty; + public string Description { get { return mvarDescription; } set { mvarDescription = value; } } + } +}