Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obfuscation+Reflection

Tags:

c#

How can I get a PropertyInfo by name using GetType().GetProperty("MypropName") of a type which is obfuscated.

like image 228
StevenzNPaul Avatar asked Mar 27 '26 08:03

StevenzNPaul


2 Answers

You need to know what the obfuscated name of the property ended up. That is very fragile as it may change from build to build. If you can tell which property is by other means (its type, custom attributes) it would be better.

The obfuscated name will mostly likely be a few non-printable characters or probably just A. Dotfuscator renames something like 80% of the code to A.

like image 160
R. Martinho Fernandes Avatar answered Mar 29 '26 20:03

R. Martinho Fernandes


An alternative would be to exclude the property from Obfuscation using the ObfuscationAttribute Class

like image 40
PHeiberg Avatar answered Mar 29 '26 20:03

PHeiberg