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(); }
private void Cache() { Type runtimeType; ITypeMetadata metadata; if (this.isBuilt) { this.baseType = null; if (this.type != null) { Type baseType = this.type.BaseType; if (baseType != null) { this.baseType = this.typeResolver.GetType(baseType); } } else if (this.lastResolvedType != null && this.lastResolvedType.BaseType != null) { this.baseType = this.typeResolver.GetType(this.lastResolvedType.BaseType); } if (this.baseType == null && !this.IsInterface) { this.baseType = this.typeResolver.ResolveType(PlatformTypes.Object); } } if (this.NearestResolvedType != null) { runtimeType = this.NearestResolvedType.RuntimeType; } else { runtimeType = null; } Type type = runtimeType; if (type == null) { type = typeof(object); } if (this.typeResolver.MetadataFactory != null) { metadata = this.typeResolver.MetadataFactory.GetMetadata(type); } else { metadata = null; } this.metadata = metadata; if (this.metadata == null || this.genericDepth >= 10) { this.nameProperty = null; this.defaultContentProperty = null; } else { this.nameProperty = this.metadata.NameProperty; this.defaultContentProperty = this.metadata.DefaultContentProperty; } this.itemType = ProjectContextType.GetItemType(this.typeResolver, type); this.nullableType = null; Type nullableType = PlatformTypeHelper.GetNullableType(type); if (nullableType != null) { this.nullableType = this.typeResolver.GetType(nullableType); } if (this.PlatformMetadata != null) { this.typeConverter = this.PlatformMetadata.GetTypeConverter(type); } }