public static object InstantiateTargetType(IAssembly projectAssembly, IInstanceBuilderContext context, Type type) { bool flag = (projectAssembly == null ? false : projectAssembly.CompareTo(type.Assembly)); IInstanceBuilder builder = context.InstanceBuilderFactory.GetBuilder(type); if (builder.ReplacementType == null) { return(InstanceBuilderOperations.InstantiateType(type, flag)); } return(InstanceBuilderOperations.InstantiateType(builder.ReplacementType, true)); }
public void Initialize(IXmlNamespace xmlNamespace, Type type, string key) { if (type == null) { throw new ArgumentNullException("type"); } PlatformTypes platformMetadata = (PlatformTypes)this.PlatformMetadata; this.isBuilt = true; this.xmlNamespace = xmlNamespace; this.type = type; Type nearestSupportedType = platformMetadata.GetNearestSupportedType(this.type); if (nearestSupportedType != null) { this.nearestSupportedType = platformMetadata.GetType(nearestSupportedType); } this.lastResolvedType = this.type; this.name = ProjectContextType.GetNameIncludingAnyDeclaringTypes(this.type); Assembly assembly = this.type.Assembly; IAssembly projectAssembly = this.typeResolver.ProjectAssembly; if (projectAssembly == null || !projectAssembly.CompareTo(assembly)) { this.assemblyName = AssemblyHelper.GetAssemblyName(assembly).Name; if (projectAssembly != null) { bool name = this.assemblyName == projectAssembly.Name; } } this.members = new MemberCollection(this.typeResolver, this); this.assembly = this.GetAssembly(this.typeResolver, this.assemblyName); if (type.IsArray) { this.arrayItemType = ProjectContextType.GetItemType(this.typeResolver, type); this.arrayRank = type.GetArrayRank(); } this.genericTypeArguments = PlatformTypeHelper.GetGenericTypeArguments(this.typeResolver, this.type); if (this.genericTypeArguments.Count > 0) { foreach (IType genericTypeArgument in this.genericTypeArguments) { ProjectContextType projectContextType = genericTypeArgument as ProjectContextType; if (projectContextType == null) { continue; } this.genericDepth = Math.Max(projectContextType.genericDepth + 1, this.genericDepth); } } this.Cache(); this.hashCode = key.GetHashCode(); }
public Type GetType(string typeName) { Type type; Type type1 = null; if (this.typeNameCache.TryGetValue(typeName, out type1)) { return type1; } using (IEnumerator<XmlnsDefinitionMap.AssemblyNamespace> enumerator = this.AssemblyNamespaces.GetEnumerator()) { while (enumerator.MoveNext()) { XmlnsDefinitionMap.AssemblyNamespace current = enumerator.Current; IAssembly assembly = current.Assembly; string str = TypeHelper.CombineNamespaceAndTypeName(current.ClrNamespace, typeName); try { type1 = PlatformTypeHelper.GetType(assembly, str); if (type1 != null) { IType type2 = this.typeResolver.GetType(type1); if (!this.typeResolver.PlatformMetadata.IsNullType(type2)) { if (TypeHelper.IsSet((assembly.CompareTo(this.targetAssembly) ? MemberAccessTypes.PublicOrInternal : MemberAccessTypes.Public), PlatformTypeHelper.GetMemberAccess(type1))) { this.typeNameCache.Add(typeName, type1); type = type1; return type; } } } } catch (ArgumentException argumentException) { type = null; return type; } } this.typeNameCache.Add(typeName, null); return null; } return type; }