public GenerateCode ( |
||
baseClass | ||
Результат |
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; }
public Type CreateClassProxy(Type theClass, Type[] interfaces) { ClassProxyGenerator generator = new ClassProxyGenerator(_scope); return generator.GenerateCode(theClass, interfaces); }
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 ); }
public virtual Type CreateClassProxy(Type theClass) { ClassProxyGenerator generator = new ClassProxyGenerator(_scope); return generator.GenerateCode(theClass); }