G
Guest
How can I get an object address as IntPtr ?
Somehow even in unsafe it's not working with objetcs...
I'am trying to compare two objects that are not the same but could be from
some point.
Example :
Let say we have two classes one derived from another
public class A
{
protected h=0;
public virtual func()
{
h=0;
}
}
public class B:A
{
public override func()
{
h=1;
}
}
I created two instance of these classes obj1 and obj2,
obj1=Activator.CreateInstance(t1); //Type t1; class A
obj2=Activator.CreateInstance(t2); //Type t2; class B
After invoking we can see in the debugger somthing like this...
obj1.A.h=0
obj2.B.A.h=1;
I dont whant to compare fieald by GetFieald() and comparing them one by one,
My idea was to try the Marshal.ReadIntPtr(IntPtr,offset) so I can read obj2
after some offset, So I needed my variable Address. (somehow even in unsafe
we cant do object *p=obj1; on objetcs...)
I tried Marshel.ReadByte and it's not working cause my object type could be
anything...
Anyone have some idea ???
Thanks
Somehow even in unsafe it's not working with objetcs...
I'am trying to compare two objects that are not the same but could be from
some point.
Example :
Let say we have two classes one derived from another
public class A
{
protected h=0;
public virtual func()
{
h=0;
}
}
public class B:A
{
public override func()
{
h=1;
}
}
I created two instance of these classes obj1 and obj2,
obj1=Activator.CreateInstance(t1); //Type t1; class A
obj2=Activator.CreateInstance(t2); //Type t2; class B
After invoking we can see in the debugger somthing like this...
obj1.A.h=0
obj2.B.A.h=1;
I dont whant to compare fieald by GetFieald() and comparing them one by one,
My idea was to try the Marshal.ReadIntPtr(IntPtr,offset) so I can read obj2
after some offset, So I needed my variable Address. (somehow even in unsafe
we cant do object *p=obj1; on objetcs...)
I tried Marshel.ReadByte and it's not working cause my object type could be
anything...
Anyone have some idea ???
Thanks