//
// Copyright (c) 2009 Microsoft Corporation All Rights Reserved
//
// Michael S. Scherotter
// mischero@microsoft.com
// 2008-10-09
// Silverlight utility classes
using System;
using System.Linq;
using System.Text;
public sealed class Utility
{
///
/// Gets a string with all of the properties that are not null.
///
/// the object to query
/// a string formatted the property names and values
public static string GetProperties(object data){
var type = data.GetType();
var properties = type.GetProperties().OrderBy(item => item.Name);
StringBuilder builder = new StringBuilder("-- " + type.FullName + " --");
foreach (var property in properties)
{
var value = property.GetValue(data, null);
if (value != null)
{
builder.AppendLine();
builder.AppendFormat(System.Globalization.CultureInfo.CurrentCulture, "{0}: {1}", property.Name, value);
}
}
return builder.ToString();
}
}