示例#1
0
        public void FactoryForDefaultCtor()
        {
            var pcd = new ProxyClassDescriptor(
                new StaticFactoryMixin(typeof(Sample).GetConstructor(Type.EmptyTypes)));
            var proxyType = ProxyModule.Default.GetTypeFromProxyClassDescriptor(pcd);
            var ctor      = StaticFactoryMixin.GetCtor <Func <object> >(proxyType);
            var result    = ctor();

            Assert.That(result, Is.Not.Null);
            Assert.That(result, Is.TypeOf <Sample>());
        }
示例#2
0
        public object GetSafeProxyForType(Type type, object target)
        {
            Func <object, object> ctor;

            if (!_safeCtorCache.TryGetValue(type, out ctor))
            {
                var pcd = new ProxyClassDescriptor(
                    new StaticFactoryMixin(),
                    new RealSubjectMixin(type, new SafeDirectProxySubject(type), new SafeProxyMetaSubject()),
                    new MethodExistsProxyMetaMixin());
                Type proxyType = _proxyModule.GetTypeFromProxyClassDescriptor(pcd);
                ctor = _safeCtorCache.GetOrAdd(type, StaticFactoryMixin.GetCtor <Func <object, object> >(proxyType));
            }
            return(ctor(target));
        }
示例#3
0
 static Func <object, object> GetCtorForType(Type proxyType)
 {
     return(StaticFactoryMixin.GetCtor <Func <object, object> >(proxyType));
 }