Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highlight dynamic calls in code

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?

like image 683
Kjara Avatar asked Mar 08 '26 13:03

Kjara


1 Answers

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.

like image 86
JPhil Avatar answered Mar 10 '26 02:03

JPhil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!