private static string CreateMessageForInaccessibleMethod(MethodBase inaccessibleMethod) { var containingType = inaccessibleMethod.DeclaringType; var targetAssembly = containingType.Assembly; var messageFormat = "Can not create proxy for method {0} because it or its declaring type is not accessible. "; var message = string.Format(messageFormat, inaccessibleMethod); var instructions = ExceptionMessageBuilder.CreateInstructionsToMakeVisible(targetAssembly); return(message + instructions); }
private void AssertValidTypeForTarget(Type type, Type target) { if (type.GetTypeInfo().IsGenericTypeDefinition) { throw new GeneratorException(string.Format("Can not create proxy for type {0} because type {1} is an open generic type.", target.GetBestName(), type.GetBestName())); } if (IsPublic(type) == false && IsAccessible(type) == false) { throw new GeneratorException(ExceptionMessageBuilder.CreateMessageForInaccessibleType(type, target)); } foreach (var typeArgument in type.GetGenericArguments()) { AssertValidTypeForTarget(typeArgument, target); } }
private void AssertValidTypeForTarget(Type type, Type target, string paramName) { if (type.IsGenericTypeDefinition) { throw new ArgumentException( $"Can not create proxy for type {target.GetBestName()} because type {type.GetBestName()} is an open generic type.", paramName); } if (ProxyUtil.IsAccessibleType(type) == false) { throw new ArgumentException(ExceptionMessageBuilder.CreateMessageForInaccessibleType(type, target), paramName); } foreach (var typeArgument in type.GetGenericArguments()) { AssertValidTypeForTarget(typeArgument, target, paramName); } }