Intellisense at runtime

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

    #1

    Intellisense at runtime

    How can you see an object's members at run-time programmaticall y. I want to
    write code that looks like :
    MyObject myObject;
    foreach ( object member in myObject)
    {
    DoSomeThingWith (member);
    }

    Thanks,
    Hananiel


  • Daniel O'Connell

    #2
    Re: Intellisense at runtime

    Could you be a little clearer about what you want exactly?
    "Hananiel" <Hananiel@junkm ail.com> wrote in message
    news:%23TAQpdav DHA.3532@TK2MSF TNGP11.phx.gbl. ..[color=blue]
    > How can you see an object's members at run-time programmaticall y. I want[/color]
    to[color=blue]
    > write code that looks like :
    > MyObject myObject;
    > foreach ( object member in myObject)
    > {
    > DoSomeThingWith (member);
    > }
    >
    > Thanks,
    > Hananiel
    >
    >[/color]


    Comment

    • Charlie Williams

      #3
      Intellisense at runtime

      You would use reflection to do this.

      Something like:

      using System.Reflecti on;

      Type t = typeof(MyObject );
      MemberInfo[] members = t.GetMembers();
      foreach(MemberI nfo mi in members){
      //Do what you want here
      }

      GetMembers gets all the members of the given type. There
      is also GetProperties, GetMethods, GetInterfaces, etc.

      Also, you can pick out a member by name instead of
      retrieving an array: t.GetMethod("Co okSalsburySteak ");

      HTH,
      Charlie
      [color=blue]
      >-----Original Message-----
      >How can you see an object's members at run-time[/color]
      programmaticall y. I want to[color=blue]
      >write code that looks like :
      >MyObject myObject;
      >foreach ( object member in myObject)
      >{
      > DoSomeThingWith (member);
      >}
      >
      >Thanks,
      >Hananiel
      >
      >
      >.
      >[/color]

      Comment

      • Hananiel

        #4
        Re: Intellisense at runtime

        Thank you. Just what i needed.
        -Hananiel
        "Charlie Williams" <cwilliams1145@ hotmail.spamfre e.com> wrote in message
        news:f4cf01c3bd b7$849862f0$a60 1280a@phx.gbl.. .[color=blue]
        > You would use reflection to do this.
        >
        > Something like:
        >
        > using System.Reflecti on;
        >
        > Type t = typeof(MyObject );
        > MemberInfo[] members = t.GetMembers();
        > foreach(MemberI nfo mi in members){
        > //Do what you want here
        > }
        >
        > GetMembers gets all the members of the given type. There
        > is also GetProperties, GetMethods, GetInterfaces, etc.
        >
        > Also, you can pick out a member by name instead of
        > retrieving an array: t.GetMethod("Co okSalsburySteak ");
        >
        > HTH,
        > Charlie
        >[color=green]
        > >-----Original Message-----
        > >How can you see an object's members at run-time[/color]
        > programmaticall y. I want to[color=green]
        > >write code that looks like :
        > >MyObject myObject;
        > >foreach ( object member in myObject)
        > >{
        > > DoSomeThingWith (member);
        > >}
        > >
        > >Thanks,
        > >Hananiel
        > >
        > >
        > >.
        > >[/color][/color]


        Comment

        Working...