Question

Is there a way to retrieve metadata about the .NET APIs?

For example, suppose I'd like to get a list of all the properties defined for System.Windows.Documents.List. It'd be nice to get this information in some structured format such as XML, JSON, etc. Each entry should look something like:

<property name="MarkerStyle" type="TextMarkerStyle" get="true" set="true"/>

I'd like to avoid having to screen scrape the MSDN library. :-)

Était-ce utile?

La solution

You could use Reflection to retrieve metadata about existing classes at runtime. The GetProperties method is something you could start with.

Autres conseils

You can use Reflection and write some code to do the formatting into XML, JSON etc.

Or you can use a tool like Reflector

Thanks to Darin and Robert for the pointers to the System.Reflection namespace.

Here is a short program which prints out all the public properties of List:

using System;
using System.Reflection;
using System.Windows.Documents;

namespace ReflectionWpfListPropertiesTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var members = typeof(List).GetMembers();

            Array.ForEach(members, info =>
                {
                    if (info.MemberType == MemberTypes.Property)
                        Console.WriteLine(info);
                });
        }
    }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top