From 648ff2799739851bf2e9793bfe09fe4fecc13be4 Mon Sep 17 00:00:00 2001 From: alcexhim Date: Wed, 27 Jan 2016 12:50:56 -0500 Subject: [PATCH] Better implementation of CustomProperties --- .../UniversalEditor.Core/ObjectModel.cs | 23 +++++- .../ObjectModelCustomProperty.cs | 75 ------------------- 2 files changed, 21 insertions(+), 77 deletions(-) delete mode 100644 CSharp/Libraries/UniversalEditor.Core/ObjectModelCustomProperty.cs diff --git a/CSharp/Libraries/UniversalEditor.Core/ObjectModel.cs b/CSharp/Libraries/UniversalEditor.Core/ObjectModel.cs index 386deb60..efff06fb 100644 --- a/CSharp/Libraries/UniversalEditor.Core/ObjectModel.cs +++ b/CSharp/Libraries/UniversalEditor.Core/ObjectModel.cs @@ -66,7 +66,26 @@ namespace UniversalEditor } } - private ObjectModelCustomProperty.ObjectModelCustomPropertyCollection mvarCustomProperties = new ObjectModelCustomProperty.ObjectModelCustomPropertyCollection(); - public ObjectModelCustomProperty.ObjectModelCustomPropertyCollection CustomProperties { get { return mvarCustomProperties; } } + private Dictionary _customProperties = new Dictionary(); + public T GetCustomProperty(string name, T defaultValue = default(T)) + { + if (_customProperties.ContainsKey(name)) + { + return (T)_customProperties[name]; + } + return defaultValue; + } + public object GetCustomProperty(string name, object defaultValue = null) + { + return GetCustomProperty(name, defaultValue); + } + public void SetCustomProperty(string name, T value) + { + _customProperties[name] = value; + } + public void SetCustomProperty(string name, object value) + { + SetCustomProperty(name, value); + } } } diff --git a/CSharp/Libraries/UniversalEditor.Core/ObjectModelCustomProperty.cs b/CSharp/Libraries/UniversalEditor.Core/ObjectModelCustomProperty.cs deleted file mode 100644 index 97c2ce87..00000000 --- a/CSharp/Libraries/UniversalEditor.Core/ObjectModelCustomProperty.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace UniversalEditor -{ - public class ObjectModelCustomProperty - { - public class ObjectModelCustomPropertyCollection - { - private Dictionary> _internalCollection = new Dictionary>(); - - public ObjectModelCustomProperty Add(DataFormatReference dataFormat, string name, object value) - { - ObjectModelCustomProperty item = new ObjectModelCustomProperty(); - item.DataFormat = dataFormat; - item.Name = name; - item.Value = value; - - Dictionary values = null; - if (!_internalCollection.ContainsKey(dataFormat)) - { - values = new Dictionary(); - _internalCollection.Add(dataFormat, values); - } - else - { - values = _internalCollection[dataFormat]; - } - values[name] = item; - return item; - } - public ObjectModelCustomProperty[] this[DataFormatReference dataFormat] - { - get - { - List list = new List(); - if (_internalCollection.ContainsKey(dataFormat)) - { - foreach (KeyValuePair kvp in _internalCollection[dataFormat]) - { - list.Add(kvp.Value); - } - } - return list.ToArray(); - } - } - public ObjectModelCustomProperty this[DataFormatReference dataFormat, string name] - { - get - { - if (!_internalCollection.ContainsKey(dataFormat)) return null; - if (!_internalCollection[dataFormat].ContainsKey(name)) return null; - return _internalCollection[dataFormat][name]; - } - set - { - if (!_internalCollection.ContainsKey(dataFormat)) _internalCollection.Add(dataFormat, new Dictionary()); - if (!_internalCollection[dataFormat].ContainsKey(name)) _internalCollection[dataFormat].Add(name, value); - _internalCollection[dataFormat][name] = value; - } - } - } - - private DataFormatReference mvarDataFormat = null; - public DataFormatReference DataFormat { get { return mvarDataFormat; } set { mvarDataFormat = value; } } - - private string mvarName = String.Empty; - public string Name { get { return mvarName; } set { mvarName = value; } } - - private object mvarValue = null; - public object Value { get { return mvarValue; } set { mvarValue = value; } } - } -}