Пример #1
0
 public IList <IType> GetGenericTypeArguments()
 {
     if (this.genericTypeArguments == null)
     {
         this.genericTypeArguments = PlatformTypeHelper.GetGenericTypeArguments(this.platformTypes.DefaultTypeResolver, this.type);
     }
     return(this.genericTypeArguments);
 }
Пример #2
0
        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();
        }
Пример #3
0
 private static System.Type GetGenericCollectionTypeFromInterface(System.Type type)
 {
     System.Type genericTypeDefinition = PlatformTypeHelper.GetGenericTypeDefinition(type);
     if (genericTypeDefinition != null && typeof(ICollection <>).IsAssignableFrom(genericTypeDefinition))
     {
         System.Type[] genericTypeArguments = PlatformTypeHelper.GetGenericTypeArguments(type);
         if (genericTypeArguments != null)
         {
             return(genericTypeArguments[0]);
         }
     }
     return(null);
 }
Пример #4
0
        public static Type GetNullableType(Type type)
        {
            Type genericTypeDefinition = PlatformTypeHelper.GetGenericTypeDefinition(type);

            if (genericTypeDefinition != (Type)null && typeof(Nullable <>).IsAssignableFrom(genericTypeDefinition))
            {
                Type[] genericTypeArguments = PlatformTypeHelper.GetGenericTypeArguments(type);
                if (genericTypeArguments != null && genericTypeArguments.Length == 1)
                {
                    return(genericTypeArguments[0]);
                }
            }
            return((Type)null);
        }
Пример #5
0
 public static bool HasUnboundTypeArguments(Type type)
 {
     if (type.IsGenericType)
     {
         foreach (Type type1 in PlatformTypeHelper.GetGenericTypeArguments(type))
         {
             if (type1.IsGenericParameter || PlatformTypeHelper.HasUnboundTypeArguments(type1))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Пример #6
0
 public static IList <IType> GetGenericTypeArguments(ITypeResolver typeResolver, Type type)
 {
     if (type != (Type)null && type.IsGenericType)
     {
         Type[] genericTypeArguments = PlatformTypeHelper.GetGenericTypeArguments(type);
         if (genericTypeArguments != null)
         {
             List <IType> list = new List <IType>(genericTypeArguments.Length);
             foreach (Type type1 in genericTypeArguments)
             {
                 IType type2 = typeResolver.GetType(type1);
                 list.Add(type2);
             }
             return((IList <IType>) new ReadOnlyCollection <IType>((IList <IType>)list));
         }
     }
     return((IList <IType>)ReadOnlyCollections <IType> .Empty);
 }
Пример #7
0
 public void Initialize(UnbuiltTypeDescription typeInfo, string key)
 {
     this.isBuilt             = false;
     this.baseType            = this.typeResolver.ResolveType(typeInfo.BaseType);
     this.type                = this.baseType.RuntimeType;
     this.xmlNamespace        = typeInfo.XmlNamespace;
     this.name                = typeInfo.TypeName;
     this.unbuiltClrNamespace = typeInfo.ClrNamespace;
     this.assembly            = typeInfo.AssemblyReference;
     if (this.assembly != this.typeResolver.ProjectAssembly)
     {
         this.assemblyName = this.assembly.Name;
     }
     this.lastResolvedType     = this.type;
     this.members              = new MemberCollection(this.typeResolver, this);
     this.genericTypeArguments = PlatformTypeHelper.GetGenericTypeArguments(this.typeResolver, null);
     this.Cache();
     this.hashCode = key.GetHashCode();
 }
Пример #8
0
        private string GetKey(IAssemblyId assembly, Type type)
        {
            string nameIncludingAnyDeclaringTypes = ProjectContextType.GetNameIncludingAnyDeclaringTypes(type);
            string key = this.GetKey(assembly, Microsoft.Expression.DesignModel.Metadata.TypeHelper.CombineNamespaceAndTypeName(type.Namespace, nameIncludingAnyDeclaringTypes));

            if (!type.IsGenericType)
            {
                return(key);
            }
            StringBuilder stringBuilder = new StringBuilder(key);

            stringBuilder.Append('<');
            Type[] genericTypeArguments = PlatformTypeHelper.GetGenericTypeArguments(type);
            if (genericTypeArguments == null)
            {
                return(null);
            }
            for (int i = 0; i < (int)genericTypeArguments.Length; i++)
            {
                Type type1 = genericTypeArguments[i];
                if (i > 0)
                {
                    stringBuilder.Append(',');
                }
                IAssembly assembly1 = this.GetAssembly(type1.Assembly);
                if (assembly1 == null)
                {
                    return(null);
                }
                string str = this.GetKey(assembly1, type1);
                if (str == null)
                {
                    return(null);
                }
                stringBuilder.Append(str);
            }
            stringBuilder.Append('>');
            return(stringBuilder.ToString());
        }