// 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); }
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); }
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); }
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); }
// 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); }