Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How can I access the properties of this object?

How can I access the properties of this object?

Scheduled Pinned Locked Moved C#
questiontutorial
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    turbosupramk3
    wrote on last edited by
    #1

    When debugging, I can see the properties of this tasklist object, but I can't figure out how to access the properties programatically. As you can see in the screen capture below, the properties enumerate while debugging, how can I access those values? Thanks! http://img833.imageshack.us/img833/7081/g4rm.jpg[^]

    V OriginalGriffO T A Richard DeemingR 5 Replies Last reply
    0
    • T turbosupramk3

      When debugging, I can see the properties of this tasklist object, but I can't figure out how to access the properties programatically. As you can see in the screen capture below, the properties enumerate while debugging, how can I access those values? Thanks! http://img833.imageshack.us/img833/7081/g4rm.jpg[^]

      V Offline
      V Offline
      Vinh Nguyen
      wrote on last edited by
      #2

      For public properties, you can access them 'programmatically' as usual. For non-public ones, try to use reflection. There are a lot of articles on the internet telling about it.

      1 Reply Last reply
      0
      • T turbosupramk3

        When debugging, I can see the properties of this tasklist object, but I can't figure out how to access the properties programatically. As you can see in the screen capture below, the properties enumerate while debugging, how can I access those values? Thanks! http://img833.imageshack.us/img833/7081/g4rm.jpg[^]

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        If you can't access them directly in the usual way, then they are not intended to be available and the access modifier has been set to private or protected to prevent you getting at them. While it would be possible (if rather slow) to access them via Reflection it is generally a very poor idea. They are not normally available for a reason, and because they aren't designed to be available there is no guarantee that they will work in the same way in the next version, or even exist at all. Relying on items you have not been given normal access to is a very poor idea, and will often come back to bite you when you least expect it. I would not recommend it, not at all.

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        1 Reply Last reply
        0
        • T turbosupramk3

          When debugging, I can see the properties of this tasklist object, but I can't figure out how to access the properties programatically. As you can see in the screen capture below, the properties enumerate while debugging, how can I access those values? Thanks! http://img833.imageshack.us/img833/7081/g4rm.jpg[^]

          T Offline
          T Offline
          turbosupramk3
          wrote on last edited by
          #4

          It is a public class that I got from code project actually. A New Task Scheduler Class Library for .NET[^] There is probably an easy way to modify this class code, I'm just not able to do it due to experience. Do you still feel the properties are hidden, or since this is a public class, I could expose them?

          1 Reply Last reply
          0
          • T turbosupramk3

            When debugging, I can see the properties of this tasklist object, but I can't figure out how to access the properties programatically. As you can see in the screen capture below, the properties enumerate while debugging, how can I access those values? Thanks! http://img833.imageshack.us/img833/7081/g4rm.jpg[^]

            A Offline
            A Offline
            Abhinav S
            wrote on last edited by
            #5

            IF the properties are public, you can access them directly (or cast them into appropriate value).

            Apps - Color Analyzer | Arctic | XKCD | Sound Meter | Speed Dial

            T 1 Reply Last reply
            0
            • A Abhinav S

              IF the properties are public, you can access them directly (or cast them into appropriate value).

              Apps - Color Analyzer | Arctic | XKCD | Sound Meter | Speed Dial

              T Offline
              T Offline
              turbosupramk3
              wrote on last edited by
              #6

              Would you consider those public, if they are exposed by the IDE? I'm able to cast this way IEnumerable<Object> stList = serverTaskList.Cast<Object>(); but still not able to get intellisense to recognize the property names

              1 Reply Last reply
              0
              • T turbosupramk3

                When debugging, I can see the properties of this tasklist object, but I can't figure out how to access the properties programatically. As you can see in the screen capture below, the properties enumerate while debugging, how can I access those values? Thanks! http://img833.imageshack.us/img833/7081/g4rm.jpg[^]

                Richard DeemingR Offline
                Richard DeemingR Offline
                Richard Deeming
                wrote on last edited by
                #7

                The TaskList class only implements IEnumerable, not IEnumerable<T>. As a result, the implicit type of your task variable is Object, and you would need to cast it as a Task before you could access the properties. The simplest solution is to specify the type name in your foreach loop:

                foreach (Task task in serverTaskList)
                {
                ...
                }


                "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                T 1 Reply Last reply
                0
                • Richard DeemingR Richard Deeming

                  The TaskList class only implements IEnumerable, not IEnumerable<T>. As a result, the implicit type of your task variable is Object, and you would need to cast it as a Task before you could access the properties. The simplest solution is to specify the type name in your foreach loop:

                  foreach (Task task in serverTaskList)
                  {
                  ...
                  }


                  "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                  T Offline
                  T Offline
                  turbosupramk3
                  wrote on last edited by
                  #8

                  Thanks Richard. You're the man, you nailed it with that simple statement ... ugh I feel so foolish! How did you know it only implemented IEnumerable and not IEnumerable ?

                  Richard DeemingR 1 Reply Last reply
                  0
                  • T turbosupramk3

                    Thanks Richard. You're the man, you nailed it with that simple statement ... ugh I feel so foolish! How did you know it only implemented IEnumerable and not IEnumerable ?

                    Richard DeemingR Offline
                    Richard DeemingR Offline
                    Richard Deeming
                    wrote on last edited by
                    #9

                    turbosupramk3 wrote:

                    How did you know it only implemented IEnumerable and not IEnumerable<T>?

                    I looked at the code[^] in the article[^] you linked to.


                    "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                    "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups