/// <summary>/// Generic and reusable IComparer for string based properties./// </summary>public class StringPropertyComparer : IComparer{ private string m_propertyName; private Type m_declaringClass; public StringPropertyComparer(Type declaringClass, string propertyName) { m_declaringClass = declaringClass; m_propertyName = propertyName; } private string getPropertyValue(object instance) { PropertyInfo info = m_declaringClass.GetProperty(m_propertyName, typeof(string)); return (string) info.GetValue(instance, null); } public int Compare(object lhsObj, object rhsObj) { string lhs = getPropertyValue(lhsObj); string rhs = getPropertyValue(rhsObj); return ((new CaseInsensitiveComparer()).Compare(lhs, rhs)); }}
Powered by: newtelligence dasBlog 2.1.8102.813
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2012, Shawn Neal
E-mail