突出显示代码中的动态调用(Highlight dynamic calls in code)

编程入门 行业动态 更新时间:2024-10-26 22:18:31
突出显示代码中的动态调用(Highlight dynamic calls in code)

我正在使用Visual Studio 2015在.NET中编写程序。我遇到的问题是,当代码中的任何地方都有动态调用时,我们的混淆工具不起作用,所以我需要摆脱它们。

是否可以使Visual Studio突出显示使用dynamic的代码? 也许发出警告或者这样的?

编辑:

我的代码中没有“ dynamic这个词,但仍有动态调用。 它们来自我使用的第三方API。 API的示例摘录:

public class ThirdPartyClass { public dynamic Foo { get { ... // returns an instance of class FooClass } } ... }

类FooClass有一个方法Bar() 。

现在让我们说在我的代码中的某个时刻我有一个名为tpc的ThirdPartyClass实例。 以下代码行

var barVar = tpc.Foo.Bar();

进行动态调用,因为tpc.Foo是动态的。 要删除动态调用,我会写

var barVar = ((FooClass)tpc.Foo).Bar();

这是我需要做的,以使混淆工具再次工作。 但是,如何在不通过代码手动的情况下找到动态调用?

I am writing a program in .NET with Visual Studio 2015. I have the problem that our obfuscating tool does not work when there are dynamic calls anywhere in the code, so I need to get rid of them.

Is it possible to make Visual Studio highlight the code that uses dynamic? Maybe give out a warning or such?

EDIT:

I do not have the word dynamic anywhere in my code, but there are still dynamic calls. They come from the third party API which I use. Example excerpt from the API:

public class ThirdPartyClass { public dynamic Foo { get { ... // returns an instance of class FooClass } } ... }

The class FooClass has a method Bar().

Now let's say at some point in my code I have an instance of ThirdPartyClass called tpc. The following line of code

var barVar = tpc.Foo.Bar();

does a dynamic call, because tpc.Foo is dynamic. To remove the dynamic call I write instead

var barVar = ((FooClass)tpc.Foo).Bar();

This is what I need to do in order to make the obfuscation tool work again. But how do I find the dynamic calls without going through the code manually?

最满意答案

在代码中查找所有动态用法的方法是临时删除Microsoft.CSharp依赖项。 这将导致动态使用的编译器错误。 也许在其他部分,所以你应该在删除动态调用后重新包含它。

A way to find all dynamic usages in code is to temporary remove the Microsoft.CSharp dependeny. This will lead to compiler error on dynamic usage. Maybee also on other parts so you should reinclude it after removing the dynamic calls.

更多推荐

本文发布于:2023-08-02 08:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1372256.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代码   动态   Highlight   code   calls

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!