public void After_adding_attribute_must_be_listed_as_contained()
        {
            AttributesToAvoidReplicating.Add <string>();
            bool contains = AttributesToAvoidReplicating.Contains(typeof(string));

            Assert.IsTrue(contains);
        }
        public void After_adding_attribute_must_still_contain_original_attributes()
        {
            AttributesToAvoidReplicating.Add <string>();
            bool contains = AttributesToAvoidReplicating.Contains(typeof(System.Runtime.InteropServices.ComImportAttribute));

            Assert.IsTrue(contains);
        }
Пример #3
0
        /// <summary>
        ///   Attributes should be replicated if they are non-inheritable,
        ///   but there are some special cases where the attributes means
        ///   something to the CLR, where they should be skipped.
        /// </summary>
        private static bool ShouldSkipAttributeReplication(Type attribute, bool ignoreInheritance)
        {
            if (attribute.GetTypeInfo().IsPublic == false)
            {
                return(true);
            }

            if (AttributesToAvoidReplicating.ShouldAvoid(attribute))
            {
                return(true);
            }

            // Later, there might be more special cases requiring attribute replication,
            // which might justify creating a `SpecialCaseAttributeThatShouldBeReplicated`
            // method and an `AttributesToAlwaysReplicate` class. For the moment, `Param-
            // ArrayAttribute` is the only special case, so keep it simple for now:
            if (attribute == typeof(ParamArrayAttribute))
            {
                return(false);
            }

            if (!ignoreInheritance)
            {
                var attrs = attribute.GetTypeInfo().GetCustomAttributes <AttributeUsageAttribute>(true).ToArray();
                if (attrs.Length != 0)
                {
                    return(attrs[0].Inherited);
                }

                return(true);
            }

            return(false);
        }
Пример #4
0
        private static T CreateServiceImpl(IInterceptor interceptor)
        {
            var serviceNamer = new ProxyNamer(new NamingScope(), typeof(T));
            var generator    = new ProxyGenerator(new DefaultProxyBuilder(new ModuleScope(false, false, serviceNamer, ModuleScope.DEFAULT_ASSEMBLY_NAME, ModuleScope.DEFAULT_FILE_NAME, ModuleScope.DEFAULT_ASSEMBLY_NAME, ModuleScope.DEFAULT_FILE_NAME)));

            AttributesToAvoidReplicating.Add <ServiceContractAttribute>();
            AttributesToAvoidReplicating.Add <OperationContractAttribute>();

            object proxy = generator.CreateInterfaceProxyWithoutTarget <T>(interceptor);

            return((T)proxy);
        }
Пример #5
0
        public BaseTest()
        {
            AttributesToAvoidReplicating.Add <TypeIdentifierAttribute>();
            chirp = new Chirp();

            app = GetApp();

            Array arr = null;

            chirp.OnConnection(app, ext_ConnectMode.ext_cm_AfterStartup, QuickMock <AddIn>(), ref arr);
            tasks = new TaskList(app);
        }
        private static void ConfigureDynamicProxyToAvoidReplicatingProblematicAttributes()
        {
#pragma warning disable 618
            AttributesToAvoidReplicating.Add <SecurityPermissionAttribute>();
#pragma warning restore 618
            AttributesToAvoidReplicating.Add <ReflectionPermissionAttribute>();
            AttributesToAvoidReplicating.Add <PermissionSetAttribute>();
            AttributesToAvoidReplicating.Add <System.Runtime.InteropServices.MarshalAsAttribute>();
#if (NET4 || NET45)
            AttributesToAvoidReplicating.Add <System.Runtime.InteropServices.TypeIdentifierAttribute>();
#endif
            AttributesToAvoidReplicating.Add <UIPermissionAttribute>();
        }
Пример #7
0
        public static void AssemblyInit(TestContext context)
        {
            // Moq 4.0 Beta 3 (or rather the version of Castle DynamicProxy its using) has problems with some CAS attributes:
            // http://code.google.com/p/moq/issues/detail?id=250
            // This should be fixed in the next version of Moq and this Assembly init code should not be needed.
            AttributesToAvoidReplicating.Add <PermissionSetAttribute>();
            AttributesToAvoidReplicating.Add <ReflectionPermissionAttribute>();

            // Initialize the Url Rewriter status cache to indicate that Url Rewriter is present
            HttpContextBase httpContext = PathHelpersTest.GetMockHttpContext(includeRewriterServerVar: false).Object;

            PathHelpers.GenerateClientUrl(httpContext, "index.html");
        }
Пример #8
0
        static CastleProxyFactory()
        {
                        #if FEATURE_CAS
            AttributesToAvoidReplicating.Add <SecurityPermissionAttribute>();
            AttributesToAvoidReplicating.Add <ReflectionPermissionAttribute>();
            AttributesToAvoidReplicating.Add <PermissionSetAttribute>();
            AttributesToAvoidReplicating.Add <UIPermissionAttribute>();
                        #endif

                        #if FEATURE_COM
            AttributesToAvoidReplicating.Add <MarshalAsAttribute>();
            AttributesToAvoidReplicating.Add <TypeIdentifierAttribute>();
                        #endif
        }
        static CastleProxyFactory()
        {
#pragma warning disable 618
            AttributesToAvoidReplicating.Add <SecurityPermissionAttribute>();
#pragma warning restore 618

#if !SILVERLIGHT
            AttributesToAvoidReplicating.Add <ReflectionPermissionAttribute>();
            AttributesToAvoidReplicating.Add <PermissionSetAttribute>();
            AttributesToAvoidReplicating.Add <System.Runtime.InteropServices.MarshalAsAttribute>();
#if !NET3x
            AttributesToAvoidReplicating.Add <System.Runtime.InteropServices.TypeIdentifierAttribute>();
#endif
#endif
        }
Пример #10
0
        static DynamicAvatarFactory()
        {
            AttributesToAvoidReplicating.Add <SecurityPermissionAttribute>();
            AttributesToAvoidReplicating.Add <System.Runtime.InteropServices.MarshalAsAttribute>();
            AttributesToAvoidReplicating.Add <System.Runtime.InteropServices.TypeIdentifierAttribute>();

            options = new ProxyGenerationOptions {
                Hook = new ObjectMethodsHook()
            };
#if DEBUG
            // This allows invoking generator.ProxyBuilder.ModuleScope.SaveAssembly() for troubleshooting.
            generator = new ProxyGenerator(new DefaultProxyBuilder(new ModuleScope(true)));
#else
            generator = new ProxyGenerator();
#endif
        }
Пример #11
0
        static DynamicProxyFactory()
        {
            AttributesToAvoidReplicating.Add <System.Runtime.InteropServices.MarshalAsAttribute>();
            AttributesToAvoidReplicating.Add <System.Runtime.InteropServices.TypeIdentifierAttribute>();

            proxyOptions = new ProxyGenerationOptions {
                Hook = new ProxyMethodHook()
            };
            generator = new ProxyGenerator();

#if DEBUG
            // generator = new ProxyGenerator(new DefaultProxyBuilder(new ModuleScope(true)));
#else
            // generator = new ProxyGenerator();
#endif
        }
Пример #12
0
        static ProxyFactory()
        {
#pragma warning disable 618
            AttributesToAvoidReplicating.Add <SecurityPermissionAttribute> ();
#pragma warning restore 618

            AttributesToAvoidReplicating.Add <ReflectionPermissionAttribute> ();
            AttributesToAvoidReplicating.Add <PermissionSetAttribute> ();
            AttributesToAvoidReplicating.Add <System.Runtime.InteropServices.MarshalAsAttribute> ();
            AttributesToAvoidReplicating.Add <UIPermissionAttribute> ();
            AttributesToAvoidReplicating.Add <System.Runtime.InteropServices.TypeIdentifierAttribute> ();

            proxyOptions = new ProxyGenerationOptions {
                Hook = new ProxyMethodHook()
            };
            generator = new ProxyGenerator();
        }
