protected ObjectModel(ObjectModel parent, string name, Type type, object value, ModelOptions options, ObjectTag tag = ObjectTag.Edit) { Parent = parent; Name = name; Value = value; Type = type; ObjectType = type.GetObjectType(); Level = Parent == null ? 0 : Parent.Level + 1; Options = options; Tag = Parent == null ? tag : Options.GetOperationFor(parent.Type, name, tag); }
public static ComplexObjectModel For(object value, Action <ModelOptions> action = null) { var options = new ModelOptions(); if (action != null) { action(options); } var type = value.GetType(); return(new ComplexObjectModel(null, type.Name, type, value, options, ObjectTag.Edit)); }
protected CollectionObjectModel(ObjectModel parent, string name, Type type, object value, ModelOptions options, ObjectTag tag) : base(parent, name, type, value, options, tag) { }
public EnumObjectModel(ObjectModel parent, string name, Type type, object value, ModelOptions options, ObjectTag tag) : base(parent, name, type, value, options, tag) { EnumValues = Enum.GetValues(Type).Cast <object>().ToList(); }
public SimpleObjectModel(ObjectModel parent, string name, Type type, object value, ModelOptions options, ObjectTag tag) : base(parent, name, type, value, options, tag) { }
public ComplexObjectModel(ObjectModel parent, string name, Type type, object value, ModelOptions options, ObjectTag tag) : base(parent, name, type, value, options, tag) { Properties = Type.GetProperties(BindingFlags.Public | BindingFlags.Instance) .Select(p => For(this, p.Name, p.PropertyType, value == null ? p.PropertyType.GetDefaultValue() : p.GetValue(Value))) .ToList(); }
public ListObjectModel(ObjectModel parent, string name, Type type, object value, ModelOptions options, ObjectTag tag) : base(parent, name, type, value, options, tag) { ItemType = GetItempType(type); TemplateObject = For(this, "[-1]", ItemType, ItemType.GetDefaultValue(), ObjectTag.Template); Values = new List <ObjectModel>(); var collection = (IEnumerable)Value; if (collection != null) { var index = 0; foreach (var collectionValue in collection) { Values.Add(For(this, string.Format("[{0}]", index), collectionValue.GetType(), collectionValue)); index++; } } }
public DictionaryObjectModel(ObjectModel parent, string name, Type type, object value, ModelOptions options, ObjectTag tag) : base(parent, name, type, value, options, tag) { ItemType = GetItempType(type); TemplateObject = For(this, "[-1]", ItemType, ItemType.GetDefaultValue(), ObjectTag.Template); Values = new List <ObjectModel>(); var dictionary = (IDictionary)Value; if (dictionary != null) { var index = 0; foreach (var pair in dictionary) { Values.Add(For(this, string.Format("[{0}]", index), ItemType, Map(pair, ItemType))); index++; } } }