Inheritance: BaseCodeGenerator
Ejemplo n.º 1
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;
		}
Ejemplo n.º 2
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 );
		}
Ejemplo n.º 3
0
		public Type CreateClassProxy(Type theClass, Type[] interfaces)
		{
			ClassProxyGenerator generator = new ClassProxyGenerator(_scope);
			return generator.GenerateCode(theClass, interfaces);
		}
Ejemplo n.º 4
0
		public virtual Type CreateCustomClassProxy(Type theClass, GeneratorContext context)
		{
			ClassProxyGenerator generator = new ClassProxyGenerator(_scope, context);
			return generator.GenerateCustomCode(theClass, null);
		}
Ejemplo n.º 5
0
		public virtual Type CreateClassProxy(Type theClass)
		{
			ClassProxyGenerator generator = new ClassProxyGenerator(_scope);
			return generator.GenerateCode(theClass);
		}