public static int Len(object obj) { if (obj != null) { var collection = obj as ICollection; if (collection != null) return collection.Count; var s = obj as string; if (s != null) return s.Length; } throw new ArgumentException(); }