diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..cbb77773 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,4 @@ +; 4-column space indentation +[*.{cs,tt}] +indent_style = space +indent_size = 4 \ No newline at end of file diff --git a/CSharpCodeStyle.SpaceIndent.DotSettings b/CSharpCodeStyle.SpaceIndent.DotSettings new file mode 100644 index 00000000..9174a55b --- /dev/null +++ b/CSharpCodeStyle.SpaceIndent.DotSettings @@ -0,0 +1,7 @@ + + + False + USE_SPACES_ONLY + + True + \ No newline at end of file diff --git a/ObjectPrinting/ObjectPrinter.cs b/ObjectPrinting/ObjectPrinter.cs index be4a4e7a..3c7867c3 100644 --- a/ObjectPrinting/ObjectPrinter.cs +++ b/ObjectPrinting/ObjectPrinter.cs @@ -1,10 +1,10 @@ namespace ObjectPrinting { public class ObjectPrinter - { - public static PrintingConfig For() - { + { + public static PrintingConfig For() + { return new PrintingConfig(); } - } + } } \ No newline at end of file diff --git a/ObjectPrinting/Solved/ObjectExtensions.cs b/ObjectPrinting/Solved/ObjectExtensions.cs index a1643b37..b0c94553 100644 --- a/ObjectPrinting/Solved/ObjectExtensions.cs +++ b/ObjectPrinting/Solved/ObjectExtensions.cs @@ -1,10 +1,10 @@ namespace ObjectPrinting.Solved { - public static class ObjectExtensions - { - public static string PrintToString(this T obj) - { - return ObjectPrinter.For().PrintToString(obj); - } - } + public static class ObjectExtensions + { + public static string PrintToString(this T obj) + { + return ObjectPrinter.For().PrintToString(obj); + } + } } \ No newline at end of file diff --git a/ObjectPrinting/Solved/ObjectPrinter.cs b/ObjectPrinting/Solved/ObjectPrinter.cs index c9fdad86..540ee769 100644 --- a/ObjectPrinting/Solved/ObjectPrinter.cs +++ b/ObjectPrinting/Solved/ObjectPrinter.cs @@ -1,10 +1,10 @@ namespace ObjectPrinting.Solved { - public class ObjectPrinter - { - public static PrintingConfig For() - { - return new PrintingConfig(); - } - } + public class ObjectPrinter + { + public static PrintingConfig For() + { + return new PrintingConfig(); + } + } } \ No newline at end of file diff --git a/ObjectPrinting/Solved/PrintingConfig.cs b/ObjectPrinting/Solved/PrintingConfig.cs index 801a2f4b..0ec5aeb2 100644 --- a/ObjectPrinting/Solved/PrintingConfig.cs +++ b/ObjectPrinting/Solved/PrintingConfig.cs @@ -5,58 +5,58 @@ namespace ObjectPrinting.Solved { - public class PrintingConfig - { - public PropertyPrintingConfig Printing() - { - return new PropertyPrintingConfig(this); - } + public class PrintingConfig + { + public PropertyPrintingConfig Printing() + { + return new PropertyPrintingConfig(this); + } public PropertyPrintingConfig Printing(Expression> memberSelector) - { - return new PropertyPrintingConfig(this); - } - - public PrintingConfig Excluding(Expression> memberSelector) - { - return this; - } - - internal PrintingConfig Excluding() - { - 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(this); + } + + public PrintingConfig Excluding(Expression> memberSelector) + { + return this; + } + + internal PrintingConfig Excluding() + { + 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(); + } + } } \ No newline at end of file diff --git a/ObjectPrinting/Solved/PropertyPrintingConfig.cs b/ObjectPrinting/Solved/PropertyPrintingConfig.cs index 4aa96372..a509697d 100644 --- a/ObjectPrinting/Solved/PropertyPrintingConfig.cs +++ b/ObjectPrinting/Solved/PropertyPrintingConfig.cs @@ -4,29 +4,29 @@ namespace ObjectPrinting.Solved { public class PropertyPrintingConfig : IPropertyPrintingConfig - { - private readonly PrintingConfig printingConfig; + { + private readonly PrintingConfig printingConfig; - public PropertyPrintingConfig(PrintingConfig printingConfig) - { - this.printingConfig = printingConfig; - } + public PropertyPrintingConfig(PrintingConfig printingConfig) + { + this.printingConfig = printingConfig; + } - public PrintingConfig Using(Func print) - { - return printingConfig; - } + public PrintingConfig Using(Func print) + { + return printingConfig; + } - public PrintingConfig Using(CultureInfo culture) - { - return printingConfig; - } + public PrintingConfig Using(CultureInfo culture) + { + return printingConfig; + } - PrintingConfig IPropertyPrintingConfig.ParentConfig => printingConfig; - } + PrintingConfig IPropertyPrintingConfig.ParentConfig => printingConfig; + } - public interface IPropertyPrintingConfig - { - PrintingConfig ParentConfig { get; } - } + public interface IPropertyPrintingConfig + { + PrintingConfig ParentConfig { get; } + } } \ No newline at end of file diff --git a/ObjectPrinting/Solved/PropertyPrintingConfigExtensions.cs b/ObjectPrinting/Solved/PropertyPrintingConfigExtensions.cs index 5a2528e7..dd392239 100644 --- a/ObjectPrinting/Solved/PropertyPrintingConfigExtensions.cs +++ b/ObjectPrinting/Solved/PropertyPrintingConfigExtensions.cs @@ -2,17 +2,17 @@ namespace ObjectPrinting.Solved { - public static class PropertyPrintingConfigExtensions - { - public static string PrintToString(this T obj, Func, PrintingConfig> config) - { - return config(ObjectPrinter.For()).PrintToString(obj); - } + public static class PropertyPrintingConfigExtensions + { + public static string PrintToString(this T obj, Func, PrintingConfig> config) + { + return config(ObjectPrinter.For()).PrintToString(obj); + } - public static PrintingConfig TrimmedToLength(this PropertyPrintingConfig propConfig, int maxLen) - { - return ((IPropertyPrintingConfig)propConfig).ParentConfig; - } + public static PrintingConfig TrimmedToLength(this PropertyPrintingConfig propConfig, int maxLen) + { + return ((IPropertyPrintingConfig)propConfig).ParentConfig; + } - } + } } \ No newline at end of file diff --git a/ObjectPrinting/Solved/Tests/ObjectPrinterAcceptanceTests.cs b/ObjectPrinting/Solved/Tests/ObjectPrinterAcceptanceTests.cs index d8948647..ac52d5ee 100644 --- a/ObjectPrinting/Solved/Tests/ObjectPrinterAcceptanceTests.cs +++ b/ObjectPrinting/Solved/Tests/ObjectPrinterAcceptanceTests.cs @@ -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() - //1. Исключить из сериализации свойства определенного типа - .Excluding() - //2. Указать альтернативный способ сериализации для определенного типа - .Printing().Using(i => i.ToString("X")) - //3. Для числовых типов указать культуру - .Printing().Using(CultureInfo.InvariantCulture) - //4. Настроить сериализацию конкретного свойства - //5. Настроить обрезание строковых свойств (метод должен быть виден только для строковых свойств) - .Printing(p => p.Name).TrimmedToLength(10) - //6. Исключить из сериализации конкретного свойства - .Excluding(p => p.Age); + var printer = ObjectPrinter.For() + //1. Исключить из сериализации свойства определенного типа + .Excluding() + //2. Указать альтернативный способ сериализации для определенного типа + .Printing().Using(i => i.ToString("X")) + //3. Для числовых типов указать культуру + .Printing().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); + } + } } \ No newline at end of file diff --git a/ObjectPrinting/Solved/Tests/Person.cs b/ObjectPrinting/Solved/Tests/Person.cs index 08663226..858ebbf8 100644 --- a/ObjectPrinting/Solved/Tests/Person.cs +++ b/ObjectPrinting/Solved/Tests/Person.cs @@ -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; } + } } \ No newline at end of file diff --git a/ObjectPrinting/Tests/ObjectPrinterAcceptanceTests.cs b/ObjectPrinting/Tests/ObjectPrinterAcceptanceTests.cs index fe215d6a..4c8b2445 100644 --- a/ObjectPrinting/Tests/ObjectPrinterAcceptanceTests.cs +++ b/ObjectPrinting/Tests/ObjectPrinterAcceptanceTests.cs @@ -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(); - //1. Исключить из сериализации свойства определенного типа - //2. Указать альтернативный способ сериализации для определенного типа - //3. Для числовых типов указать культуру - //4. Настроить сериализацию конкретного свойства - //5. Настроить обрезание строковых свойств (метод должен быть виден только для строковых свойств) - //6. Исключить из сериализации конкретного свойства + var printer = ObjectPrinter.For(); + //1. Исключить из сериализации свойства определенного типа + //2. Указать альтернативный способ сериализации для определенного типа + //3. Для числовых типов указать культуру + //4. Настроить сериализацию конкретного свойства + //5. Настроить обрезание строковых свойств (метод должен быть виден только для строковых свойств) + //6. Исключить из сериализации конкретного свойства string s1 = printer.PrintToString(person); - //7. Синтаксический сахар в виде метода расширения, сериализующего по-умолчанию - //8. ...с конфигурированием - } - } + //7. Синтаксический сахар в виде метода расширения, сериализующего по-умолчанию + //8. ...с конфигурированием + } + } } \ No newline at end of file diff --git a/ObjectPrinting/Tests/Person.cs b/ObjectPrinting/Tests/Person.cs index 4d288c57..f9555955 100644 --- a/ObjectPrinting/Tests/Person.cs +++ b/ObjectPrinting/Tests/Person.cs @@ -2,11 +2,11 @@ namespace ObjectPrinting.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; } + } } \ No newline at end of file diff --git a/Samples/Spectacle/Program.cs b/Samples/Spectacle/Program.cs index 7bdf37ab..e9900c46 100644 --- a/Samples/Spectacle/Program.cs +++ b/Samples/Spectacle/Program.cs @@ -3,20 +3,20 @@ namespace SpectacleSample { - public class Program - { - public static void Main() - { - var spectacle = new Spectacle() - .Say("Привет мир!") - .Delay(TimeSpan.FromSeconds(1)) - .UntilKeyPressed(s => - s.TypeText("тра-ля-ля") - .TypeText("тру-лю-лю") - ) - .Say("Пока-пока!"); + public class Program + { + public static void Main() + { + var spectacle = new Spectacle() + .Say("Привет мир!") + .Delay(TimeSpan.FromSeconds(1)) + .UntilKeyPressed(s => + s.TypeText("тра-ля-ля") + .TypeText("тру-лю-лю") + ) + .Say("Пока-пока!"); - spectacle.Play(); - } - } + spectacle.Play(); + } + } } \ No newline at end of file diff --git a/Samples/Spectacle/Spectacle.cs b/Samples/Spectacle/Spectacle.cs index 3a8504fd..aa7fbc75 100644 --- a/Samples/Spectacle/Spectacle.cs +++ b/Samples/Spectacle/Spectacle.cs @@ -4,47 +4,47 @@ namespace SpectacleSample { - public class Spectacle - { - private readonly List actions = new List(); + public class Spectacle + { + private readonly List actions = new List(); - public void Schedule(Action action) - { - actions.Add(action); - } + public void Schedule(Action action) + { + actions.Add(action); + } - public Spectacle Say(string message) - { - Schedule(() => Console.WriteLine(message)); - return this; - } + public Spectacle Say(string message) + { + Schedule(() => Console.WriteLine(message)); + return this; + } - public Spectacle Delay(TimeSpan timeSpan) - { - Schedule(() => Thread.Sleep(timeSpan)); - return this; - } + public Spectacle Delay(TimeSpan timeSpan) + { + Schedule(() => Thread.Sleep(timeSpan)); + return this; + } - public void Play() - { - foreach (var action in actions) - { - action(); - } - } + public void Play() + { + foreach (var action in actions) + { + action(); + } + } - public Spectacle UntilKeyPressed(Func inner) - { - var innerSpectacle = inner(new Spectacle()); - Schedule(() => - { - while (!Console.KeyAvailable) - { - innerSpectacle.Play(); - } - Console.ReadKey(true); - }); - return this; - } - } + public Spectacle UntilKeyPressed(Func inner) + { + var innerSpectacle = inner(new Spectacle()); + Schedule(() => + { + while (!Console.KeyAvailable) + { + innerSpectacle.Play(); + } + Console.ReadKey(true); + }); + return this; + } + } } \ No newline at end of file diff --git a/Samples/Spectacle/SpectacleExtensions.cs b/Samples/Spectacle/SpectacleExtensions.cs index a160ad26..24e6b740 100644 --- a/Samples/Spectacle/SpectacleExtensions.cs +++ b/Samples/Spectacle/SpectacleExtensions.cs @@ -3,20 +3,20 @@ namespace SpectacleSample { - public static class SpectacleExtensions - { - public static Spectacle TypeText(this Spectacle spectacle, string message) - { - spectacle.Schedule(() => - { - foreach (var ch in message) - { - Console.Write(ch); - Thread.Sleep(50); - } - Console.WriteLine(); - }); - return spectacle; - } - } + public static class SpectacleExtensions + { + public static Spectacle TypeText(this Spectacle spectacle, string message) + { + spectacle.Schedule(() => + { + foreach (var ch in message) + { + Console.Write(ch); + Thread.Sleep(50); + } + Console.WriteLine(); + }); + return spectacle; + } + } } \ No newline at end of file diff --git a/fluent-api.sln.DotSettings b/fluent-api.sln.DotSettings index 631637aa..135b83ec 100644 --- a/fluent-api.sln.DotSettings +++ b/fluent-api.sln.DotSettings @@ -1,3 +1,83 @@  <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /> \ No newline at end of file + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /> + True + True + Imported 10.10.2016 + NUnitTests + NUnit Test Fixture + True + getFileNameWithoutExtension() + 1 + True + 0 + True + True + 2.0 + InCSharpTypeAndNamespace + True + 2.0 + InCSharpTypeMember + tf + True + [NUnit.Framework.TestFixture] +public class $Class$_Should +{ + [NUnit.Framework.Test] + public void $DoSomething_WhenSomething$() + { + + } +} + True + True + Imported 10.10.2016 + NUnitTests + NUnit TearDown + True + True + 2.0 + InCSharpFile + td + True + [NUnit.Framework.TearDownAttribute] +public void TearDown() +{ + $END$ +} + + True + True + Imported 10.10.2016 + NUnitTests + NUnit Test + True + 0 + True + True + 2.0 + InCSharpTypeMember + tt + True + [NUnit.Framework.Test] +public void $DoSomething_WhenSomething$() +{ + $END$ +} + True + True + Imported 10.10.2016 + NUnitTests + NUnit SetUp + True + True + 2.0 + InCSharpFile + su + True + [NUnit.Framework.SetUpAttribute] +public void SetUp() +{ + $END$ +} + \ No newline at end of file