Exemple #1
0
        public object Assemble(ValueModel model, Type expectedType, AssemblyContext context)
        {
            ArrayModel array       = model as ArrayModel;
            Type       elementType = GetElementType(expectedType);
            bool       isList      = IsList(expectedType);

            object     list = Activator.CreateInstance(typeof(List <>).MakeGenericType(elementType));
            MethodInfo add  = list.GetType().GetMethod("Add");

            // I barfed a little writing that.

            for (int i = 0; i < array.Length; i++)
            {
                add.Invoke(list, new object[] { _elementAssembler.Assemble(array[i], array.IsTypeImplicit ? elementType : array[i].GetModelType(), context) });
            }

            if (isList)
            {
                return(list);
            }
            else
            {
                MethodInfo toArray = list.GetType().GetMethod("ToArray");
                return(toArray.Invoke(list, new object[] { }));
            }
        }
Exemple #2
0
        public object Assemble(RootModel model, Type expectedType)
        {
            AssemblyContext context = new AssemblyContext();
            object          obj     = _rootAssembler.Assemble(model.Root, expectedType, context);

            context.ReturnReferenceRequests();

            return(obj);
        }
Exemple #3
0
 public override void Assemble(object obj, IAssignableMemberInfo member, ValueModel model, Type expectedType, AssemblyContext context)
 {
     member.SetValue(obj, _assembler.Assemble(model, expectedType, context));
 }