/// <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); } }
public override DynamicMetaObject FallbackInvoke(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion) { if (ComBinder.TryBindInvoke(this, target, args, out DynamicMetaObject res)) { return(res); } return(errorSuggestion ?? new DynamicMetaObject( Expression.Throw( Expression.New( typeof(NotSupportedException).GetConstructor(new[] { typeof(string) }), Expression.Constant(ParserStrings.CannotCall) ), typeof(object) ), target.Restrictions.Merge(BindingRestrictions.Combine(args)) )); }
internal ComObject(object rcw) { Debug.Assert(ComBinder.IsComObject(rcw)); RuntimeCallableWrapper = rcw; }