StevenzNPaul
StevenzNPaul

Reputation: 188

Obfuscation+Reflection

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

Upvotes: 2

Views: 1954

Answers (3)

R. Martinho Fernandes
R. Martinho Fernandes

Reputation: 234504

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.

Upvotes: 7

harriyott
harriyott

Reputation: 10645

Depending on the obfuscator, a mapping file might be generated. I've used this to lookup which properties have been mapped to which obfuscated ones. The problem is shipping the mapping file with the assembly kind of defeats the object of obfuscating.

Upvotes: 1

PHeiberg
PHeiberg

Reputation: 29811

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

Upvotes: 3

Related Questions