コード例 #1
0
        private static object InstantiateConstructorArgument(IInstanceBuilderContext context, ViewNode viewNode, IParameter constructorArgument, IProperty constructorArgumentProperty, DocumentNode constructorArgumentNode)
        {
            object defaultValue;

            if (constructorArgumentProperty != null)
            {
                return(InstanceBuilderOperations.UpdatePropertyWithoutApply(context, viewNode, constructorArgumentProperty, constructorArgumentNode).Instance);
            }
            if (constructorArgumentNode != null)
            {
                ViewNode viewNode1 = InstanceBuilderOperations.UpdateChildWithoutApply(context, viewNode, viewNode.Children.Count, DocumentNodeChangeAction.Add, constructorArgumentNode);
                return(viewNode1.Instance);
            }
            IDocumentContext documentContext = viewNode.DocumentNode.Context;
            Type             targetType      = viewNode.TargetType;
            Type             runtimeType     = constructorArgument.ParameterType.RuntimeType;
            ReferenceStep    referenceStep   = constructorArgumentProperty as ReferenceStep;

            if (referenceStep == null || !referenceStep.HasDefaultValue(targetType))
            {
                bool flag = documentContext.TypeResolver.InTargetAssembly(constructorArgument.ParameterType);
                defaultValue = InstanceBuilderOperations.InstantiateType(runtimeType, flag);
            }
            else
            {
                defaultValue = referenceStep.GetDefaultValue(targetType);
            }
            if (context.IsSerializationScope)
            {
                defaultValue = documentContext.CreateNode(runtimeType, defaultValue);
            }
            return(defaultValue);
        }