예제 #1
0
            private MemberInfo[] LookupDefaultMembers(ref string DefaultMemberName)
            {
                string name     = null;
                Type   baseType = this.m_Type;

                do
                {
                    object[] customAttributes = baseType.GetCustomAttributes(typeof(DefaultMemberAttribute), false);
                    if ((customAttributes != null) && (customAttributes.Length > 0))
                    {
                        name = ((DefaultMemberAttribute)customAttributes[0]).MemberName;
                        break;
                    }
                    baseType = baseType.BaseType;
                }while ((baseType != null) && !Symbols.IsRootObjectType(baseType));
                if (name != null)
                {
                    MemberInfo[] array = FilterInvalidMembers(baseType.GetMember(name, BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.IgnoreCase));
                    if (array != null)
                    {
                        DefaultMemberName = name;
                        if (array.Length > 1)
                        {
                            Array.Sort <MemberInfo>(array, InheritanceSorter.Instance);
                        }
                        return(array);
                    }
                }
                return(NoMembers);
            }
예제 #2
0
 internal static ConversionClass ClassifyPredefinedCLRConversion(Type TargetType, Type SourceType)
 {
     if (TargetType == SourceType)
     {
         return(ConversionClass.Identity);
     }
     if (Symbols.IsRootObjectType(TargetType) || Symbols.IsOrInheritsFrom(SourceType, TargetType))
     {
         return(ConversionClass.Widening);
     }
     if (Symbols.IsRootObjectType(SourceType) || Symbols.IsOrInheritsFrom(TargetType, SourceType))
     {
         return(ConversionClass.Narrowing);
     }
     if (Symbols.IsInterface(SourceType))
     {
         if ((Symbols.IsClass(TargetType) || Symbols.IsArrayType(TargetType)) || Symbols.IsGenericParameter(TargetType))
         {
             return(ConversionClass.Narrowing);
         }
         if (Symbols.IsInterface(TargetType))
         {
             return(ConversionClass.Narrowing);
         }
         if (!Symbols.IsValueType(TargetType))
         {
             return(ConversionClass.Narrowing);
         }
         if (Symbols.Implements(TargetType, SourceType))
         {
             return(ConversionClass.Narrowing);
         }
         return(ConversionClass.None);
     }
     if (Symbols.IsInterface(TargetType))
     {
         if (Symbols.IsArrayType(SourceType))
         {
             return(ClassifyCLRArrayToInterfaceConversion(TargetType, SourceType));
         }
         if (Symbols.IsValueType(SourceType))
         {
             if (Symbols.Implements(SourceType, TargetType))
             {
                 return(ConversionClass.Widening);
             }
             return(ConversionClass.None);
         }
         if (Symbols.IsClass(SourceType))
         {
             if (Symbols.Implements(SourceType, TargetType))
             {
                 return(ConversionClass.Widening);
             }
             return(ConversionClass.Narrowing);
         }
     }
     if (Symbols.IsEnum(SourceType) || Symbols.IsEnum(TargetType))
     {
         if (Symbols.GetTypeCode(SourceType) != Symbols.GetTypeCode(TargetType))
         {
             return(ConversionClass.None);
         }
         if (Symbols.IsEnum(TargetType))
         {
             return(ConversionClass.Narrowing);
         }
         return(ConversionClass.Widening);
     }
     if (Symbols.IsGenericParameter(SourceType))
     {
         if (!Symbols.IsClassOrInterface(TargetType))
         {
             return(ConversionClass.None);
         }
         foreach (Type type2 in Symbols.GetInterfaceConstraints(SourceType))
         {
             switch (ClassifyPredefinedConversion(TargetType, type2))
             {
             case ConversionClass.Widening:
             case ConversionClass.Identity:
                 return(ConversionClass.Widening);
             }
         }
         Type classConstraint = Symbols.GetClassConstraint(SourceType);
         if (classConstraint != null)
         {
             switch (ClassifyPredefinedConversion(TargetType, classConstraint))
             {
             case ConversionClass.Widening:
             case ConversionClass.Identity:
                 return(ConversionClass.Widening);
             }
         }
         return(Interaction.IIf <ConversionClass>(Symbols.IsInterface(TargetType), ConversionClass.Narrowing, ConversionClass.None));
     }
     if (Symbols.IsGenericParameter(TargetType))
     {
         Type derived = Symbols.GetClassConstraint(TargetType);
         if ((derived != null) && Symbols.IsOrInheritsFrom(derived, SourceType))
         {
             return(ConversionClass.Narrowing);
         }
         return(ConversionClass.None);
     }
     if ((Symbols.IsArrayType(SourceType) && Symbols.IsArrayType(TargetType)) && (SourceType.GetArrayRank() == TargetType.GetArrayRank()))
     {
         return(ClassifyCLRConversionForArrayElementTypes(TargetType.GetElementType(), SourceType.GetElementType()));
     }
     return(ConversionClass.None);
 }