Results 1 to 4 of 4

Thread: [RESOLVED] Reflection get default property value set at design time

  1. #1

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,976

    Resolved [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.

  2. #2

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,976

    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.

  3. #3
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    10,268

    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

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    106,912

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width