Skip to content

Print all properties of Environment class

4 July 2010

If you need a quick overview of the system configuration you can use this code snippet:

public class EnvironmentHelper
{
    public static string GetAllEnvironmentInformations()
    {
        StringBuilder builder = new StringBuilder();

        Type type = typeof(Environment);
        PropertyInfo[] propertyInfos = type.GetProperties();
        foreach (PropertyInfo propertyInfo in propertyInfos)
        {
            object value = propertyInfo.GetValue(null, null);
            if( value != null)
            {
                builder.AppendLine(propertyInfo.Name + ": " + value);
            }
        }

        return builder.ToString();
    }
}
Advertisements

From → .NET, C#

Leave a Comment

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: