コード例 #1
0
ファイル: BaseProxyGenerator.cs プロジェクト: patdhlk/Core
 private bool IsConstructorVisible(ConstructorInfo constructor)
 {
     return(constructor.IsPublic ||
            constructor.IsFamily ||
            constructor.IsFamilyOrAssembly ||
            (constructor.IsAssembly && InternalsUtil.IsInternalToDynamicProxy(constructor.DeclaringType.GetTypeInfo().Assembly)));
 }
コード例 #2
0
        private bool IsConstructorVisible(IConstructorInfo constructor)
        {
            return(constructor.IsPublic ||
                   constructor.IsFamily ||
                   constructor.IsFamilyOrAssembly
#if !Silverlight
                   || (constructor.IsAssembly && InternalsUtil.IsInternalToDynamicProxy(constructor.DeclaringType.Assembly())));
#else
                   ;
#endif
        }
コード例 #3
0
ファイル: ProxyUtil.cs プロジェクト: raynwang/Core
        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 is not accessible. ";

            var message = string.Format(messageFormat,
                                        inaccessibleMethod);

            var instructions = InternalsUtil.CreateInstructionsToMakeVisible(targetAssembly);

            return(message + instructions);
        }
コード例 #4
0
        /// <summary>
        ///   Initializes a new instance of the <see cref = "ModuleScope" /> class, allowing to specify whether the assemblies generated by this instance
        ///   should be saved and what simple names are to be assigned to them.
        /// </summary>
        /// <param name = "savePhysicalAssembly">If set to <c>true</c> saves the generated module.</param>
        /// <param name = "disableSignedModule">If set to <c>true</c> disables ability to generate signed module. This should be used in cases where ran under constrained permissions.</param>
        /// <param name = "namingScope">Naming scope used to provide unique names to generated types and their members (usually via sub-scopes).</param>
        /// <param name = "strongAssemblyName">The simple name of the strong-named assembly generated by this <see
        ///    cref = "ModuleScope" />.</param>
        /// <param name = "strongModulePath">The path and file name of the manifest module of the strong-named assembly generated by this <see
        ///    cref = "ModuleScope" />.</param>
        /// <param name = "weakAssemblyName">The simple name of the weak-named assembly generated by this <see cref = "ModuleScope" />.</param>
        /// <param name = "weakModulePath">The path and file name of the manifest module of the weak-named assembly generated by this <see
        ///    cref = "ModuleScope" />.</param>
        public ModuleScope(bool savePhysicalAssembly, bool disableSignedModule, INamingScope namingScope,
                           string strongAssemblyName, string strongModulePath,
                           string weakAssemblyName, string weakModulePath)
        {
            this.savePhysicalAssembly = savePhysicalAssembly;
            this.disableSignedModule  = disableSignedModule;
            this.namingScope          = namingScope;
            this.strongAssemblyName   = strongAssemblyName;
            this.strongModulePath     = strongModulePath;
            this.weakAssemblyName     = weakAssemblyName;
            this.weakModulePath       = weakModulePath;

            this.internalsUtil = new InternalsUtil(this);
        }
コード例 #5
0
        /// <summary>
        /// Creates a message to inform clients that a proxy couldn't be created due to reliance on an
        /// inaccessible type (perhaps itself).
        /// </summary>
        /// <param name="inaccessibleType">the inaccessible type that prevents proxy creation</param>
        /// <param name="typeToProxy">the type that couldn't be proxied</param>
        public static string CreateMessageForInaccessibleType(Type inaccessibleType, Type typeToProxy)
        {
            var targetAssembly = typeToProxy.GetTypeInfo().Assembly;

            string inaccessibleTypeDescription = inaccessibleType == typeToProxy
                ? "it"
                : "type " + inaccessibleType.GetBestName();

            var messageFormat = "Can not create proxy for type {0} because {1} is not accessible. ";

            var message = string.Format(messageFormat,
                                        typeToProxy.GetBestName(),
                                        inaccessibleTypeDescription);

            var instructions = InternalsUtil.CreateInstructionsToMakeVisible(targetAssembly);

            return(message + instructions);
        }
コード例 #6
0
        private MethodAttributes ObtainAttributes()
        {
            var methodInfo = Method;
            var attributes = MethodAttributes.Virtual;

            if (methodInfo.IsFinal || Method.DeclaringType.IsInterface)
            {
                attributes |= MethodAttributes.NewSlot;
            }

            if (methodInfo.IsPublic)
            {
                attributes |= MethodAttributes.Public;
            }

            if (methodInfo.IsHideBySig)
            {
                attributes |= MethodAttributes.HideBySig;
            }
            if (InternalsUtil.IsInternal(methodInfo) &&
                InternalsUtil.IsInternalToDynamicProxy(methodInfo.DeclaringType.Assembly))
            {
                attributes |= MethodAttributes.Assembly;
            }
            if (methodInfo.IsFamilyAndAssembly)
            {
                attributes |= MethodAttributes.FamANDAssem;
            }
            else if (methodInfo.IsFamilyOrAssembly)
            {
                attributes |= MethodAttributes.FamORAssem;
            }
            else if (methodInfo.IsFamily)
            {
                attributes |= MethodAttributes.Family;
            }

            if (Standalone == false)
            {
                attributes |= MethodAttributes.SpecialName;
            }
            return(attributes);
        }
コード例 #7
0
        /// <summary>
        /// Validates that the target type to proxy is visible and not generic.
        /// </summary>
        /// <param name="target">
        /// The interface type to proxy.
        /// </param>
        private static void AssertValidType(Type target)
        {
            // This is copied from the DefaultProxyBuilder because we need to
            // validate types but the validation logic is not accessible.

            bool isTargetNested      = target.IsNested;
            bool isNestedAndInternal = isTargetNested && (target.IsNestedAssembly || target.IsNestedFamORAssem);
            bool isInternalNotNested = target.IsVisible == false && isTargetNested == false;

            bool internalAndVisibleToDynProxy = (isInternalNotNested || isNestedAndInternal) &&
                                                InternalsUtil.IsInternalToDynamicProxy(target.Assembly);
            var isAccessible = target.IsPublic || target.IsNestedPublic || internalAndVisibleToDynProxy;

            if (!isAccessible)
            {
                throw new GeneratorException(String.Format(CultureInfo.CurrentUICulture, Resources.DynamicProxy_InterfaceTypeToProxyNotPublic, target.FullName));
            }
            if (target.IsGenericTypeDefinition)
            {
                throw new GeneratorException(String.Format(CultureInfo.CurrentUICulture, Resources.DynamicProxy_InterfaceTypeToProxyIsGeneric, target.FullName));
            }
        }