I am currently working on a Blazor project in .NET8 and are having some issues trying to access a public property at runtime using reflection.
Issue:I have an array of objects[] at runtime which I cant access the properties value i need once I have drilled down the array to the type using reflection.
I have tried this so far which I am able to see the properties and the types values but cant access them.
//Have to use reflection as we don't now the type at compile time var type = obj[i].GetType(); //I can see all of the public properties in this array object[] PropertyInfo = type.GetProperties(); //but when I try and access one of the properties, I get null var property = type.GetProperty("Name"); //The name should be accessable here?? var name = property.GetValue(obj[i]);Public Model:
public class MyClass{ public int Address { get; set; } public string Name { get; set; }}`Any help or guidance would be very welcomed as I thought it was due to the property not being public but it actually is.
Thanks in advance for any pointers on this one