c# - Func-eval on polymorphic classes -


i'm making managed .net debugger using mdbg sample.

mdbg sample operates on top level class of given instance, not searching deep inside class hierarchy. able go through hierarchy , available methods. problem occurs in such case:

    public abstract class base{         public base() {someprop = "base"}         public string someprop {get;set;}     }      public class : base{         public base() {someprop = "a"}         public new string someprop {get;set;}     }      public static void main(){         var = new a();         var castedtobase = (base)a;         //castedtobase.someprop -- expect result "base" when debugging     } 

the problem when i'm getting castedtobase icordebugvalue , query it's icordebugvalue2::getexacttype class instead of base class. @ point cannot distinguish more method get_someprop invoke. expect icordebugvalue2::getexacttype take in consideration performed casts , not return underlying type.

how can understand method should invoke?

some code of i'm doing listed below. mdbgvalue represents castedtobase object. sztypedef returns "a" instead of expected "base"

    imetadataimport importer;     var classtoken = mdbgvalue.corvalue.exacttype.class.token;      int size;     int ptkextends;     typeattributes pdwtypedefflags;     importer.gettypedefprops(classtoken,         null,         0,         out size,         out pdwtypedefflags,         out ptkextends         );     stringbuilder sztypedef = new stringbuilder(size);     importer.gettypedefprops(classtoken,         sztypedef,         sztypedef.capacity,         out size,         out pdwtypedefflags,         out ptkextends         ); 

casting object it's base class doesn't change type of object, how perceived. suggest need pass "perceived" type around along value, , use instead of actual type purpose of finding correct method.

the "perceived" type statically determined type based on got value from.

  • if got value parameter using icordebugilframe::getargument(), extract corresponding argument type method signature.
    • if first argument , method signature has hasthis flag not explicitthis flag type value instead.
  • if got value local using icordebugilframe::getlocalvariable() extract type methods locals signature (the metadata token of locals signature needs extracted method header.)
  • if got value running method icordebugeval (eg. property getter), should use return type of method called (also extracted method signature.)
  • if got value field, extract type field signature.
  • if cast value, use whatever type casting to.

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -