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
    26,424

    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
    26,424

    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
    Posts
    12,397

    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
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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