Skip to content

Commit

Permalink
replace tabs with spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
epeshk committed Nov 20, 2018
1 parent c42dca5 commit 52e58e6
Show file tree
Hide file tree
Showing 16 changed files with 323 additions and 232 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
; 4-column space indentation
[*.{cs,tt}]
indent_style = space
indent_size = 4
7 changes: 7 additions & 0 deletions CSharpCodeStyle.SpaceIndent.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<!-- code style guide version 1.0.5 -->
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CommonFormatter/USE_INDENTS_FROM_MAIN_LANGUAGE_IN_FILE/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CommonFormatter/ALIGNMENT_TAB_FILL_STYLE/@EntryValue">USE_SPACES_ONLY</s:String>

<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EFormat_002ESettingsUpgrade_002EAlignmentTabFillStyleMigration/@EntryIndexedValue">True</s:Boolean>
</wpf:ResourceDictionary>
8 changes: 4 additions & 4 deletions ObjectPrinting/ObjectPrinter.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace ObjectPrinting
{
public class ObjectPrinter
{
public static PrintingConfig<T> For<T>()
{
{
public static PrintingConfig<T> For<T>()
{
return new PrintingConfig<T>();
}
}
}
}
14 changes: 7 additions & 7 deletions ObjectPrinting/Solved/ObjectExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace ObjectPrinting.Solved
{
public static class ObjectExtensions
{
public static string PrintToString<T>(this T obj)
{
return ObjectPrinter.For<T>().PrintToString(obj);
}
}
public static class ObjectExtensions
{
public static string PrintToString<T>(this T obj)
{
return ObjectPrinter.For<T>().PrintToString(obj);
}
}
}
14 changes: 7 additions & 7 deletions ObjectPrinting/Solved/ObjectPrinter.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace ObjectPrinting.Solved
{
public class ObjectPrinter
{
public static PrintingConfig<T> For<T>()
{
return new PrintingConfig<T>();
}
}
public class ObjectPrinter
{
public static PrintingConfig<T> For<T>()
{
return new PrintingConfig<T>();
}
}
}
100 changes: 50 additions & 50 deletions ObjectPrinting/Solved/PrintingConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,58 @@

namespace ObjectPrinting.Solved
{
public class PrintingConfig<TOwner>
{
public PropertyPrintingConfig<TOwner, TPropType> Printing<TPropType>()
{
return new PropertyPrintingConfig<TOwner, TPropType>(this);
}
public class PrintingConfig<TOwner>
{
public PropertyPrintingConfig<TOwner, TPropType> Printing<TPropType>()
{
return new PropertyPrintingConfig<TOwner, TPropType>(this);
}

public PropertyPrintingConfig<TOwner, TPropType> Printing<TPropType>(Expression<Func<TOwner, TPropType>> memberSelector)
{
return new PropertyPrintingConfig<TOwner, TPropType>(this);
}

public PrintingConfig<TOwner> Excluding<TPropType>(Expression<Func<TOwner, TPropType>> memberSelector)
{
return this;
}

internal PrintingConfig<TOwner> Excluding<TPropType>()
{
return this;
}

public string PrintToString(TOwner obj)
{
return PrintToString(obj, 0);
}

private string PrintToString(object obj, int nestingLevel)
{
//TODO apply configurations
if (obj == null)
{
return new PropertyPrintingConfig<TOwner, TPropType>(this);
}

public PrintingConfig<TOwner> Excluding<TPropType>(Expression<Func<TOwner, TPropType>> memberSelector)
{
return this;
}

internal PrintingConfig<TOwner> Excluding<TPropType>()
{
return this;
}

public string PrintToString(TOwner obj)
{
return PrintToString(obj, 0);
}

private string PrintToString(object obj, int nestingLevel)
{
//TODO apply configurations
if (obj == null)
return "null" + Environment.NewLine;

var finalTypes = new[]
{
typeof(int), typeof(double), typeof(float), typeof(string),
typeof(DateTime), typeof(TimeSpan)
};
if (finalTypes.Contains(obj.GetType()))
return obj + Environment.NewLine;

var identation = new string('\t', nestingLevel + 1);
var sb = new StringBuilder();
var type = obj.GetType();
sb.AppendLine(type.Name);
foreach (var propertyInfo in type.GetProperties())
{
sb.Append(identation + propertyInfo.Name + " = " +
PrintToString(propertyInfo.GetValue(obj),
nestingLevel + 1));
}
return sb.ToString();
}
}
var finalTypes = new[]
{
typeof(int), typeof(double), typeof(float), typeof(string),
typeof(DateTime), typeof(TimeSpan)
};
if (finalTypes.Contains(obj.GetType()))
return obj + Environment.NewLine;

var identation = new string('\t', nestingLevel + 1);
var sb = new StringBuilder();
var type = obj.GetType();
sb.AppendLine(type.Name);
foreach (var propertyInfo in type.GetProperties())
{
sb.Append(identation + propertyInfo.Name + " = " +
PrintToString(propertyInfo.GetValue(obj),
nestingLevel + 1));
}
return sb.ToString();
}
}
}
40 changes: 20 additions & 20 deletions ObjectPrinting/Solved/PropertyPrintingConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@
namespace ObjectPrinting.Solved
{
public class PropertyPrintingConfig<TOwner, TPropType> : IPropertyPrintingConfig<TOwner, TPropType>
{
private readonly PrintingConfig<TOwner> printingConfig;
{
private readonly PrintingConfig<TOwner> printingConfig;

public PropertyPrintingConfig(PrintingConfig<TOwner> printingConfig)
{
this.printingConfig = printingConfig;
}
public PropertyPrintingConfig(PrintingConfig<TOwner> printingConfig)
{
this.printingConfig = printingConfig;
}

public PrintingConfig<TOwner> Using(Func<TPropType, string> print)
{
return printingConfig;
}
public PrintingConfig<TOwner> Using(Func<TPropType, string> print)
{
return printingConfig;
}

public PrintingConfig<TOwner> Using(CultureInfo culture)
{
return printingConfig;
}
public PrintingConfig<TOwner> Using(CultureInfo culture)
{
return printingConfig;
}

PrintingConfig<TOwner> IPropertyPrintingConfig<TOwner, TPropType>.ParentConfig => printingConfig;
}
PrintingConfig<TOwner> IPropertyPrintingConfig<TOwner, TPropType>.ParentConfig => printingConfig;
}

public interface IPropertyPrintingConfig<TOwner, TPropType>
{
PrintingConfig<TOwner> ParentConfig { get; }
}
public interface IPropertyPrintingConfig<TOwner, TPropType>
{
PrintingConfig<TOwner> ParentConfig { get; }
}
}
22 changes: 11 additions & 11 deletions ObjectPrinting/Solved/PropertyPrintingConfigExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

namespace ObjectPrinting.Solved
{
public static class PropertyPrintingConfigExtensions
{
public static string PrintToString<T>(this T obj, Func<PrintingConfig<T>, PrintingConfig<T>> config)
{
return config(ObjectPrinter.For<T>()).PrintToString(obj);
}
public static class PropertyPrintingConfigExtensions
{
public static string PrintToString<T>(this T obj, Func<PrintingConfig<T>, PrintingConfig<T>> config)
{
return config(ObjectPrinter.For<T>()).PrintToString(obj);
}

public static PrintingConfig<TOwner> TrimmedToLength<TOwner>(this PropertyPrintingConfig<TOwner, string> propConfig, int maxLen)
{
return ((IPropertyPrintingConfig<TOwner, string>)propConfig).ParentConfig;
}
public static PrintingConfig<TOwner> TrimmedToLength<TOwner>(this PropertyPrintingConfig<TOwner, string> propConfig, int maxLen)
{
return ((IPropertyPrintingConfig<TOwner, string>)propConfig).ParentConfig;
}

}
}
}
62 changes: 31 additions & 31 deletions ObjectPrinting/Solved/Tests/ObjectPrinterAcceptanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,37 @@

namespace ObjectPrinting.Solved.Tests
{
[TestFixture]
public class ObjectPrinterAcceptanceTests
{
[Test]
public void Demo()
{
var person = new Person { Name = "Alex", Age = 19 };
[TestFixture]
public class ObjectPrinterAcceptanceTests
{
[Test]
public void Demo()
{
var person = new Person { Name = "Alex", Age = 19 };

var printer = ObjectPrinter.For<Person>()
//1. Исключить из сериализации свойства определенного типа
.Excluding<Guid>()
//2. Указать альтернативный способ сериализации для определенного типа
.Printing<int>().Using(i => i.ToString("X"))
//3. Для числовых типов указать культуру
.Printing<double>().Using(CultureInfo.InvariantCulture)
//4. Настроить сериализацию конкретного свойства
//5. Настроить обрезание строковых свойств (метод должен быть виден только для строковых свойств)
.Printing(p => p.Name).TrimmedToLength(10)
//6. Исключить из сериализации конкретного свойства
.Excluding(p => p.Age);
var printer = ObjectPrinter.For<Person>()
//1. Исключить из сериализации свойства определенного типа
.Excluding<Guid>()
//2. Указать альтернативный способ сериализации для определенного типа
.Printing<int>().Using(i => i.ToString("X"))
//3. Для числовых типов указать культуру
.Printing<double>().Using(CultureInfo.InvariantCulture)
//4. Настроить сериализацию конкретного свойства
//5. Настроить обрезание строковых свойств (метод должен быть виден только для строковых свойств)
.Printing(p => p.Name).TrimmedToLength(10)
//6. Исключить из сериализации конкретного свойства
.Excluding(p => p.Age);

string s1 = printer.PrintToString(person);
//7. Синтаксический сахар в виде метода расширения, сериализующего по-умолчанию
string s2 = person.PrintToString();
//8. ...с конфигурированием
string s3 = person.PrintToString(s => s.Excluding(p => p.Age));
Console.WriteLine(s1);
Console.WriteLine(s2);
Console.WriteLine(s3);
}
}
string s1 = printer.PrintToString(person);
//7. Синтаксический сахар в виде метода расширения, сериализующего по-умолчанию
string s2 = person.PrintToString();
//8. ...с конфигурированием
string s3 = person.PrintToString(s => s.Excluding(p => p.Age));
Console.WriteLine(s1);
Console.WriteLine(s2);
Console.WriteLine(s3);
}
}
}
14 changes: 7 additions & 7 deletions ObjectPrinting/Solved/Tests/Person.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace ObjectPrinting.Solved.Tests
{
public class Person
{
public Guid Id { get; set; }
public string Name { get; set; }
public double Height { get; set; }
public int Age { get; set; }
}
public class Person
{
public Guid Id { get; set; }
public string Name { get; set; }
public double Height { get; set; }
public int Age { get; set; }
}
}
36 changes: 18 additions & 18 deletions ObjectPrinting/Tests/ObjectPrinterAcceptanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@

namespace ObjectPrinting.Tests
{
[TestFixture]
public class ObjectPrinterAcceptanceTests
{
[Test]
public void Demo()
{
var person = new Person { Name = "Alex", Age = 19 };
[TestFixture]
public class ObjectPrinterAcceptanceTests
{
[Test]
public void Demo()
{
var person = new Person { Name = "Alex", Age = 19 };

var printer = ObjectPrinter.For<Person>();
//1. Исключить из сериализации свойства определенного типа
//2. Указать альтернативный способ сериализации для определенного типа
//3. Для числовых типов указать культуру
//4. Настроить сериализацию конкретного свойства
//5. Настроить обрезание строковых свойств (метод должен быть виден только для строковых свойств)
//6. Исключить из сериализации конкретного свойства
var printer = ObjectPrinter.For<Person>();
//1. Исключить из сериализации свойства определенного типа
//2. Указать альтернативный способ сериализации для определенного типа
//3. Для числовых типов указать культуру
//4. Настроить сериализацию конкретного свойства
//5. Настроить обрезание строковых свойств (метод должен быть виден только для строковых свойств)
//6. Исключить из сериализации конкретного свойства

string s1 = printer.PrintToString(person);

//7. Синтаксический сахар в виде метода расширения, сериализующего по-умолчанию
//8. ...с конфигурированием
}
}
//7. Синтаксический сахар в виде метода расширения, сериализующего по-умолчанию
//8. ...с конфигурированием
}
}
}
Loading

0 comments on commit 52e58e6

Please sign in to comment.