public static ComObject ObjectToComObject(object rcw) { Debug.Assert(ComObject.IsComObject(rcw)); // Marshal.Get/SetComObjectData has a LinkDemand for UnmanagedCode which will turn into // a full demand. We could avoid this by making this method SecurityCritical object data = Marshal.GetComObjectData(rcw, _ComObjectInfoKey); if (data != null) { return((ComObject)data); } lock (_ComObjectInfoKey) { data = Marshal.GetComObjectData(rcw, _ComObjectInfoKey); if (data != null) { return((ComObject)data); } ComObject comObjectInfo = CreateComObject(rcw); if (!Marshal.SetComObjectData(rcw, _ComObjectInfoKey, comObjectInfo)) { throw Error.SetComObjectDataFailed(); } return(comObjectInfo); } }
/// <summary> /// Determines if an object is a COM object. /// </summary> /// <param name="value">The object to test.</param> /// <returns>true if the object is a COM object, false otherwise.</returns> public static bool IsComObject(object value) { return(ComObject.IsComObject(value)); }
internal ComObject(object rcw) { Debug.Assert(ComObject.IsComObject(rcw)); _rcw = rcw; }