Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
0
        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)
 {
 }
Exemplo n.º 4
0
 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();
 }
Exemplo n.º 5
0
 public SimpleObjectModel(ObjectModel parent, string name, Type type, object value, ModelOptions options, ObjectTag tag) : base(parent, name, type, value, options, tag)
 {
 }
Exemplo n.º 6
0
 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();
 }
Exemplo n.º 7
0
        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++;
                }
            }
        }
Exemplo n.º 8
0
        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++;
                }
            }
        }