Ejemplo n.º 1
0
        public ObjectModel Extract(object obj, DisassemblyContext context)
        {
            Type objectType = obj.GetType();
            var  properties = new List <ObjectField>();

            IEnumerable <IAssignableMemberInfo> fields = GetModelFields(objectType);

            foreach (IAssignableMemberInfo info in fields)
            {
                try
                {
                    ObjectField objectField = new ObjectField();
                    objectField.Name = info.Name;

                    object memberValue = info.GetValue(obj);

                    if (memberValue != null)
                    {
                        GetPropertyAssembler(info.AttributeType).Disassemble(objectField, memberValue, info.ValueType, context);

                        if (memberValue.GetType() != info.ValueType)
                        {
                            objectField.Model.MakeExplicit(memberValue.GetType());
                        }
                    }
                    else
                    {
                        objectField.Model = new NullModel();
                    }

                    properties.Add(objectField);
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                }
            }

            return(context.MakeReferencable(obj, new ObjectModel(properties.ToArray())) as ObjectModel);
        }
Ejemplo n.º 2
0
        public ValueModel Disassemble(object obj, Type expectedType, DisassemblyContext context)
        {
            List <ValueModel> models     = new List <ValueModel>();
            IEnumerable       enumerable = obj as IEnumerable;

            if (obj != null)
            {
                foreach (object element in enumerable)
                {
                    ValueModel model = _elementAssembler.Disassemble(element, element.GetType(), context);
                    if (element.GetType() != GetElementType(obj.GetType()))
                    {
                        model.MakeExplicit(element.GetType());
                    }
                    models.Add(model);
                }
            }

            var modelsArray = models.ToArray();

            return(context.MakeReferencable(modelsArray, new ArrayModel(modelsArray)));
        }