问题描述
编辑-自v6.11.11起已修复!
我试图使用Util.ondemand
依赖于flag属性,以两种不同的方式转储结果集,结果发现结果集无法正常工作。我可以用这个小例子来重现它:
void Main()
{
var i = new test() { Prop1 = "One" };
i.Dump(exclude:"Prop1");
Util.ondemand("On Demand Exclude Prop1",()=>i).Dump(exclude:"Prop1");
}
public class Test
{
public string Prop1 { get; set; }
}
输出:
Test
UserQuery+Test
On Demand Exclude Prop1
Test
UserQuery+Test
Test
UserQuery+Test
Prop1 One
预期结果:
Test
UserQuery+Test
Test
UserQuery+Test
我相当确定这与Util.ondemand
没有直接关系,但更可能是DumpContainer
的问题,因为这也会产生相同的排除结果:
new DumpContainer(i).Dump(exclude:"Prop1");
我没有检查所有参数,但是我已经确认collapseto
在以这种方式调用时也有异常行为,可能还有其他情况。
解决方法
我认为不可能。我的理解是Dump(exclude:"")
从调用该方法的对象中排除属性。在您的情况下,您可以在没有LINQPad.DumpContainer
属性的Prop1
对象上运行它。我无法从Prop1
中排除DumpContainer.Content
。
清洁和推荐的解决方案是覆盖ToDump
方法:
public class Test
{
public string Prop1 { get; set; }
object ToDump()
{
IDictionary<string,object> custom = new System.Dynamic.ExpandoObject();
var props = GetType().GetProperties (BindingFlags.Public | BindingFlags.Instance)
.Where (p => p.Name != "Prop1");
foreach (var prop in props)
custom[prop.Name] = prop.GetValue (this);
return custom;
}
}
否则,如果您不想编写其他方法,将首先将其转换为ExpandoObject
,这将导致一个难看的衬里:
Util.OnDemand("On Demand Exclude Prop1",() => (Util.ToExpando(i,exclude:"Prop1"))).Dump()
,
这不是理想的行为:unzip -p ./build/app/outputs/apk/debug/app-debug.apk lib/arm64-v8a/libvision_utils.so > ./build/temp-libvision_utils.so
和bloaty ./build/temp-libvision_utils.so --debug-file=./build/vision_utils/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libvision_utils.so -d compileunits
之类的选项应该对转储容器的内容起作用,而不是对容器本身起作用。我将修复下一个LINQPad版本。同时,建议的解决方法看起来不错。