IntelliTrace引用参数

本文关键字:参数 引用 IntelliTrace | 更新日期: 2023-09-27 18:03:44

使用IntelliTrace,我无法看到通过引用传递到方法的字符串的输出和在同一事件(或根本)中方法的结果。

方法示例:

public bool ByReferenceTestMethod(System.ArgumentNullException exception, ref string referenceArgument)
{
    referenceArgument = string.Format("referenceArgument{0}", exception.Message);
    return true;
}

collectionplan.xml示例不使用引用参数参考:

<DiagnosticEventSpecification>
    <CategoryId>stackoverflow.test.application</CategoryId>
    <SettingsName _locID="settingsName.Test.Application.Reference">VerifyIDFromBackEnd called</SettingsName>
    <SettingsDescription _locID="settingsDescription.Test.Application.Reference">VerifyIDFromBackEnd was called</SettingsDescription>
    <Bindings>
        <Binding onReturn="false">
            <ModuleSpecificationId>stackoverflow.test.application</ModuleSpecificationId>
            <MethodName>ByReferenceTestMethod</MethodName>
            <MethodId>Test.Application.TestClass.ByReferenceTestMethod(System.ArgumentException,System.String&amp;):System.Boolean</MethodId>
            <ShortDescription _locID="shortDescription.Test.Application.Reference.called">Method 'ByReferenceTestMethod' called</ShortDescription>
            <LongDescription _locID="longDescription.Test.Application.Reference.called">ByReferenceTestMethod called with ArgumentException parameter name "{0}" and message "{1}"</LongDescription>
            <TypeName>Test.Application.TestClass</TypeName>
            <DataQueries>
                <DataQuery index="1" maxSize="2048" type="String" name="Exception parameter" _locID="dataquery.Test.Application.Reference.exception.Paramname" query="m_paramName" />
                <DataQuery index="1" maxSize="2048" type="String" name="Exception message" _locID="dataquery.Test.Application.Reference.exc5eption.Message" _locAttrData="name" query="_message" />
        </DataQueries>
        </Binding>
        <Binding onReturn="true">
            <ModuleSpecificationId>stackoverflow.test.application</ModuleSpecificationId>
            <MethodName>ByReferenceTestMethod</MethodName>
            <MethodId>Test.Application.TestClass.ByReferenceTestMethod(System.Exception,System.String&amp;):System.Boolean</MethodId>
            <ShortDescription _locID="shortDescription.Test.Application.Reference.result">Method 'ByReferenceTestMethod' completed</ShortDescription>
            <LongDescription _locID="longDescription.Test.Application.Reference.result">ByReferenceTestMethod returned result "{0}" with an unknown referenceArgument</LongDescription>
            <TypeName>Test.Application.TestClass</TypeName>
            <DataQueries>
                <DataQuery index="-1" maxSize="0" type="Boolean" name="Reference Result" _locID="dataquery.Test.Application.Reference.result" _locAttrData="name" query="" />
            </DataQueries>
        </Binding>
    </Bindings>
</DiagnosticEventSpecification>

collectionplan.xml示例不能使用引用参数reference:

<LongDescription _locID="longDescription.Test.Application.Reference.result">ByReferenceTestMethod returned result "{0}" with referenceArgument "{1}"</LongDescription>
<TypeName>Test.Application.TestClass</TypeName>
<DataQueries>
    <DataQuery index="-1" maxSize="0" type="Boolean" name="Reference Result" _locID="dataquery.Test.Application.Reference.result" _locAttrData="name" query="" />
    <DataQuery index="2" maxSize="4096" type="String" name="referenceArgument" _locID="dataquery.Test.Application.Reference.Reference.Value" _locAttrData="name" query="" />
</DataQueries>

这显示了没有解析标记的LongDescription,如果我改变顺序,消息本身根本不会出现。

据我所知,ref应该在onResult="true"时出现,因为该事件直到方法返回后才进行评估。如果我在onResult="false"数据查询中使用相同的参数,则在方法可能设置值之前对其进行评估。

我做错了什么?

IntelliTrace引用参数

据我所知,你不能为所欲为。我过去也试过几次同样的事情,但没有成功。然而,问题不在于ref参数。它也不能与"正常"参数一起工作。

如果您使用onReturn="true",那么您只能引用从方法返回的值,即index="-1"。在这种情况下,不能读取参数的值。这是由于IntelliTrace在引擎盖下的工作方式,我不知道解决办法。

可编程数据查询也没有帮助。PDQ有两个实现方法:

  • object[] EntryQuery(object thisArg, object[] args)
  • object[] ExitQuery(object returnValue)

调用第一个来分析输入参数(onReturn="false"),调用第二个来分析返回值(onReturn="false")。同样,在ExitQuery中,您只能访问返回值。