How can I access the properties of this object?
-
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[^]
-
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[^]
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.
-
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[^]
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.
-
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[^]
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?
-
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[^]
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
-
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
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
-
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[^]
The
TaskList
class only implementsIEnumerable
, notIEnumerable<T>
. As a result, the implicit type of yourtask
variable isObject
, and you would need to cast it as aTask
before you could access the properties. The simplest solution is to specify the type name in yourforeach
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
-
The
TaskList
class only implementsIEnumerable
, notIEnumerable<T>
. As a result, the implicit type of yourtask
variable isObject
, and you would need to cast it as aTask
before you could access the properties. The simplest solution is to specify the type name in yourforeach
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
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 ?
-
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 ?
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