public string Unwrap <TEnumerable>(TEnumerable enumerable) where TEnumerable : IEnumerable { if (enumerable == null) { return(String.Empty); } StringBuilder sb = new StringBuilder(200); sb.Append("["); foreach (var val in enumerable) { if (val == null) { continue; } sb.Append(PocoToStringerConfiguration.ArraySeparator); if (val.GetType().IsClass) { sb.Append(ToStringer.GetString(val)); } else { sb.Append(val); } } sb.Remove(1, 1).Append("]"); return(sb.ToString()); }
public void CreateByOther() { var provider = new ToStringer(); var attrType = typeof (DescriptionAttribute); var str = Create().Create(attrType, provider); Assert.AreEqual($"{attrType.FullName}|{ToStringer.Name}", str); }
public void Test() { PocoToStringerConfiguration.SetPocoFormatter <DefaultPocoFormatter>(); PocoToStringerConfiguration.ArraySeparator = "|"; var testclass = new MyClass() { }; Stopwatch sw = new Stopwatch(); Console.WriteLine(ToStringer <MyClass> .GetString(testclass)); Console.WriteLine(ToStringer.GetString(testclass)); Console.WriteLine(testclass.ToString()); sw.Start(); for (int i = 0; i < 2000000; i++) { var y = ToStringer <MyClass> .GetString(testclass); } sw.Stop(); Console.WriteLine(sw.Elapsed.TotalMilliseconds); sw.Reset(); sw.Start(); for (int i = 0; i < 2000000; i++) { var y = ToStringer.GetString(testclass); } sw.Stop(); Console.WriteLine(sw.Elapsed.TotalMilliseconds); sw.Reset(); sw.Start(); for (int i = 0; i < 2000000; i++) { var y = testclass.ToString(); } sw.Stop(); Console.WriteLine(sw.Elapsed.TotalMilliseconds); Console.ReadKey(); }