private static MethodInfo GetAddMethod(Type type, int paramCount, out bool hasMoreThanOne)
        {
            MethodInfo result = null;

            MemberInfo[] addMembers = type.GetMember(KnownStrings.Add, MemberTypes.Method, GetBindingFlags(type));
            if (addMembers != null)
            {
                foreach (MemberInfo mi in addMembers)
                {
                    MethodInfo method = (MethodInfo)mi;
                    if (!TypeReflector.IsPublicOrInternal(method))
                    {
                        continue;
                    }
                    ParameterInfo[] paramInfos = method.GetParameters();
                    if (paramInfos == null || paramInfos.Length != paramCount)
                    {
                        continue;
                    }
                    if (result != null)
                    {
                        // More than one Add method
                        hasMoreThanOne = true;
                        return(null);
                    }
                    result = method;
                }
            }
            hasMoreThanOne = false;
            return(result);
        }
Exemple #2
0
        // Assumes declaring type is visible and is either public or internal
        // Assumes method type args (if any) are visible
        internal static bool IsProtectedVisibleTo(MethodInfo method, Type derivedType, XamlSchemaContext schemaContext)
        {
            if (derivedType == null)
            {
                return(false);
            }

            // Note: this doesn't handle the case of method.IsAssembly, because callers should use
            // IsInternalVisibleTo for those cases.
            if (!derivedType.Equals(method.DeclaringType) && !derivedType.IsSubclassOf(method.DeclaringType))
            {
                return(false);
            }
            if (method.IsFamily || method.IsFamilyOrAssembly)
            {
                return(true);
            }
            if (method.IsFamilyAndAssembly)
            {
                if (TypeReflector.IsInternal(method.DeclaringType))
                {
                    // We've already done an internals visibility check for the declaring type
                    return(true);
                }
                return(schemaContext.AreInternalsVisibleTo(
                           method.DeclaringType.Assembly, derivedType.Assembly));
            }
            return(false);
        }
Exemple #3
0
        private static MethodInfo GetAddMethod(Type type, int paramCount, out bool hasMoreThanOne)
        {
            MethodInfo info = null;

            MemberInfo[] infoArray = type.GetMember("Add", MemberTypes.Method, GetBindingFlags(type));
            if (infoArray != null)
            {
                foreach (MemberInfo info2 in infoArray)
                {
                    MethodInfo method = (MethodInfo)info2;
                    if (TypeReflector.IsPublicOrInternal(method))
                    {
                        ParameterInfo[] parameters = method.GetParameters();
                        if ((parameters != null) && (parameters.Length == paramCount))
                        {
                            if (info != null)
                            {
                                hasMoreThanOne = true;
                                return(null);
                            }
                            info = method;
                        }
                    }
                }
            }
            hasMoreThanOne = false;
            return(info);
        }
        private static MethodInfo GetMethod(Type type, string name, Type[] argTypes)
        {
            MethodInfo result = type.GetMethod(name, GetBindingFlags(type), null, argTypes, null);

            if (result != null && !TypeReflector.IsPublicOrInternal(result))
            {
                result = null;
            }
            return(result);
        }
Exemple #5
0
        private static MethodInfo GetMethod(Type type, string name, Type[] argTypes)
        {
            MethodInfo method = type.GetMethod(name, GetBindingFlags(type), null, argTypes, null);

            if ((method != null) && !TypeReflector.IsPublicOrInternal(method))
            {
                method = null;
            }
            return(method);
        }
 internal static bool IsInternalVisibleTo(MethodInfo method, Assembly accessingAssembly, XamlSchemaContext schemaContext)
 {
     if (accessingAssembly == null)
     {
         return(false);
     }
     if (!method.IsAssembly && !method.IsFamilyOrAssembly)
     {
         return(false);
     }
     return(TypeReflector.IsInternal(method.DeclaringType) || schemaContext.AreInternalsVisibleTo(method.DeclaringType.Assembly, accessingAssembly));
 }
Exemple #7
0
 internal static bool GenericArgumentsAreVisibleTo(MethodInfo method, Assembly accessingAssembly, XamlSchemaContext schemaContext)
 {
     if (method.IsGenericMethod)
     {
         foreach (Type typeArg in method.GetGenericArguments())
         {
             if (!TypeReflector.IsVisibleTo(typeArg, accessingAssembly, schemaContext))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Exemple #8
0
 // Assumes declaring type is visible and is either public or internal
 // Assumes method type args (if any) are visible
 internal static bool IsInternalVisibleTo(MethodInfo method, Assembly accessingAssembly, XamlSchemaContext schemaContext)
 {
     if (accessingAssembly == null)
     {
         return(false);
     }
     if (method.IsAssembly || method.IsFamilyOrAssembly)
     {
         if (TypeReflector.IsInternal(method.DeclaringType))
         {
             // We've already done an internals visibility check for the declaring type
             return(true);
         }
         return(schemaContext.AreInternalsVisibleTo(
                    method.DeclaringType.Assembly, accessingAssembly));
     }
     return(false);
 }
 internal static bool IsProtectedVisibleTo(MethodInfo method, System.Type derivedType, XamlSchemaContext schemaContext)
 {
     if (derivedType == null)
     {
         return(false);
     }
     if (!derivedType.Equals(method.DeclaringType) && !derivedType.IsSubclassOf(method.DeclaringType))
     {
         return(false);
     }
     if (method.IsFamily || method.IsFamilyOrAssembly)
     {
         return(true);
     }
     if (!method.IsFamilyAndAssembly)
     {
         return(false);
     }
     return(TypeReflector.IsInternal(method.DeclaringType) || schemaContext.AreInternalsVisibleTo(method.DeclaringType.Assembly, derivedType.Assembly));
 }