Created
April 8, 2012 22:02
-
-
Save einarwh/2340053 to your computer and use it in GitHub Desktop.
Looking for properties to tamper with.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public bool MaybeTamperWith() | |
| { | |
| return _typeDef.IsClass | |
| && HasPropertiesToTamperWith() | |
| && ReallyTamperWith(); | |
| } | |
| private bool HasPropertiesToTamperWith() | |
| { | |
| FindPropertiesToTamperWith(); | |
| return _map.Count > 0; | |
| } | |
| private void FindPropertiesToTamperWith() | |
| { | |
| var isViewableType = IsViewable(_typeDef); | |
| foreach (var prop in _typeDef.Properties | |
| .Where(p => IsViewable(p) || (isViewableType && !IsOpaque(p)))) | |
| { | |
| HandlePropertyToNotify(prop); | |
| } | |
| } | |
| private static bool IsViewable(ICustomAttributeProvider item) | |
| { | |
| return HasAttribute(item, ViewableAttributeName); | |
| } | |
| private static bool IsOpaque(ICustomAttributeProvider item) | |
| { | |
| return HasAttribute(item, OpaqueAttributeName); | |
| } | |
| private static bool HasAttribute(ICustomAttributeProvider item, | |
| string attributeName) | |
| { | |
| return item.CustomAttributes.Any( | |
| a => a.AttributeType.Name == attributeName); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment