public static string PrintToString <T>(this T obj, Func <PrintingConfig <T>, PrintingConfig <T> > configPrinter) { var printer = configPrinter(ObjectPrinter.For <T>()); return(printer.PrintToString(obj)); }
/// <summary> /// Serialize object with configuration /// </summary> /// <typeparam name="T">object type</typeparam> /// <param name="obj">this object</param> /// <param name="configuratePrinter">function wchich include and configurate serializator</param> /// <returns>serializarion in string</returns> public static string Serialize <T>(this T obj, Action <PrintingConfig <T> > configuratePrinter) { var printer = ObjectPrinter.For <T>(); configuratePrinter(printer); return(printer.PrintToString(obj)); }
public static string PrintToString <TOwner>(this TOwner obj, Func <IPrintingConfig <TOwner>, IPrintingConfig <TOwner> > config) { var printer = config(ObjectPrinter.For <TOwner>()); return(printer.PrintToString(obj)); }
public static void Main() { var person = new Person { Name = "Alex", Age = 20 }; var printer = ObjectPrinter.For <Person>() //1. Исключить из сериализации свойства определенного типа .Excluding <Guid>() //2. Указать альтернативный способ сериализации для определенного типа .Printing <int>().Using(i => i.ToString()) //3. Для числовых типов указать культуру .Printing <int>().Using(CultureInfo.InvariantCulture) //4. Настроить сериализацию конкретного свойства //5. Настроить обрезание строковых свойств (метод должен быть виден только для строковых свойств) .Printing(p => p.Name).TrimmedToLength(2) //6. Исключить из сериализации конкретного свойства .Excluding(p => p.Age); string s1 = printer.PrintToString(person); string s2 = person.PrintToString(); Console.WriteLine(s1); Console.WriteLine(s2); }
public static void Main() { var person = new Person { Name = "Alex", Age = 19, Parent = new Person() { Name = "Sanny" } }; var printer = ObjectPrinter.For <Person>() //1. Исключить из сериализации свойства определенного типа //.ExcludeType<int>() //2. Указать альтернативный способ сериализации для определенного типа .Printing(t => t.Age).Using(t => t + " yo") .Printing <string>().Using(2); //3. Для числовых типов указать культуру //.Printing<int>().UsingCulture(new CultureInfo("en")) //4. Настроить сериализацию конкретного свойства //.Printing(t => t.Age).Using(t => t.ToString()) //5. Настроить обрезание строковых свойств (метод должен быть виден только для строковых свойств) //.Printing<string>().Using(5) //6. Исключить из сериализации конкретного свойства //.ExcludeProperty(t => t.Age) //.ExcludeType<double>() //.Printing(t => t.Name).Using(t => t + " is dead"); Console.Write(printer.PrintToString(person)); }
public void Should_ExcludeByTypeCorrectly() { var printer = ObjectPrinter.For <Person>() .Excluding <int>(); var printing = printer.PrintToString(person); var expected = "Person" + Environment.NewLine + $"\tId = {person.Id}" + Environment.NewLine + $"\tName = {person.Name}" + Environment.NewLine + $"\tHeight = {person.Height}" + Environment.NewLine; printing.Should().BeEquivalentTo(expected); }
public void Should_TrimStringsCorrectly() { var printer = ObjectPrinter.For <Person>() .Printing(p => p.Name) .TrimmedToLength(2); var printing = printer.PrintToString(person); var expected = "Person" + Environment.NewLine + $"\tId = {person.Id}" + Environment.NewLine + $"\tName = Jo" + Environment.NewLine + $"\tHeight = {person.Height}" + Environment.NewLine + $"\tAge = {person.Age}" + Environment.NewLine; printing.Should().BeEquivalentTo(expected); }
public void Should_SerializeByPropertyCorrectly() { var printer = ObjectPrinter.For <Person>() .Printing(p => p.Name) .Using(name => name.ToLower()); var printing = printer.PrintToString(person); var expected = "Person" + Environment.NewLine + $"\tId = {person.Id}" + Environment.NewLine + $"\tName = {person.Name.ToLower()}" + Environment.NewLine + $"\tHeight = {person.Height}" + Environment.NewLine + $"\tAge = {person.Age}" + Environment.NewLine; printing.Should().BeEquivalentTo(expected); }
public void Should_ChangeCultureInfoCorrectly() { var printer = ObjectPrinter.For <Person>() .Printing <double>() .Using(CultureInfo.InstalledUICulture); var printing = printer.PrintToString(person); var expected = "Person" + Environment.NewLine + $"\tId = {person.Id}" + Environment.NewLine + $"\tName = {person.Name}" + Environment.NewLine + $"\tHeight = {person.Height.ToString(CultureInfo.InstalledUICulture)}" + Environment.NewLine + $"\tAge = {person.Age}" + Environment.NewLine; printing.Should().BeEquivalentTo(expected); }
public static string PrintToString <T>(this T obj, Func <PrintingConfig <T>, PrintingConfig <T> > func) { return(func(ObjectPrinter.For <T>()).GetStringRepresentation(obj)); }
public static string GetDefaultSerializ(this Person person) { return(ObjectPrinter.For <Person>().PrintToString(person)); }
public static string PrintToString <T>(this T printedObject) { return(ObjectPrinter.For <T>().PrintToString(printedObject)); }
public static string PrintToString <TOwner> (this TOwner obj, Func <PrintingConfig <TOwner>, PrintingConfig <TOwner> > printConfig) { return(printConfig(ObjectPrinter.For <TOwner>()).PrintToString(obj)); }
/// <summary> /// Serialize object /// </summary> /// <typeparam name="T">type</typeparam> /// <param name="obj">this object</param> /// <returns>serializarion in string</returns> public static string Serialize <T>(this T obj) { var printer = ObjectPrinter.For <T>(); return(printer.PrintToString(obj)); }
public static string PrintToString <T>(this T obj, Func <PrintingConfig <T>, PrintingConfig <T> > configFunc) => configFunc(ObjectPrinter.For <T>()).PrintToString(obj);
public static string PrintToString <T>(this T serializableObject) { return(ObjectPrinter.For <object>().PrintToString(serializableObject)); }
public static string PrintToString <T>(this T obj) { return(ObjectPrinter <T> .Should().Build().PrintToString(obj)); }
public static string PrintToString <T>(this T obj) { return(ObjectPrinter.For <T>().GetStringRepresentation(obj)); }
public static string PrintToString <T>(this T obj) { return(ObjectPrinter.For <T>().PrintToString(obj)); }
public static string PrintToString <T>(this T obj) => ObjectPrinter.For <T>().PrintToString(obj);
public static string PrintToString <T>(this T obj, Func <PrintingConfig <T>, PrintingConfig <T> > config) { return(config(ObjectPrinter.For <T>()).PrintToString(obj)); }
public static string PrintToString <T>(this T serializableObject, Func <PrintingConfig <T>, PrintingConfig <T> > configurationFunction) { return(configurationFunction(ObjectPrinter.For <T>()).PrintToString(serializableObject)); }