CreateProxyType() публичный Метод

Creates a proxy type using the given baseType as the base class and ensures that the proxy type implements the given interface types.
public CreateProxyType ( Type baseType, IEnumerable baseInterfaces ) : Type
baseType System.Type The base class from which the proxy type will be derived.
baseInterfaces IEnumerable The list of interfaces that the proxy will implement.
Результат System.Type
Пример #1
0
        /// <summary>
        /// Initializes a new instance of the ProxyObjectReference class.
        /// </summary>
        /// <param name="info">The <see cref="SerializationInfo"/> class that contains the serialized data.</param>
        /// <param name="context">The <see cref="StreamingContext"/> that describes the serialization state.</param>
        protected ProxyObjectReference(SerializationInfo info, StreamingContext context)
        {
            // Deserialize the base type using its assembly qualified name
            string qualifiedName = info.GetString("__baseType");
            _baseType = Type.GetType(qualifiedName, true, false);

            // Rebuild the list of interfaces
            List<Type> interfaceList = new List<Type>();
            int interfaceCount = info.GetInt32("__baseInterfaceCount");
            for (int i = 0; i < interfaceCount; i++)
            {
                string keyName = string.Format("__baseInterface{0}", i);
                string currentQualifiedName = info.GetString(keyName);
                Type interfaceType = Type.GetType(currentQualifiedName, true, false);

                interfaceList.Add(interfaceType);
            }

            // Reconstruct the proxy
            ProxyFactory factory = new ProxyFactory();
            Type proxyType = factory.CreateProxyType(_baseType, interfaceList.ToArray());
            _proxy = (IProxy)Activator.CreateInstance(proxyType);

            IInterceptor interceptor = (IInterceptor)info.GetValue("__interceptor", typeof(IInterceptor));
            _proxy.Interceptor = interceptor;
        }
Пример #2
0
        /// <summary>
        ///     Initializes a new instance of the ProxyObjectReference class.
        /// </summary>
        /// <param name="info">The <see cref="SerializationInfo" /> class that contains the serialized data.</param>
        /// <param name="context">The <see cref="StreamingContext" /> that describes the serialization state.</param>
        protected ProxyObjectReference(SerializationInfo info, StreamingContext context)
        {
            // Deserialize the base type using its assembly qualified name
            var qualifiedName = info.GetString("__baseType");

            _baseType = Type.GetType(qualifiedName, true, false);

            // Rebuild the list of interfaces
            var interfaceList  = new List <Type>();
            var interfaceCount = info.GetInt32("__baseInterfaceCount");

            for (var i = 0; i < interfaceCount; i++)
            {
                var keyName = string.Format("__baseInterface{0}", i);
                var currentQualifiedName = info.GetString(keyName);
                var interfaceType        = Type.GetType(currentQualifiedName, true, false);

                interfaceList.Add(interfaceType);
            }

            // Reconstruct the proxy
            var factory   = new ProxyFactory();
            var proxyType = factory.CreateProxyType(_baseType, interfaceList.ToArray());

            _proxy = (IProxy)Activator.CreateInstance(proxyType);

            var interceptor = (IInterceptor)info.GetValue("__interceptor", typeof(IInterceptor));

            _proxy.Interceptor = interceptor;
        }