public void PostInstantiate(string entityName, Type persistentClass, ISet <Type> interfaces, MethodInfo getIdentifierMethod, MethodInfo setIdentifierMethod, IAbstractComponentType componentIdType)
        {
            if (persistentClass.IsGenericType)
            {
                return;
            }

            int  interfacesCount = interfaces.Count;
            bool isClassProxy    = interfacesCount == 1;

            Type[] ifaces = new Type[interfacesCount];
            interfaces.CopyTo(ifaces, 0);

            Type proxyType;

            if (isClassProxy)
            {
                proxyType = _proxyBuilder.CreateClassProxy(persistentClass, ifaces, ProxyGenerationOptions.Default);
            }
            else
            {
                proxyType = _proxyBuilder.CreateInterfaceProxyTypeWithoutTarget(ifaces[0], ifaces, ProxyGenerationOptions.Default);
            }

            _proxies[entityName] = proxyType;
        }
        private Type GetProxyType(CompositeType compositeType)
        {
            if (compositeType == null)
            {
                throw new ArgumentNullException("compositeType");
            }

            if (!CachedProxyTypes.ContainsKey(compositeType))
            {
                Type[] additionalInterfaceTypes = BuildAdditionalTypeArrayForProxyType(compositeType);
                Type   proxyType;

                /* ^ */ var _typeInfo = compositeType.PrimaryType.GetTypeInfo();                 /* [email protected] ^ */

                if (/* ^ */ _typeInfo.IsClass /* [email protected] ^ */)
                {
                    if (/* ^ */ _typeInfo.IsSealed /* [email protected] ^ */)
                    {
                        throw new ArgumentException("Cannot mock sealed classes.");
                    }

                    proxyType = ProxyBuilder.CreateClassProxyType(compositeType.PrimaryType, additionalInterfaceTypes, ProxyGenerationOptions.Default);
                }
                else
                {
                    proxyType = ProxyBuilder.CreateInterfaceProxyTypeWithoutTarget(compositeType.PrimaryType, additionalInterfaceTypes, new ProxyGenerationOptions {
                        BaseTypeForInterfaceProxy = typeof(InterfaceMockBase)
                    });
                }

                lock (locker)
                {
                    if (!CachedProxyTypes.ContainsKey(compositeType))
                    {
                        CachedProxyTypes[compositeType] = proxyType;
                    }
                }
                return(proxyType);
            }

            return(CachedProxyTypes[compositeType]);
        }
示例#3
0
 public Type CreateInterfaceProxyTypeWithoutTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy,
                                                   ProxyGenerationOptions options)
 {
     return(_baseProxyBuilder.CreateInterfaceProxyTypeWithoutTarget(interfaceToProxy, additionalInterfacesToProxy, options));
 }