Пример #1
0
        private void AssertValidType(Type target)
        {
#if SILVERLIGHT
            var isTargetNested = target.IsNested();
            var isAccessible   = target.IsPublic || target.IsNestedPublic;
#else
            bool isTargetNested      = target.IsNested;
            bool isNestedAndInternal = isTargetNested && (target.IsNestedAssembly || target.IsNestedFamORAssem);
            bool isInternalNotNested = target.IsVisible == false && isTargetNested == false;

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

            if (!isAccessible)
            {
                throw new GeneratorException("Type " + target.FullName + "is not public. " +
                                             "Can not create proxy for types that are not accessible.");
            }
            if (target.IsGenericTypeDefinition)
            {
                throw new GeneratorException("Type " + target.FullName + "is a generic type definition. " +
                                             "Can not create proxy for open generic types.");
            }
        }
Пример #2
0
        private bool IsAccessible(Type target)
        {
            var isTargetNested      = target.IsNested;
            var isNestedAndInternal = isTargetNested && (target.IsNestedAssembly || target.IsNestedFamORAssem);
            var isInternalNotNested = target.IsVisible == false && isTargetNested == false;

            var internalAndVisibleToDynProxy = (isInternalNotNested || isNestedAndInternal) &&
                                               InternalsHelper.IsInternalToDynamicProxy(target.Assembly);

            return(internalAndVisibleToDynProxy);
        }