Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set a field value in a VB.NET module using Reflection?

Tags:

.net

vb.net

How do I set a field value in a VB.NET module using Reflection?

like image 576
Denis Avatar asked May 21 '12 21:05

Denis


2 Answers

i think it should be very similar to the C# code

objectwithfield.GetType().GetField("field").SetValue(objectwithfield, newValue)
like image 137
user287107 Avatar answered Oct 07 '22 01:10

user287107


@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)
like image 34
Denis Avatar answered Oct 07 '22 00:10

Denis