internal static bool IsVisibleTo(Type type, Assembly accessingAssembly, XamlSchemaContext schemaContext) { TypeVisibility visibility = GetVisibility(type); if (visibility == TypeVisibility.NotVisible) { return(false); } if (visibility == TypeVisibility.Internal && !schemaContext.AreInternalsVisibleTo(type.Assembly, accessingAssembly)) { return(false); } if (type.IsGenericType) { foreach (Type typeArg in type.GetGenericArguments()) { if (!IsVisibleTo(typeArg, accessingAssembly, schemaContext)) { return(false); } } } else if (type.HasElementType) { return(IsVisibleTo(type.GetElementType(), accessingAssembly, schemaContext)); } return(true); }
private Type GetTargetType(MethodInfo instanceMethod) { Type declaringType = instanceMethod.DeclaringType; // Derived classes are not allowed to access protected members on instances of their base classes. // So if it it's an inherited protected member, we need to cast to the local type. if (_localType != null && _localType != declaringType && declaringType.IsAssignableFrom(_localType)) { if (instanceMethod.IsFamily || instanceMethod.IsFamilyAndAssembly) { return(_localType); } if (instanceMethod.IsFamilyOrAssembly) { // This is a non-security-critical check; we're attempting to do the right thing here, // but the real security check happens in the CLR when we execute the dynamic method. bool areInternalsVisible = _schemaContext.AreInternalsVisibleTo( declaringType.Assembly, _localType.Assembly); if (!areInternalsVisible) { return(_localType); } } } // Otherwise just cast to the declaring type of the member return(declaringType); }
// 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); }
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)); }
// 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)); }