Example #1
0
        public static T GetPropertyValueAs <T>(this IDynamicProperties props, string key)
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentNullException(nameof(key));
            }

            var dictionary = props.Properties as IDictionary <string, object>;

            if (dictionary == null || !dictionary.ContainsKey(key))
            {
                throw new DynamicValueNotFoundException(key);
            }

            var property = dictionary[key];

            if (property is T)
            {
                return((T)property);
            }

            var result = Convert.ChangeType(property, typeof(T));

            return((T)result);
        }
Example #2
0
        public static bool ContainsProperty(this IDynamicProperties props, string key)
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentNullException(nameof(key));
            }

            var dictionary = props.Properties as IDictionary <string, object>;

            return(dictionary != null && dictionary.ContainsKey(key));
        }
Example #3
0
 public static bool ContainsProperty(this IDynamicProperties props, string key)
 {
     if (key == null)
     {
         throw new ArgumentNullException(nameof(key));
     }
     if (string.IsNullOrWhiteSpace(key))
     {
         throw new ArgumentException(nameof(key));
     }
     return(props.Properties.ContainsKey(key));
 }
Example #4
0
 public bool LoadObject(IDynamicProperties obj)
 {
     try
     {
         obj.SetPropertyGrid(propertyGrid1);
         propertyGrid1.SelectedObject = obj;
         return(true);
     }
     catch (Exception e)
     {
         MathNode.Log(this, e);
     }
     return(false);
 }