Code: Select all
namespace Foobar
{
internal class Foo()
{
internal static readonly Me = new Foo();
}
}
< /code>
Ich kann den Wert des Feldes einfach mit folgendem erhalten: < /p>
Assembly a = Assembly.Load("AssemblyWithFoo");
Type t = a.GetType("Foobar.Foo");
FieldInfo fi = t.GetRuntimeFields().First(f => f is { Name: "Me", IsStatic: true });
var bar = fi.GetValue(null);
Code: Select all
fi.SetValue(null, new Foo());
Code: Select all
var foo = GetFooFromAssembly();
var bar = fi.GetValue(null);
unsafe
{
object* ptr = &bar;
*ptr = foo;
}