private static IEnumerable <DispatchMember> GetMembersRaw(this IDispatchEx dispatchEx) { var isEnumerable = false; int dispid; var result = dispatchEx.GetNextDispID(DispatchEnumFlags.All, SpecialDispIDs.StartEnum, out dispid); while (result == HResult.S_OK) { string name; if (HResult.Succeeded(dispatchEx.GetMemberName(dispid, out name))) { DispatchPropFlags flags; if (HResult.Succeeded(dispatchEx.GetMemberProperties(dispid, DispatchPropFlags.CanAll, out flags))) { if (dispid == SpecialDispIDs.NewEnum) { isEnumerable = true; } yield return(new DispatchMember(name, dispid, flags)); } } result = dispatchEx.GetNextDispID(DispatchEnumFlags.All, dispid, out dispid); } if (isEnumerable) { yield return(new DispatchMember("GetEnumerator", SpecialDispIDs.GetEnumerator, DispatchPropFlags.CanCall)); } }
private static int GetDispIDForName(this IDispatchEx dispatchEx, string name, bool ensure, bool ignoreCase) { var flags = ignoreCase ? DispatchNameFlags.CaseInsensitive : DispatchNameFlags.CaseSensitive; if (ensure) { flags |= DispatchNameFlags.Ensure; } var result = dispatchEx.GetDispID(name, flags, out var dispid); if (ensure && (result == HResult.DISP_E_UNKNOWNNAME)) { throw new NotSupportedException("The object does not support dynamic properties"); } if (HResult.Succeeded(result)) { return(dispid); } if (name.IsDispIDName(out dispid)) { return(dispid); } var member = dispatchEx.GetMembers().FirstOrDefault(testMember => testMember.Name.Equals(name, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal)); if (member != null) { return(member.DispID); } throw new MissingMemberException(MiscHelpers.FormatInvariant("The object has no property named '{0}'", name)); }
public static ITypeInfo GetTypeInfo(this IDispatch dispatch) { uint count; if (HResult.Succeeded(dispatch.GetTypeInfoCount(out count)) && (count > 0)) { ITypeInfo typeInfo; if (HResult.Succeeded(dispatch.GetTypeInfo(0, 0, out typeInfo))) { return(typeInfo); } } return(null); }
private static int GetDispIDForName(this IDispatch dispatch, string name) { var dispids = new int[1]; var names = new[] { name }; if (HResult.Succeeded(dispatch.GetIDsOfNames(ref iid, names, 1, 0, dispids))) { return(dispids[0]); } if (name.IsDispIDName(out dispids[0])) { return(dispids[0]); } var member = dispatch.GetMembers().FirstOrDefault(testMember => testMember.Name == name); if (member == null) { throw new MissingMemberException(MiscHelpers.FormatInvariant("The object has no property named '{0}'", name)); } return(member.DispID); }