Exemplo n.º 1
0
        public object RecreateClassProxy()
        {
            var generator = new ClassProxyGenerator(scope, baseType);
            var proxyType = generator.GenerateCode(interfaces, proxyGenerationOptions);

            return(InstantiateClassProxy(proxyType));
        }
        public void MethodBodyGetterCall()
        {
            var methodDescription = new MethodDescription(
                "myMethod",
                new List <ModifierDescription> {
                ModifierDescription.PUBLIC
            },
                new List <ParameterDescription>(),
                "void"
                );

            var classDescription = new ClassDescription(
                "MyClass",
                "packageName",
                new List <ModifierDescription>(),
                new List <FieldDescription>(),
                new List <MethodDescription> {
                methodDescription
            },
                new List <string>(),
                new List <ClassDescription>(),
                isNested: false);

            var methodBodyGetter    = new MockMethodBodyGetter();
            var classProxyGenerator = new ClassProxyGenerator(methodBodyGetter);

            classProxyGenerator.Generate(classDescription);

            Assert.AreEqual(1, methodBodyGetter.CallsCount);
            Assert.AreEqual("myMethod", methodBodyGetter.CallArgumentName);
        }
Exemplo n.º 3
0
        public object RecreateClassProxy(SerializationInfo info, StreamingContext context)
        {
            bool delegateBaseSer = info.GetBoolean("__delegateToBase");

            if (!delegateBaseSer)
            {
                _data = (object[])info.GetValue("__data", typeof(object[]));
            }

            object proxy = null;

            GeneratorContext genContext = new GeneratorContext();

            if (_mixins.Length != 0)
            {
                foreach (object mixin in _mixins)
                {
                    genContext.AddMixinInstance(mixin);
                }
            }

            ClassProxyGenerator cpGen = new ClassProxyGenerator(_scope, genContext);

            Type proxy_type;

            if (_mixins.Length == 0)
            {
                proxy_type = cpGen.GenerateCode(_baseType, _interfaces);
            }
            else
            {
                proxy_type = cpGen.GenerateCustomCode(_baseType, _interfaces);
            }

            if (delegateBaseSer)
            {
                proxy = Activator.CreateInstance(proxy_type, new object[] { info, context });
            }
            else
            {
                if (_mixins.Length == 0)
                {
                    proxy = Activator.CreateInstance(proxy_type, new object[] { _interceptor });
                }
                else
                {
                    ArrayList args = new ArrayList();
                    args.Add(_interceptor);
                    args.Add(genContext.MixinsAsArray());

                    proxy = Activator.CreateInstance(proxy_type, args.ToArray());
                }

                MemberInfo[] members = FormatterServices.GetSerializableMembers(_baseType);
                FormatterServices.PopulateObjectMembers(proxy, members, _data);
            }

            return(proxy);
        }
Exemplo n.º 4
0
        public ClassProxyGenerator_should()
        {
            var methodBodyGetter          = new MethodBodyGetter("classRef", "jObject");
            var methodProxyGenerator      = new MethodProxyGenerator(methodBodyGetter);
            var constructorProxyGenerator = new ConstructorProxyGenerator(methodBodyGetter);

            classProxyGenerator = new ClassProxyGenerator(methodProxyGenerator, constructorProxyGenerator);
        }
Exemplo n.º 5
0
        public Type CreateClassProxyType(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options)
        {
            AssertValidType(classToProxy);
            AssertValidTypes(additionalInterfacesToProxy);

            var generator = new ClassProxyGenerator(scope, classToProxy)
            {
                Logger = logger
            };

            return(generator.GenerateCode(additionalInterfacesToProxy, options));
        }
        public object RecreateClassProxy(SerializationInfo info, StreamingContext context)
        {
            Type type;
            bool boolean = info.GetBoolean("__delegateToBase");

            if (!boolean)
            {
                this._data = (object[])info.GetValue("__data", typeof(object[]));
            }
            object           obj2     = null;
            GeneratorContext context2 = new GeneratorContext();

            if (this._mixins.Length != 0)
            {
                foreach (object obj3 in this._mixins)
                {
                    context2.AddMixinInstance(obj3);
                }
            }
            ClassProxyGenerator generator = new ClassProxyGenerator(_scope, context2);

            if (this._mixins.Length == 0)
            {
                type = generator.GenerateCode(this._baseType, this._interfaces);
            }
            else
            {
                type = generator.GenerateCustomCode(this._baseType, this._interfaces);
            }
            if (boolean)
            {
                return(Activator.CreateInstance(type, new object[] { info, context }));
            }
            if (this._mixins.Length == 0)
            {
                obj2 = Activator.CreateInstance(type, new object[] { this._interceptor });
            }
            else
            {
                ArrayList list = new ArrayList();
                list.Add(this._interceptor);
                list.Add(context2.MixinsAsArray());
                obj2 = Activator.CreateInstance(type, list.ToArray());
            }
            MemberInfo[] serializableMembers = FormatterServices.GetSerializableMembers(this._baseType);
            FormatterServices.PopulateObjectMembers(obj2, serializableMembers, this._data);
            return(obj2);
        }
        public void Generate(
            LibraryDescription description,
            string assemblyName,
            string assemblyOutputPath,
            Action <IEnumerable <SyntaxNode> > sourceWriter = null,
            Action <string> compiltionLogWriter             = null)
        {
            var classGenerator = new ClassProxyGenerator(new MethodBodyGetter());
            var proxySource    = new LibraryProxyGenerator(classGenerator).Generate(description);

            var trees = CompilationTreesGetter.GetCompilationTreesFrom(proxySource);

            sourceWriter?.Invoke(trees.Select(el => el.GetRoot()));

            new Compiller().Compile(trees, assemblyName, assemblyOutputPath, compiltionLogWriter);
        }
