示例#1
0
        /// <summary>
        /// </summary>
        /// <param name="typeParameter">
        /// </param>
        /// <returns>
        /// </returns>
        public IType ResolveTypeParameter(IType typeParameter, bool isByRef = false, bool isPinned = false)
        {
            IType resolved = null;

            if (this.Map.TryGetValue(typeParameter, out resolved))
            {
                if (isByRef || isPinned)
                {
                    return(resolved.Clone(false, false, isByRef, isPinned));
                }

                return(resolved);
            }

            return(typeParameter);
        }
        public override bool Instantiate(IInstanceBuilderContext context, ViewNode viewNode)
        {
            IConstructorArgumentNodeCollection constructorArgumentNodeCollections;

            if (viewNode.Instance == null)
            {
                DocumentCompositeNode documentNode = viewNode.DocumentNode as DocumentCompositeNode;
                if (documentNode == null)
                {
                    return(base.Instantiate(context, viewNode));
                }
                IType        type            = documentNode.Type;
                IConstructor bestConstructor = documentNode.GetBestConstructor(out constructorArgumentNodeCollections);
                if (bestConstructor == null)
                {
                    CultureInfo currentCulture = CultureInfo.CurrentCulture;
                    string      instanceBuilderCannotInstantiateType = ExceptionStringTable.InstanceBuilderCannotInstantiateType;
                    object[]    name = new object[] { type.Name };
                    throw new InstanceBuilderException(string.Format(currentCulture, instanceBuilderCannotInstantiateType, name), documentNode);
                }
                IConstructorArgumentProperties constructorArgumentProperties = type.GetConstructorArgumentProperties();
                IPropertyId[] propertyIdArray  = new IPropertyId[constructorArgumentNodeCollections.Count];
                IPropertyId[] propertyIdArray1 = propertyIdArray;
                propertyIdArray1 = propertyIdArray;
                if (!context.IsSerializationScope)
                {
                    object[] objArray = new object[constructorArgumentNodeCollections.Count];
                    for (int i = 0; i < constructorArgumentNodeCollections.Count; i++)
                    {
                        IParameter item     = bestConstructor.Parameters[i];
                        IProperty  property = constructorArgumentProperties[item.Name];
                        propertyIdArray1[i] = property;
                        objArray[i]         = MarkupExtensionInstanceBuilderBase.InstantiateConstructorArgument(context, viewNode, item, property, constructorArgumentNodeCollections[i]);
                    }
                    try
                    {
                        viewNode.Instance = bestConstructor.Invoke(objArray);
                    }
                    catch (Exception exception1)
                    {
                        Exception   exception   = exception1;
                        CultureInfo cultureInfo = CultureInfo.CurrentCulture;
                        string      str         = ExceptionStringTable.InstanceBuilderCannotInstantiateType;
                        object[]    name1       = new object[] { type.Name };
                        throw new InstanceBuilderException(string.Format(cultureInfo, str, name1), exception, documentNode);
                    }
                }
                else
                {
                    DocumentNode[] documentNodeArray = new DocumentNode[constructorArgumentNodeCollections.Count];
                    for (int j = 0; j < constructorArgumentNodeCollections.Count; j++)
                    {
                        IParameter parameter = bestConstructor.Parameters[j];
                        IProperty  item1     = constructorArgumentProperties[parameter.Name];
                        propertyIdArray1[j]  = item1;
                        documentNodeArray[j] = (DocumentNode)MarkupExtensionInstanceBuilderBase.InstantiateConstructorArgument(context, viewNode, parameter, item1, constructorArgumentNodeCollections[j]);
                    }
                    type = (IType)type.Clone(context.DocumentContext.TypeResolver);
                    DocumentCompositeNode documentCompositeNode = context.DocumentContext.CreateNode(type);
                    documentCompositeNode.SetConstructor(bestConstructor, documentNodeArray);
                    viewNode.Instance = documentCompositeNode;
                }
                if (viewNode.Instance != null)
                {
                    List <DocumentNode> documentNodes = null;
                    foreach (IProperty property1 in context.GetProperties(viewNode))
                    {
                        if (Array.IndexOf <IPropertyId>(propertyIdArray1, property1) >= 0)
                        {
                            continue;
                        }
                        if (documentNodes == null)
                        {
                            documentNodes = new List <DocumentNode>();
                        }
                        documentNodes.Add(documentNode.Properties[property1]);
                    }
                    if (documentNodes != null)
                    {
                        documentNodes.Sort(MarkupExtensionInstanceBuilderBase.DocumentNodeComparer);
                        foreach (DocumentNode documentNode1 in documentNodes)
                        {
                            this.UpdateProperty(context, viewNode, documentNode1.SitePropertyKey, documentNode1);
                        }
                    }
                }
            }
            viewNode.InstanceState = InstanceState.Valid;
            return(true);
        }