Exemplo n.º 1
0
        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));
            }
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }