public static ObjectDefInstance Create(string name, object values, KV <string, object> key = null) { var instance = new ObjectDefInstance() { Name = name, Key = key }; Type type = values.GetType(); foreach (var prop in type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)) { instance.Properties.Add(prop.Name, prop.GetValue(values)); } return(instance); }
public static ObjectDefInstance CreateInstance <T>(T t, KV <string, object> key = null) { Type type = typeof(T); string name = type.Name; string listName = name.Pluralize(); ObjectDefInstance instance = new ObjectDefInstance() { Name = type.Name, Key = key }; foreach (var p in type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)) { if (p.PropertyType.IsSimpleType()) { instance.Properties.Add(p.Name, p.GetValue(t)); } } return(instance); }
public ObjectDefInstance() { Key = new KV <string, object>("", ""); Properties = new Dictionary <string, object>(); }