C# propertyinfo getvalue
<p>I have constructed a generic method which "deserialiazes" an object in the following manner:</p>

<pre><code>public class AClass
{
   public int Id {get; set;}
   public string Name {get;set;}
}


public class NestingClass
{
  public string Address {get; set;}
  List&lt;AClass&gt; Classes {get; set;}
}
</code></pre>

<p>the output if a list of keyvaluepair : NestingClass Value: none, AddressNestingClass value,
List1.Generic.Collections ClassesNestingClass none, IdAClassNestingClass value, NameAClassNestingClass value.</p>

<p>I manage to get the types of all , but with the values is a little harder because while using propertyInfo.GetValue() i  cannot use always the object, e.g for the propertyInfos of a AClass the object (which is the type which forms the list of classes) the object should be of type AClass. Using "this" also does not work . I get the object doesn't match the target object.
What I would need is some sort of mechanism of "slicing" through the object passed as a generic parameter and try to get the values in that manner. 
The code is something like:</p>

<pre><code>    public List&lt;KeyValuePair&lt;string,string&gt;&gt; Process(object foo)
    {

        if (foo == null)
            return new List&lt;KeyValuePair&lt;string,string&gt;&gt;();
        var result = List&lt;KeyValuePair&lt;string,string&gt;&gt;();

        var types = new Stack&lt;Helper&gt;();
        types.Push(new Helper { Type = o.GetType(),Name = string.Empty, Value = string.Empty });

        while (types.Count &gt; 0)
        {
            Helper tHelper = types.Pop();
            Type t = tHelper.Type;
            result.Items.Add(new KeyValuePair { Key = tHelper.Name, Value = tHelper.Value });
            if (t.IsValueType || t == typeof(string))
                continue;

            if (t.IsGenericType)
            {
                foreach (var arg in t.GetGenericArguments())
                    types.Push(new TypeHelper { Type = arg, Name = string.Empty });
                continue;

            }

                foreach (var propertyInfo in t.GetProperties())
                {
//here comes the issue                   
                    types.Push(new TypeHelper { Type = propertyInfo.PropertyType, Name = propertyInfo.Name + propertyInfo.DeclaringType.Name, Value= propertyInfo.GetValue(this,null).ToString() });
                }
            }

            return result;
        }
</code></pre>
