Click here to Skip to main content
15,889,442 members
Home / Discussions / C#
   

C#

 
GeneralRe: Render loop for other process Pin
Jitse28-Feb-08 3:47
Jitse28-Feb-08 3:47 
GeneralRe: Render loop for other process Pin
Dave Kreskowiak28-Feb-08 14:44
mveDave Kreskowiak28-Feb-08 14:44 
GeneralRe: Render loop for other process Pin
Jitse29-Feb-08 9:33
Jitse29-Feb-08 9:33 
GeneralRe: Render loop for other process Pin
Dave Kreskowiak29-Feb-08 18:28
mveDave Kreskowiak29-Feb-08 18:28 
GeneralRe: Render loop for other process Pin
Jitse1-Mar-08 2:10
Jitse1-Mar-08 2:10 
GeneralRe: Render loop for other process Pin
Dave Kreskowiak1-Mar-08 14:45
mveDave Kreskowiak1-Mar-08 14:45 
GeneralRe: Render loop for other process Pin
Jitse2-Mar-08 2:23
Jitse2-Mar-08 2:23 
QuestionUsing System.Reflection to walk values in an array??? Pin
LongRange.Shooter27-Feb-08 8:08
LongRange.Shooter27-Feb-08 8:08 
I have an object that is several levels deep. It may or may not contain values in each level. I need to serialize the object as XML -- and yes, I would normally use XmlSerializer to accomplish this. The problem is that the application this is feeding requires an XML format that is not well-formed. The area in which it loses it's well-formedness (is that a word) is with arrays. That is also the area I'm having troubles getting my hands around.

I have my primary code which handles the parent and then creates instances of ObjectWalker and IEnumerableWalker to handle flat objects and arrays. Furthermore the arrays are only System.Collection.ArrayList. So I can specifically state that if property.DeclaringType.Name.Equals("ArrayList") then I know I have an array.

What I'd like to do is get the actual array object and pass it to my IEnumerableWalker, but it seems I cannot do that.

So I'm passing the PropertyInfo of the ArrayList, the object it is contained in, and the current Xml depth. What I cannot find on the internet or here is the next step of iterating through each element in the array and getting the property names and values.

If anyone can point me to a good article or snippet that does this I'd appreciate it!

Thanks

Here is my ObjectWalker that eventually calls an instance of IEnumerableWalker:
public void Walk(object newHierarchy, int depth)
{
    Type objectType = newHierarchy.GetType();
    XmlWriter.WriteOpen(objectType.Name);
    PropertyInfo[] properties = objectType.GetProperties();
    foreach (PropertyInfo property in properties)
    {
        Trace.WriteLine("Processing property" + property.Name);
        if (property.DeclaringType.Name.Equals("ArrayList"))
        {
            new IEnumerableWalker().Walk(property, newHierarchy, depth);
        }
        else if (property.PropertyType.FullName.StartsWith("MyNamespace"))
        {
            object itemValue = property.GetValue(newHierarchy, null);
            new ObjectWalker().Walk(itemValue, depth+1);
        }
        else if (property.CanRead && property.CanWrite && property.GetValue(newHierarchy, null) != null )
        {
            XmlWriter.WriteLine(property.Name, property.GetValue(newHierarchy, null).ToString(), depth);
        }
    }
    XmlWriter.WriteClose(objectType.Name);
}

GeneralRe: Using System.Reflection to walk values in an array??? Pin
buchstaben27-Feb-08 8:18
buchstaben27-Feb-08 8:18 
GeneralRe: Using System.Reflection to walk values in an array??? Pin
LongRange.Shooter27-Feb-08 8:32
LongRange.Shooter27-Feb-08 8:32 
GeneralRe: Using System.Reflection to walk values in an array??? Pin
buchstaben27-Feb-08 8:42
buchstaben27-Feb-08 8:42 
GeneralRe: Using System.Reflection to walk values in an array??? Pin
LongRange.Shooter27-Feb-08 12:15
LongRange.Shooter27-Feb-08 12:15 
Generalvs 2003 debugger issue Pin
robustm27-Feb-08 7:53
robustm27-Feb-08 7:53 
AnswerRe: vs 2003 debugger issue Pin
buchstaben27-Feb-08 7:59
buchstaben27-Feb-08 7:59 
GeneralSystem.io.Directory.GetFiles Pin
George Luttrell27-Feb-08 7:45
George Luttrell27-Feb-08 7:45 
GeneralRe: System.io.Directory.GetFiles Pin
buchstaben27-Feb-08 7:51
buchstaben27-Feb-08 7:51 
GeneralRe: System.io.Directory.GetFiles Pin
George Luttrell28-Feb-08 3:43
George Luttrell28-Feb-08 3:43 
GeneralRe: System.io.Directory.GetFiles Pin
buchstaben28-Feb-08 3:49
buchstaben28-Feb-08 3:49 
GeneralRe: System.io.Directory.GetFiles Pin
George Luttrell28-Feb-08 13:43
George Luttrell28-Feb-08 13:43 
GeneralTrapping a Keystroke Pin
MarkMokris27-Feb-08 6:30
MarkMokris27-Feb-08 6:30 
GeneralRe: Trapping a Keystroke Pin
Gareth H27-Feb-08 6:37
Gareth H27-Feb-08 6:37 
GeneralRe: Trapping a Keystroke Pin
MarkMokris27-Feb-08 6:42
MarkMokris27-Feb-08 6:42 
GeneralRe: Trapping a Keystroke Pin
Gareth H27-Feb-08 6:49
Gareth H27-Feb-08 6:49 
GeneralRe: Trapping a Keystroke Pin
PIEBALDconsult27-Feb-08 6:58
mvePIEBALDconsult27-Feb-08 6:58 
GeneralRe: Trapping a Keystroke Pin
Dave Kreskowiak27-Feb-08 7:04
mveDave Kreskowiak27-Feb-08 7:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.