.NET Framework Reflection Creating Object and setting properties using reflection

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

Lets say we have a class Classy that has property Propertua

public class Classy
{
    public string Propertua {get; set;}
}

to set Propertua using reflection:

var typeOfClassy = typeof (Classy);
var classy = new Classy();
var prop = typeOfClassy.GetProperty("Propertua");
prop.SetValue(classy, "Value");


Got any .NET Framework Question?