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, s_comObjectInfoKey); if (data != null) { return((ComObject)data); } lock (s_comObjectInfoKey) { data = Marshal.GetComObjectData(rcw, s_comObjectInfoKey); if (data != null) { return((ComObject)data); } ComObject comObjectInfo = CreateComObject(rcw); if (!Marshal.SetComObjectData(rcw, s_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 ((value != null) && (!WinRTHelper.IsWinRTType(value.GetType())) && ComObject.IsComObject(value)); }
internal ComObject(object rcw) { Debug.Assert(ComObject.IsComObject(rcw)); RuntimeCallableWrapper = rcw; }