예제 #1
0
        /// <summary>
        /// The class which provides events for this object
        /// </summary>
        // private ComEventProvider _ComEventProvider; //dv: i don't need it

        #endregion

        #region Construction

        /// <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>
		/// The class which provides events for this object
		/// </summary>
		// private ComEventProvider _ComEventProvider; //dv: i don't need it

		#endregion

		#region Construction
		
		/// <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();
		}