Ejemplo n.º 1
0
        /// <summary>
        /// Gets a <see cref="ComObject"/> that wraps the runtime-callable-wrapper, or creates one if none currently exists.
        /// </summary>
        /// <returns></returns>
        public static ComObject ObjectToComObject(object rcw)
        {
            Debug.Assert(ComBinder.IsComObject(rcw));

            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);
            }
        }
Ejemplo n.º 2
0
 internal ComObject(object rcw)
 {
     Debug.Assert(ComBinder.IsComObject(rcw));
     RuntimeCallableWrapper = rcw;
 }