enumerate properties of anonymous type
Published: 21. December 2008 | Updated: 26. October 2011License: Microsoft Public License (MS-PL)
Categories: Framework » Reflection, Framework » Types
Tags: C# Reflection
Import namespace
using System.ComponentModel;
Code
object values = new { firstProperty = "value", secondProperty = 2 }; foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(values)) { Console.WriteLine("{0} = {1}", descriptor.Name, descriptor.GetValue(values)); }Console Output:
firstProperty = value
secondProperty = 2
secondProperty = 2
| Send us feedback about this snippet » |





