How to set field value in VB.NET module using Reflection?

How to set field value in VB.NET module using Reflection?

+5
source share
2 answers

@ user287107 was close, but this is what works:

    Dim ass As Assembly = Assembly.Load("AssemblyNameWhereModuleResides")
    Dim moduleType as Type = ass.GetType("MyNameSpaceIfApplicable.MyModuleName")
    moduleType.GetField("field").SetValue(Nothing, newValue)
+3
source

I think it should be very similar to C # code

objectwithfield.GetType().GetField("field").SetValue(objectwithfield, newValue)
+5
source

All Articles