Пример #1
0
        /// <summary>
        /// Creates a COM object and returns the transparent proxy
        /// which intercepts all calls to the object
        /// </summary>
        /// <param name="type">Interface which defines the method and properties to intercept</param>
        /// <returns>Transparent proxy to the real proxy for the object</returns>
        /// <remarks>
        /// The <paramref name="type"/> must be an interface decorated with
        /// the <see cref="ComProgIdAttribute"/> attribute.
        /// </remarks>
        public static object CreateInstance(Type type)
        {
            if (null == type)
            {
                throw new ArgumentNullException("type");
            }
            if (!type.IsInterface)
            {
                throw new ArgumentException("The specified type must be an interface.", "type");
            }

            ComProgIdAttribute progID = ComProgIdAttribute.GetAttribute(type);

            if (null == progID || null == progID.Value || 0 == progID.Value.Length)
            {
                throw new ArgumentException("The specified type must define a ComProgId attribute.", "type");
            }

            Type   comType   = Type.GetTypeFromProgID(progID.Value, true);
            object comObject = Activator.CreateInstance(comType);

            if (null == comObject)
            {
                throw new TypeLoadException(
                          string.Format("Unable to create an instance of the specified COM server \"{0}\".",
                                        progID.Value));
            }

            COMWrapper wrapper = new COMWrapper(comObject, type);

            return(wrapper.GetTransparentProxy());
        }
Пример #2
0
		/// <summary>
		/// Wrap an object and return the transparent proxy which intercepts all calls
		/// to the object
		/// </summary>
		/// <param name="comObject">An object to intercept</param>
		/// <param name="type">Interface which defines the method and properties to intercept</param>
		/// <returns>Transparent proxy to the real proxy for the object</returns>
		public static object Wrap(object comObject, Type type)
		{
			if (null == comObject) throw new ArgumentNullException("comObject");
			if (null == type) throw new ArgumentNullException("type");
			
			COMWrapper wrapper = new COMWrapper(comObject, type);
			return wrapper.GetTransparentProxy();
		}
Пример #3
0
		/// <summary>
		/// Creates a COM object and returns the transparent proxy 
		/// which intercepts all calls to the object
		/// </summary>
		/// <param name="type">Interface which defines the method and properties to intercept</param>
		/// <returns>Transparent proxy to the real proxy for the object</returns>
		/// <remarks>
		/// The <paramref name="type"/> must be an interface decorated with
		/// the <see cref="ComProgIdAttribute"/> attribute.
		/// </remarks>
		public static object CreateInstance(Type type)
		{
			if (null == type) throw new ArgumentNullException("type");
			if (!type.IsInterface) throw new ArgumentException("The specified type must be an interface.", "type");
			
			ComProgIdAttribute progID = ComProgIdAttribute.GetAttribute(type);
			if (null == progID || null == progID.Value || 0 == progID.Value.Length)
				throw new ArgumentException("The specified type must define a ComProgId attribute.", "type");
			
			Type comType = Type.GetTypeFromProgID(progID.Value, true);
			object comObject = Activator.CreateInstance(comType);
			if (null == comObject)
			{
				throw new TypeLoadException(
					string.Format("Unable to create an instance of the specified COM server \"{0}\".",
					progID.Value));
			}
			
			COMWrapper wrapper = new COMWrapper(comObject, type);
			return wrapper.GetTransparentProxy();
		}
Пример #4
0
		/// <summary>
		/// Wrap an object and return the transparent proxy which intercepts all calls
		/// to the object
		/// </summary>
		/// <param name="comObject">An object to intercept</param>
		/// <param name="type">Interface which defines the method and properties to intercept</param>
		/// <returns>Transparent proxy to the real proxy for the object</returns>
		public static object Wrap(object comObject, Type type)
		{
			if (null == comObject) throw new ArgumentNullException("comObject");
			if (null == type) throw new ArgumentNullException("type");
			
			COMWrapper wrapper = new COMWrapper(comObject, type);
			return wrapper.GetTransparentProxy();
		}