Пример #1
0
        public static IProxy CreateProxy(this Type type, params Type[] baseInterfaces)
        {
            Type   proxyType = _factory.CreateProxyType(type, baseInterfaces);
            IProxy result    = (IProxy)Activator.CreateInstance(proxyType);

            return(result);
        }
Пример #2
0
        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());

            // Initialize the proxy with the deserialized data
            object[] args = new object[] { info, context };
            _proxy = (IProxy)Activator.CreateInstance(proxyType, args);
        }