本文整理汇总了C#中GeneratorContext.AddMixinInstance方法的典型用法代码示例。如果您正苦于以下问题:C# GeneratorContext.AddMixinInstance方法的具体用法?C# GeneratorContext.AddMixinInstance怎么用?C# GeneratorContext.AddMixinInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GeneratorContext
的用法示例。
在下文中一共展示了GeneratorContext.AddMixinInstance方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TwoMixins
public void TwoMixins()
{
GeneratorContext context = new GeneratorContext();
SimpleMixin mixin1 = new SimpleMixin();
OtherMixin mixin2 = new OtherMixin();
context.AddMixinInstance( mixin1 );
context.AddMixinInstance( mixin2 );
AssertInvocationInterceptor interceptor = new AssertInvocationInterceptor();
object proxy = _generator.CreateCustomClassProxy(
typeof(SimpleClass), interceptor, context );
Assert.IsFalse( interceptor.Invoked );
Assert.IsNotNull(proxy);
Assert.IsTrue( typeof(SimpleClass).IsAssignableFrom( proxy.GetType() ) );
ISimpleMixin mixin = proxy as ISimpleMixin;
Assert.IsNotNull(mixin);
Assert.AreEqual(1, mixin.DoSomething());
Assert.IsTrue( interceptor.Invoked );
Assert.AreSame( proxy, interceptor.proxy );
Assert.AreSame( mixin1, interceptor.mixin );
IOtherMixin other = proxy as IOtherMixin;
Assert.IsNotNull(other);
Assert.AreEqual(3, other.Sum(1,2));
Assert.IsTrue( interceptor.Invoked );
Assert.AreSame( proxy, interceptor.proxy );
Assert.AreSame( mixin2, interceptor.mixin );
}
示例2: MixinForInterfaces
public void MixinForInterfaces()
{
GeneratorContext context = new GeneratorContext();
SimpleMixin mixin_instance = new SimpleMixin();
context.AddMixinInstance( mixin_instance );
AssertInvocationInterceptor interceptor = new AssertInvocationInterceptor();
MyInterfaceImpl target = new MyInterfaceImpl();
object proxy = _generator.CreateCustomProxy(
typeof(IMyInterface), interceptor, target, context );
Assert.IsNotNull(proxy);
Assert.IsTrue( typeof(IMyInterface).IsAssignableFrom( proxy.GetType() ) );
Assert.IsFalse( interceptor.Invoked );
ISimpleMixin mixin = proxy as ISimpleMixin;
Assert.IsNotNull(mixin);
Assert.AreEqual(1, mixin.DoSomething());
Assert.IsTrue( interceptor.Invoked );
Assert.AreSame( proxy, interceptor.proxy );
Assert.AreSame( mixin_instance, interceptor.mixin );
}
示例3: MixinImplementingMoreThanOneInterface
public void MixinImplementingMoreThanOneInterface()
{
GeneratorContext context = new GeneratorContext();
ComplexMixin mixin_instance = new ComplexMixin();
context.AddMixinInstance( mixin_instance );
AssertInvocationInterceptor interceptor = new AssertInvocationInterceptor();
object proxy = _generator.CreateCustomClassProxy(
typeof(SimpleClass), interceptor, context );
Assert.IsNotNull(proxy);
Assert.IsTrue( typeof(SimpleClass).IsAssignableFrom( proxy.GetType() ) );
Assert.IsFalse( interceptor.Invoked );
IThird inter3 = proxy as IThird;
Assert.IsNotNull(inter3);
inter3.DoThird();
Assert.IsTrue( interceptor.Invoked );
Assert.AreSame( proxy, interceptor.proxy );
Assert.AreSame( mixin_instance, interceptor.mixin );
ISecond inter2 = proxy as ISecond;
Assert.IsNotNull(inter2);
inter2.DoSecond();
Assert.IsTrue( interceptor.Invoked );
Assert.AreSame( proxy, interceptor.proxy );
Assert.AreSame( mixin_instance, interceptor.mixin );
IFirst inter1 = proxy as IFirst;
Assert.IsNotNull(inter1);
inter1.DoFirst();
Assert.IsTrue( interceptor.Invoked );
Assert.AreSame( proxy, interceptor.proxy );
Assert.AreSame( mixin_instance, interceptor.mixin );
}
示例4: RecreateInterfaceProxy
public object RecreateInterfaceProxy(SerializationInfo info, StreamingContext context)
{
object proxy = null;
GeneratorContext genContext = new GeneratorContext();
foreach(object mixin in _mixins)
{
genContext.AddMixinInstance(mixin);
}
InterfaceProxyGenerator gen = new InterfaceProxyGenerator( _scope, genContext );
object target = info.GetValue("__target", typeof(object));
if (_mixins.Length == 0)
{
Type proxy_type = gen.GenerateCode( _interfaces, target.GetType());
proxy = Activator.CreateInstance( proxy_type, new object[] { _interceptor, target } );
}
else
{
Type proxy_type = gen.GenerateCode( _interfaces, target.GetType() );
proxy = Activator.CreateInstance( proxy_type, new object[] { _interceptor, target, genContext.MixinsAsArray() } );
}
return proxy;
}
示例5: RecreateClassProxy
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;
}
示例6: XmlSerialization
public void XmlSerialization()
{
ProxyObjectReference.ResetScope();
GeneratorContext context = new GeneratorContext();
SimpleMixin mixin1 = new SimpleMixin();
OtherMixin mixin2 = new OtherMixin();
context.AddMixinInstance( mixin1 );
context.AddMixinInstance( mixin2 );
object proxy = generator.CreateCustomClassProxy(
typeof(SimpleClass), new StandardInterceptor(), context );
System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(SimpleClass));
MemoryStream stream = new MemoryStream();
serializer.Serialize(stream, proxy);
stream.Position = 0;
SimpleClass otherProxy = (SimpleClass) serializer.Deserialize( stream );
ISimpleMixin mixin = otherProxy as ISimpleMixin;
Assert.AreEqual(1, mixin.DoSomething());
IOtherMixin other = otherProxy as IOtherMixin;
Assert.AreEqual(3, other.Sum(1,2));
}
示例7: MixinSerialization
public void MixinSerialization()
{
ProxyObjectReference.ResetScope();
GeneratorContext context = new GeneratorContext();
SimpleMixin mixin1 = new SimpleMixin();
OtherMixin mixin2 = new OtherMixin();
context.AddMixinInstance( mixin1 );
context.AddMixinInstance( mixin2 );
object proxy = generator.CreateCustomClassProxy(
typeof(SimpleClass), new StandardInterceptor(), context );
Assert.IsTrue( typeof(SimpleClass).IsAssignableFrom( proxy.GetType() ) );
(proxy as SimpleClass).DoSome();
ISimpleMixin mixin = proxy as ISimpleMixin;
Assert.AreEqual(1, mixin.DoSomething());
IOtherMixin other = proxy as IOtherMixin;
Assert.AreEqual(3, other.Sum(1,2));
SimpleClass otherProxy = (SimpleClass) SerializeAndDeserialize(proxy);
otherProxy.DoSome();
mixin = otherProxy as ISimpleMixin;
Assert.AreEqual(1, mixin.DoSomething());
other = otherProxy as IOtherMixin;
Assert.AreEqual(3, other.Sum(1,2));
}