G
gz
Good morning everyone,
I am writing a module that needs to access fields in classes
efficiently. The trouble is that the module does not know the classes
beforehand, although the user of the module does know the classes in
compile time without resorting to reflection.
For example, I have a class A and I also have class Module. It knows
nothing about class A, but needs to access field f1. In C or C++, I
can tell class Module the offset and type of f1, and then it knows how
to access f1.
class A
{
public: int f1;
};
class Module
{
void Register(const char * class_type, const char *field_type, int
offset);
}
Module m;
m.Register("A", "int", (int)((char*)(&((A*)(0))->f1)));
How do I do this in C#?
Thanks,
GZ
I am writing a module that needs to access fields in classes
efficiently. The trouble is that the module does not know the classes
beforehand, although the user of the module does know the classes in
compile time without resorting to reflection.
For example, I have a class A and I also have class Module. It knows
nothing about class A, but needs to access field f1. In C or C++, I
can tell class Module the offset and type of f1, and then it knows how
to access f1.
class A
{
public: int f1;
};
class Module
{
void Register(const char * class_type, const char *field_type, int
offset);
}
Module m;
m.Register("A", "int", (int)((char*)(&((A*)(0))->f1)));
How do I do this in C#?
Thanks,
GZ