[RESOLVED] Reflection get default property value set at design time
I have this code...
Code:
Dim instances = From t In Assembly.GetExecutingAssembly().GetTypes()
Where t.GetInterfaces().Contains(GetType(Shape2D))
Select New With {
.className = t.Name,
.index = t.GetProperty("sortIndex"),
.argumentsString = t.GetProperties().Select(Function(p) p.Name).Except(New String() {"sortIndex"}).ToArray}
The .index property isn't returning the integer values i'm trying for. The goal is to sort instances based on the integers 0-9 which are stored in the sortIndex property of the concrete classes.
Can anyone help? I've tried more or less every possible angle.
Re: Reflection get default property value set at design time
Nevermind... I changed it to a constant. Now have the class names in the right order.
Re: [RESOLVED] Reflection get default property value set at design time
The GetTypes method (documentation) will only return the types defined in the assembly. Take a look at this sandbox example: https://dotnetfiddle.net/oFdnM8
This doesn't sound like what you're wanting to do. It sounds like you want any instance of the Shape2D class, sorted by the sortIndex. So in my example, any of the references defined in shapes. Is that correct or am I misunderstanding you?
Edit - Nevermind, it looks like you solved it lol
Re: [RESOLVED] Reflection get default property value set at design time
If you wanted to sort on property values then, at some point, you'd have to be calling GetValue on a PropertyInfo object. If it was an instance property then you'd have to have an instance to get that value from.