Example #1
0
        private static string CreateMessageForInaccessibleMethod(MethodBase inaccessibleMethod)
        {
            var containingType = inaccessibleMethod.DeclaringType;
            var targetAssembly = containingType.GetTypeInfo().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 (ProxyUtil.IsAccessibleType(type) == false)
     {
         throw new GeneratorException(ExceptionMessageBuilder.CreateMessageForInaccessibleType(type, target));
     }
     foreach (var typeArgument in type.GetGenericArguments())
     {
         AssertValidTypeForTarget(typeArgument, target);
     }
 }