public static T GetInstance(DataRow dr) { var ctors = typeof(T).GetConstructors( BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); if (ctors.Count() != 1) throw new InvalidOperationException(String.Format("Type {0} must have exactly one constructor.", typeof(T))); var ctor = ctors.SingleOrDefault(c => c.IsPrivate); if (ctor == null) throw new InvalidOperationException(String.Format("The constructor for {0} must be private.", typeof(T))); return (T)ctor.Invoke(new object[] { dr }); } public static T GetInstance(DataRow dr) { var ctors = typeof(T).GetConstructors( BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); if (ctors.Count() != 1) throw new InvalidOperationException(String.Format("Type {0} must have exactly one constructor.", typeof(T))); var ctor = ctors.SingleOrDefault(c => c.IsPrivate); if (ctor == null) throw new InvalidOperationException(String.Format("The constructor for {0} must be private.", typeof(T))); return (T)ctor.Invoke(new object[] { dr }); }