c# - Check if property type overloads == operator with Mono.Cecil -


i using mono.cecil write program injects il code property setters. problem need use equality operator on property within il. example:

public class someclass {     private int _property1;      public int property1      {         { return _property1; }         set { _property1 = value; }     }      private string _property2;      public string property2     {         { return _property2; }         set { _property2 = value; }     } } 

and il code need inject in setters like:

if (value != _property1) {    //do stuff } 

same goes property2. problem property2 of type string overloads == operator , in il instead of ceq code need call op_equality. question is: there way check if == operator overridden on property type using mono.cecil?

well, it's easy. i've created class

 public class foo     {         public static bool operator ==(foo a, foo b)         {             if (system.object.referenceequals(a, b))             {                 return true;             }             if (((object)a == null) || ((object)b == null))             {                 return false;             }             return == b;         }          public static bool operator !=(foo a, foo b)         {             return !(a == b);         }     } 

compiled , looked @ in mono.cecil

 assemblydefinition assembly = assemblydefinition.readassembly(path);             foreach (var item in assembly.modules)             {                 foreach (var type in item.types)                 {                     foreach (var method in type.methods)                     {                         if (method.isstatic && method.isspecialname && method.ispublic && method.name.contains("op_equality"))                         {                             //that type overides == operator                         }                     }                 }             } 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -