Inheritance of the DoNotObfuscate Attribute
Andy_L
Posts: 4 New member
I have some code similar to this:
<div>[SmartAssembly.Attributes.DoNotObfuscate]</div><div>public class BaseClass {}</div><div><br></div><div>public class DerivedClass : BaseClass {}</div>
When I look at the implementation of the DoNotObfuscateAttribute, I can see its AttributeUsage attribute doesn't specify a value for the Inherited parameter, so uses the default value of true, and the attribute should be inherited by derived classes.
At runtime, if I look at
typeof(DerivedClass).GetCustomAttributes()then sure enough, DerivedClass has the SmartAssembly.Attributes.DoNotObfuscateAttribute attribute.
Yet when I run obfuscation, DerivedClass gets obfuscated while BaseClass doesn't. Why does DerivedClass get obfuscated when it should inherit the DoNotObfuscateAttribute?
Tagged:
Best Answer
-
Russell D Posts: 1,324 Diamond 5So this is certainly true. When applying
[DoNotObfuscate]
on a base class, it doesn't affect derived classes.
I'm not sure that it's a bug though. I can imagine people wanting to obfuscate all derived classes, but not the base class (as is right now). Or obfuscate the base class, but not derived classes. So its because of this that we've added an enhancement request to our backlog, one possible alternative would be to exclude classes one-by-one in GUI, but it needs some thought/testing.
Another alternative would be to do some find-and-replace magic. For example, if I wanted to not obfuscate all classes deriving formBaseClass
, I could replace\r?\n.*?class[^\r\n]+:[^\r\n]+\bBaseClass
to[DoNotObfuscate]$0
.
It's a somewhat dirty regular expression. but it might work; especially with more thought.
Sorry for the delay in response; it took a little thought.Have you visited our Help Centre?
Answers