C# 如何识别一个;“默认成员”;在COM库中?

C# 如何识别一个;“默认成员”;在COM库中?,c#,com,C#,Com,我正在使用ITypeInfoAPI将COM类型库“转换”为我的应用程序使用的“声明”对象 “声明”的一个特性是“属性”-我能够告诉属性“声明”何时应该具有{name}.VB_UserMemId=-4属性(即,当它是\u NewEnum不可浏览属性时;我还能够告诉属性何时被隐藏 我没有告诉您的是,成员何时是该类型的默认成员。根据FUNCFLAG\u FDEFAULTBIND()的描述: 最能代表对象的函数。类型信息中只有一个函数可以具有此属性 …这听起来很像我正在寻找的。但是在所有成员中,我迭代了

我正在使用
ITypeInfo
API将COM类型库“转换”为我的应用程序使用的“声明”对象

“声明”的一个特性是“属性”-我能够告诉属性“声明”何时应该具有
{name}.VB_UserMemId=-4
属性(即,当它是
\u NewEnum
不可浏览属性时;我还能够告诉属性何时被隐藏

我没有告诉您的是,成员何时是该类型的默认成员。根据
FUNCFLAG\u FDEFAULTBIND
()的描述:

最能代表对象的函数。类型信息中只有一个函数可以具有此属性

…这听起来很像我正在寻找的。但是在所有成员中,我迭代了几个类型库(包括VBA标准库和整个Excel对象模型),没有一个启用该标志

我希望此代码调用
AddDefaultMemberAttribute
来处理
Collection.Item
,这是类型的默认成员,但没有骰子。我是否没有检查正确的标志/值

var attributes = new Attributes();
if (((FUNCFLAGS)memberDescriptor.wFuncFlags) != 0)
{
    if (memberName == "_NewEnum" && ((FUNCFLAGS)memberDescriptor.wFuncFlags).HasFlag(FUNCFLAGS.FUNCFLAG_FNONBROWSABLE))
    {
        attributes.AddEnumeratorMemberAttribute(memberName);
    }
    else if (((FUNCFLAGS)memberDescriptor.wFuncFlags).HasFlag(FUNCFLAGS.FUNCFLAG_FHIDDEN))
    {
        attributes.AddHiddenMemberAttribute(memberName);
    }
    else if (((FUNCFLAGS)memberDescriptor.wFuncFlags).HasFlag(FUNCFLAGS.FUNCFLAG_FDEFAULTBIND))
    {
        // bug: none of the 30K+ reflected members have this flag on??
        attributes.AddDefaultMemberAttribute(memberName);
    }
}

删除对
wFuncFlags!=0的检查,您将跳过大量使用该检查的成员,其中许多是您真正感兴趣的成员

现在检查
memid==0
()

这个小的
Debug.WriteLine
指令产生这个输出(被截断,以适应post字符限制):

找到的默认成员:_ErrObject.Number(PropertyGet/VT_I4) 找到默认成员:\u ErrObject.Number(PropertyLet/VT\u VOID) 找到默认成员:_Collection.Item(函数/VT_变量) 找到默认成员:Adjusts.Item(PropertyGet/VT_R4) 找到默认成员:Adjustments.Item(PropertyLet/VT\u VOID) 找到默认成员:ColorFormat.RGB(PropertyGet/VT_用户定义) 找到默认成员:ColorFormat.RGB(PropertyLet/VT\u VOID) 找到默认成员:ShapeNodes.Item(函数/VT\u PTR) 找到默认成员:DiagramNodes.Item(函数/VT\u PTR) 找到默认成员:DiagramNodeChildren.Item(函数/VT\u PTR) 找到默认成员:IWindows.\u默认(PropertyGet/VT\u HRESULT) 找到默认成员:\应用程序。\默认(PropertyGet/VT\BSTR) 找到默认成员:IRange.\u默认(PropertyGet/VT\u HRESULT) 找到默认成员:IRange.\u默认(PropertyLet/VT\u HRESULT) 找到默认成员:工作表。\u默认值(PropertyGet/VT\u DISPATCH) 找到默认成员:IHPageBreaks.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:IVPageBreaks.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:IRecentFiles.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:IStyle.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:IStyles.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:IBorders.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:IAddIns.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:IToolbars.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:IToolbarButtons.\u默认(PropertyGet/VT\u HRESULT) 找到默认成员:IAreas.\u默认(PropertyGet/VT\u HRESULT) 找到默认成员:工作簿。\u默认值(PropertyGet/VT\u PTR) 找到默认成员:IMenuBars.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:IMenus.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:IMenuItems.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:ICharts.\u默认(PropertyGet/VT\u HRESULT) 找到默认成员:IDrawingObjects.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:IDrawingObjects.\u默认值(PropertyLet/VT\u HRESULT) 找到默认成员:ipivocaches.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:IPivotFormula.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:IPivotFormula.\u默认值(PropertyLet/VT\u HRESULT) 找到默认成员:IPivotFormulas.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:IPivotTable.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:IPivotTable.\u默认值(PropertyLet/VT\u HRESULT) 找到默认成员:IPivotField.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:IPivotField.\u默认值(PropertyLet/VT\u HRESULT) 找到默认成员:ICalculatedFields.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:IPivotItem.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:IPivotItem.\u默认值(PropertyLet/VT\u HRESULT) 找到默认成员:ICalculatedItems.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:IDialogs.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:ICheckBox.\u默认(PropertyGet/VT\u HRESULT) 找到默认成员:ICheckBox.\u默认值(PropertyLet/VT\u HRESULT) 找到默认成员:ICheckBox.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:ICheckBox.\u默认值(PropertyLet/VT\u HRESULT) 找到默认成员:IOptionButton.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:IOptionButton.\u默认值(PropertyLet/VT\u HRESULT) 找到默认成员:IOptionButtons.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:IOptionButtons.\u默认值(PropertyLet/VT\u HRESULT) 找到默认成员:IScrollBar.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:IScrollBar.\u默认值(PropertyLet/VT\u HRESULT) 找到默认成员:IScrollBars.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:IScrollBars.\u默认值(PropertyLet/VT\u HRESULT) 找到默认成员:IListBox.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:IListBox.\u默认值(PropertyLet/VT\u HRESULT) 找到默认成员:IListBox.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:IListBox.\u默认值(PropertyLet/VT\u HRESULT) 找到默认成员:IDropDown.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:IDropDown.\u默认值(PropertyLet/VT\u HRESULT) 找到默认成员:IDropDowns.\u默认值(PropertyGet/VT\u HRESULT) 找到默认成员:IDropDowns.\u默认(PropertyLet/VT
else if (memberDescriptor.memid == 0)
{
    attributes.AddDefaultMemberAttribute(memberName);
    Debug.WriteLine("Default member found: {0}.{1} ({2} / {3})", moduleDeclaration.IdentifierName, memberName, memberDeclarationType, (VarEnum)memberDescriptor.elemdescFunc.tdesc.vt);
}