Exemplo n.º 8
0
        public object RecreateClassProxy()
        {
            delegateToBase = GetValue <bool>("__delegateToBase");

            ClassProxyGenerator cpGen = new ClassProxyGenerator(scope, baseType);

            Type proxy_type = cpGen.GenerateCode(interfaces, proxyGenerationOptions);


            if (delegateToBase)
            {
                return(Activator.CreateInstance(proxy_type, new object[] { info, context }));
            }
            else
            {
                return(FormatterServices.GetSafeUninitializedObject(proxy_type));
            }
        }
Exemplo n.º 9
0
        public void CustomMarkerInterface()
        {
            ProxyObjectReference.ResetScope();

            ClassProxyGenerator classGenerator = new ClassProxyGenerator(
                new ModuleScope(), new GeneratorContext());

            Type proxyType = classGenerator.GenerateCode(typeof(ClassWithMarkerInterface), new Type[] { typeof(IMarkerInterface) });

            object proxy = Activator.CreateInstance(proxyType, new object[] { new StandardInterceptor() });

            Assert.IsNotNull(proxy);
            Assert.IsTrue(proxy is IMarkerInterface);

            object otherProxy = SerializeAndDeserialize(proxy);

            Assert.IsTrue(otherProxy is IMarkerInterface);
        }
Exemplo n.º 10
0
        public void Generate(
            LibraryDescription description,
            string assemblyName,
            string assemblyOutputPath,
            Action <IEnumerable <string> > sourceLogger = null,
            Action <string> compiltionLogger            = null)
        {
            var methodBodyGetter          = new MethodBodyGetter("classRef", "jObject");
            var methodProxyGenerator      = new MethodProxyGenerator(methodBodyGetter);
            var constructorProxyGenerator = new ConstructorProxyGenerator(methodBodyGetter);

            var classGenerator = new ClassProxyGenerator(methodProxyGenerator, constructorProxyGenerator);
            var proxySource    = new LibraryProxyGenerator(classGenerator).Generate(description);

            var trees = CompilationTreesGetter.GetCompilationTreesFrom(proxySource);

            sourceLogger?.Invoke(trees.Select(el => el
                                              .GetRoot()
                                              .NormalizeWhitespace()
                                              .ToFullString())
                                 );

            new Compiller().Compile(trees, assemblyName, assemblyOutputPath, compiltionLogger);
        }
        public virtual Type CreateCustomClassProxy(Type theClass, GeneratorContext context)
        {
            ClassProxyGenerator generator = new ClassProxyGenerator(_scope, context);

            return(generator.GenerateCustomCode(theClass, null));
        }
        public Type CreateClassProxy(Type theClass, Type[] interfaces)
        {
            ClassProxyGenerator generator = new ClassProxyGenerator(_scope);

            return(generator.GenerateCode(theClass, interfaces));
        }
        public virtual Type CreateClassProxy(Type theClass)
        {
            ClassProxyGenerator generator = new ClassProxyGenerator(_scope);

            return(generator.GenerateCode(theClass));
        }
 public virtual Type CreateCustomClassProxy(Type theClass, GeneratorContext context)
 {
     ClassProxyGenerator generator = new ClassProxyGenerator(m_scope, context);
     return generator.GenerateCode( theClass );
 }
 public virtual Type CreateClassProxy(Type theClass)
 {
     ClassProxyGenerator generator = new ClassProxyGenerator(m_scope);
     return generator.GenerateCode( theClass );
 }