Пример #13
0
        private static void ConfigureDynamicProxyToAvoidReplicatingProblematicAttributes()
        {
#pragma warning disable 618
            AttributesToAvoidReplicating.Add <SecurityPermissionAttribute>();
#pragma warning restore 618

            AttributesToAvoidReplicating.Add <System.ServiceModel.ServiceContractAttribute>();

#if !SILVERLIGHT
            AttributesToAvoidReplicating.Add <ReflectionPermissionAttribute>();
            AttributesToAvoidReplicating.Add <PermissionSetAttribute>();
            AttributesToAvoidReplicating.Add <System.Runtime.InteropServices.MarshalAsAttribute>();
#if NET4
            AttributesToAvoidReplicating.Add <System.Runtime.InteropServices.TypeIdentifierAttribute>();
#endif
#endif
        }
Пример #14
0
        static CastleProxyFactory()
        {
#if FEATURE_CAS
            AttributesToAvoidReplicating.Add <SecurityPermissionAttribute>();
            AttributesToAvoidReplicating.Add <ReflectionPermissionAttribute>();
            AttributesToAvoidReplicating.Add <PermissionSetAttribute>();
            AttributesToAvoidReplicating.Add <UIPermissionAttribute>();
#endif

#if FEATURE_COM
            AttributesToAvoidReplicating.Add <MarshalAsAttribute>();
            AttributesToAvoidReplicating.Add <TypeIdentifierAttribute>();
#endif

            proxyOptions = new ProxyGenerationOptions {
                Hook = new IncludeObjectMethodsHook()
            };
        }
Пример #15
0
        static CastleProxyFactory()
        {
#pragma warning disable 618
            AttributesToAvoidReplicating.Add <SecurityPermissionAttribute>();
#pragma warning restore 618

#if !SILVERLIGHT
            AttributesToAvoidReplicating.Add <ReflectionPermissionAttribute>();
            AttributesToAvoidReplicating.Add <PermissionSetAttribute>();
            AttributesToAvoidReplicating.Add <System.Runtime.InteropServices.MarshalAsAttribute>();
            AttributesToAvoidReplicating.Add <UIPermissionAttribute>();
#if !NET3x
            AttributesToAvoidReplicating.Add <System.Runtime.InteropServices.TypeIdentifierAttribute>();
#endif
#endif
            proxyOptions = new ProxyGenerationOptions {
                Hook = new ProxyMethodHook(), BaseTypeForInterfaceProxy = typeof(InterfaceProxy)
            };
        }
Пример #16
0
        static CastleDynamicProxyGenerator()
        {
#pragma warning disable 618
            AttributesToAvoidReplicating.Add(typeof(SecurityPermissionAttribute));
#pragma warning restore 618
        }
Пример #17
0
 public static void Initialize(TestContext context)
 {
     AttributesToAvoidReplicating.Add(typeof(ServiceContractAttribute));
 }
Пример #18
0
 private static bool SpecialCaseAttributThatShouldNotBeReplicated(Type attribute)
 {
     return(AttributesToAvoidReplicating.Contains(attribute) ||
            (!CheckDynamicallyInvokable(attribute)));
 }
Пример #19
0
 static CastleDynamicProxyGenerator()
 {
     AttributesToAvoidReplicating.Add(typeof(SecurityPermissionAttribute));
 }
Пример #20
0
 private static bool SpecialCaseAttributThatShouldNotBeReplicated(Type attribute)
 {
     return(AttributesToAvoidReplicating.Contains(attribute));
 }
 protected ServiceAttributeBase()
 {
     IsInitialized.GetOrAdd(GetType(), t => {
         AttributesToAvoidReplicating.Add(t);
         return(default);
     });
Пример #22
0
 public void MyTestInitialize()
 {
     AttributesToAvoidReplicating.Add(typeof(UIPermissionAttribute));
 }