locked
how to use class fields as an Enum, so i can pass its name instead of its value RRS feed

  • Question

  • User105898038 posted

    i have a class like this:

    public class Customer

            public Name as string

            public Age as integer

    end class

    i want to use the class fields as an Enum, so i can pass its name like so

          SearchTasks.add _
              (
                FieldToSearch:= Customer.Name,
                SearchType:= SearchTypes.DirectMatch
                SearchFor:= "Lisa"
               )

    instead of so:

    SearchTasks.add _
              (
                FieldToSearch:= "Name",
                SearchType:= SearchTypes.DirectMatch
                SearchFor:= "Lisa"
               )

    The directcast feature can do it too. it can pass noninstanced objects as the second parameter.

    The actual search is send as XML and executed on another machine. the customer fields are available in the asp.net site but the object instance with its actual values is on another machine. which is why i want to pass the field name. however i prefer providing it TYPED. instead of UNTYPED as a string.

    Saturday, June 23, 2018 1:40 AM

All replies

  • User36583972 posted


    Hi fazioli,

    how to use class fields as an Enum, so i can pass its name instead of its value

    i have a class like this:

    public class Customer

            public Name as string

            public Age as integer

    end class

    i want to use the class fields as an Enum, so i can pass its name like so

          SearchTasks.add _
              (
                FieldToSearch:= Customer.Name,
                SearchType:= SearchTypes.DirectMatch
                SearchFor:= "Lisa"
               )

    instead of so:

    SearchTasks.add _
              (
                FieldToSearch:= "Name",
                SearchType:= SearchTypes.DirectMatch
                SearchFor:= "Lisa"
               )

    As far as I know, you can't do it like this.

    When you have a number of constants that are logically related to each other, then you can group together these constants in an enumeration.

    Enums are strongly typed constants which makes the code more readable and less prone to errors. It is useful when you have a set of values that are functionally significant and unchanged.

    You can define an Enum in your class.

    Enum Class:
    https://msdn.microsoft.com/en-us/library/system.enum(v=vs.110).aspx


    Best Regards,

    Yong Lu

    Monday, June 25, 2018 5:56 AM