Referencing Property as variable?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brett Romero

    #1

    Referencing Property as variable?

    If I have a collection such as:
    Person.addressc ollection[0].Address1

    and have a variable
    myAddressField = "Address1"

    how can I do something such as
    Person.addressc ollection[0].myAddressField

    to reach the field "Address1"?

    Thanks,
    Brett

  • Peter Rilling

    #2
    Re: Referencing Property as variable?

    You cannot the way you have it, but you can use reflection to dynamically
    investigate and invoke objects. Take a look at the Type.GetPropert y( ... ).
    You will most likly have to wrap whatever you are doing in some method as
    there is not built-in syntax for this.


    "Brett Romero" <account@cygen. com> wrote in message
    news:1137789783 .187468.322720@ g14g2000cwa.goo glegroups.com.. .[color=blue]
    > If I have a collection such as:
    > Person.addressc ollection[0].Address1
    >
    > and have a variable
    > myAddressField = "Address1"
    >
    > how can I do something such as
    > Person.addressc ollection[0].myAddressField
    >
    > to reach the field "Address1"?
    >
    > Thanks,
    > Brett
    >[/color]


    Comment

    • chris martin

      #3
      Re: Referencing Property as variable?

      > If I have a collection such as:[color=blue]
      > Person.addressc ollection[0].Address1
      > and have a variable
      > myAddressField = "Address1"
      > how can I do something such as
      > Person.addressc ollection[0].myAddressField
      > to reach the field "Address1"?
      >
      > Thanks,
      > Brett[/color]

      public class Address
      {
      private string myAddressField;

      ...

      public string Address1
      {
      get{ return myAddressField; }
      }
      }


      Comment

      • Brett Romero

        #4
        Re: Referencing Property as variable?

        Peter, I could try something with Type.GetPropery but that means
        needType.DLL will need to include all the DLLs of every type it needs.

        I have an EXE project that file references this needType.DLL and A.DLL,
        B.DLL, C.DLL. Those last three DLLs contain the types I'd need to use
        with GetProperty in needType.DLL. If I were to reference the three
        DLLs in needType.DLL, I'd have a lot of reduncy and complexity.
        There'd probably be circular references.

        Thanks,
        Brett

        Comment

        Working...