private ICOMObject InternalCreateKnownObjectFromComProxy(ICOMObject caller, object comProxy, Type contractWrapperType) { CheckInitialize(); try { ICOMObject result = null; lock (_createComObjectLock) { TypeInformation typeInfo = CoreTypeExtensions.GetTypeInformationForKnownObject(this, contractWrapperType, comProxy); if (null != typeInfo) { result = CoreCreateExtensions.CreateInstance(this, typeInfo, caller, comProxy); } else { result = CoreCreateExtensions.TryCreateObjectByResolveEvent(this, caller, contractWrapperType, contractWrapperType); if (null == result) { throw new FactoryException(String.Format("Unable to find implementation: {0}.", contractWrapperType.FullName)); } } //result = InternalObjectActivator.TryReplaceInstance(caller, result); return(result); } } catch (Exception throwedException) { Console.WriteException(throwedException); throw; } }
/// <summary> /// Creates a new ICOMObject based on classType of comProxy /// </summary> /// <param name="caller">parent there have created comProxy</param> /// <param name="comProxy">new created proxy</param> /// <param name="allowDynamicObject">allow to create a COMDynamicObject instance if its failed to resolve the wrapper type</param> /// <returns>corresponding wrapper class instance or plain COMObject</returns> /// <exception cref="ArgumentNullException">comProxy arguments is null</exception> /// <exception cref="CreateInstanceException">throws when its failed to create new instance</exception> /// <exception cref="FactoryException">throws when its failed to find the corresponding factory. this indicates a missing netoffice api assembly</exception> /// <exception cref="NetOfficeInitializeException">unexpected initialization error. see inner exception(s) for details</exception> public virtual ICOMObject CreateObjectFromComProxy(ICOMObject caller, object comProxy, bool allowDynamicObject) { if (null == caller) { throw new ArgumentNullException("caller"); } CheckInitialize(); try { ICOMObject result = null; Guid typeId = Guid.Empty; Guid componentId = Guid.Empty; CoreTypeExtensions.GetComponentAndTypeId(this, comProxy, ref componentId, ref typeId); lock (_createComObjectLock) { // get type factory first to handle possible duplicate type ITypeFactory factoryInfo = CoreFactoryExtensions.GetTypeFactory(this, caller, comProxy, componentId, typeId, false); if (null != factoryInfo) { TypeInformation typeInfo = CoreTypeExtensions.GetTypeInformationForUnknownObject(this, factoryInfo, typeId, comProxy); if (null == typeInfo) { throw new FactoryException(String.Format("Unable to resolve proxy type:{0}", ComTypes.TypeDescriptor.GetFullComponentClassName(comProxy))); } result = CoreCreateExtensions.CreateInstance(this, typeInfo, caller, comProxy); //result = InternalObjectActivator.TryReplaceInstance(caller, result); } else { result = CoreCreateExtensions.TryCreateObjectByResolveEvent(this, caller, null, comProxy); if (null == result) { if (allowDynamicObject && Settings.EnableDynamicObjects) { result = InternalObjectActivator.RaiseCreateCOMDynamic(caller, comProxy); if (null == result) { result = new COMDynamicObject(caller, comProxy); } } else { throw new FactoryException(String.Format("Unable to resolve proxy type:{0}", ComTypes.TypeDescriptor.GetFullComponentClassName(comProxy))); } } } return(result); } } catch (Exception throwedException) { Console.WriteException(throwedException); throw; } }