-
Notifications
You must be signed in to change notification settings - Fork 263
Шептихин Вячеслав #255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sheptikhinv
wants to merge
18
commits into
kontur-courses:master
Choose a base branch
from
sheptikhinv:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Шептихин Вячеслав #255
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
7295411
add implementation for features
sheptikhinv f2da40b
add exclude functionality in PrintToString
sheptikhinv c50077b
fix property excluding
sheptikhinv 84ed49f
implement serialization and apply some refactoring
sheptikhinv 4fced3a
add trim implementation
sheptikhinv ba0caa4
implement cultrue applying
sheptikhinv b834a6d
fix stackoverflow on cyclic references
sheptikhinv 365c1e5
update person model for test cases
sheptikhinv 1c585a5
move logic from ProjectConfig to separate classes
sheptikhinv cbaca85
remove solved directory
sheptikhinv 439a6fc
implement collections output
sheptikhinv 0511559
implement dictionary output
sheptikhinv a191238
replace a lot of Environment.NewLine with only one
sheptikhinv f56d5ff
add unit tests that suggests generated result is really what we expect
sheptikhinv e513382
refactoring: remove unused usings, add data validation in TrimAction.…
sheptikhinv 3888065
no more changing global culture, add SpecifyCultureAction.cs
sheptikhinv d7db1a9
add culture tests
sheptikhinv 2c4265d
make "Expected" path non-dependent on file system
sheptikhinv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| namespace ObjectPrinting.Actions; | ||
|
|
||
| public class ActionResult | ||
| { | ||
| public string Value { get; set; } | ||
| public bool IsSkipped { get; set; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| using System; | ||
| using System.Reflection; | ||
|
|
||
| namespace ObjectPrinting.Actions; | ||
|
|
||
| public class ExcludeAction : IAction | ||
| { | ||
| private readonly Type? typeToExclude = null; | ||
| private readonly PropertyInfo? propertyToExclude = null; | ||
|
|
||
| public ExcludeAction(Type typeToExclude) | ||
| { | ||
| this.typeToExclude = typeToExclude; | ||
| } | ||
|
|
||
| public ExcludeAction(PropertyInfo propertyToExclude) | ||
| { | ||
| this.propertyToExclude = propertyToExclude; | ||
| } | ||
|
|
||
| public bool CanHandle(PropertyInfo property) | ||
| { | ||
| return propertyToExclude != null && propertyToExclude == property || | ||
| typeToExclude != null && typeToExclude.IsAssignableFrom(property.PropertyType); | ||
| } | ||
|
|
||
| public ActionResult Handle(object value) | ||
| { | ||
| return new ActionResult | ||
| { | ||
| IsSkipped = true | ||
| }; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| using System.Reflection; | ||
|
|
||
| namespace ObjectPrinting.Actions; | ||
|
|
||
| public interface IAction | ||
| { | ||
| bool CanHandle(PropertyInfo property); | ||
| ActionResult Handle(object value); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| using System; | ||
| using System.Reflection; | ||
|
|
||
| namespace ObjectPrinting.Actions; | ||
|
|
||
| public class SerializeAction : IAction | ||
| { | ||
| private readonly Func<object, string> serializer; | ||
|
|
||
| private readonly Type? typeToSerialize = null; | ||
| private readonly PropertyInfo? propertyToSerialize = null; | ||
|
|
||
| public SerializeAction(Type typeToSerialize, Func<object, string> serializer) | ||
| { | ||
| this.typeToSerialize = typeToSerialize; | ||
| this.serializer = serializer; | ||
| } | ||
|
|
||
| public SerializeAction(PropertyInfo propertyToSerialize, Func<object, string> serializer) | ||
| { | ||
| this.propertyToSerialize = propertyToSerialize; | ||
| this.serializer = serializer; | ||
| } | ||
|
|
||
| public bool CanHandle(PropertyInfo property) | ||
| { | ||
| return propertyToSerialize != null && propertyToSerialize == property || | ||
| typeToSerialize != null && typeToSerialize.IsAssignableFrom(property.PropertyType); | ||
| } | ||
|
|
||
| public ActionResult Handle(object value) | ||
| { | ||
| return new ActionResult | ||
| { | ||
| IsSkipped = false, | ||
| Value = serializer(value) | ||
| }; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| using System; | ||
| using System.Globalization; | ||
| using System.Reflection; | ||
|
|
||
| namespace ObjectPrinting.Actions; | ||
|
|
||
| public class SpecifyCultureAction : IAction | ||
| { | ||
| private readonly Type? typeToFormat = null; | ||
| private readonly PropertyInfo? propertyToFormat = null; | ||
| private readonly CultureInfo cultureInfo; | ||
|
|
||
| public SpecifyCultureAction(Type typeToFormat, CultureInfo cultureInfo) | ||
| { | ||
| this.typeToFormat = typeToFormat; | ||
| this.cultureInfo = cultureInfo; | ||
| } | ||
|
|
||
| public SpecifyCultureAction(PropertyInfo propertyToFormat, CultureInfo cultureInfo) | ||
| { | ||
| this.propertyToFormat = propertyToFormat; | ||
| this.cultureInfo = cultureInfo; | ||
| } | ||
|
|
||
|
|
||
| public bool CanHandle(PropertyInfo property) | ||
| { | ||
| return propertyToFormat != null && propertyToFormat == property && | ||
| typeof(IFormattable).IsAssignableFrom(property.PropertyType) || | ||
| typeToFormat != null && typeToFormat.IsAssignableFrom(property.PropertyType); | ||
| } | ||
|
|
||
| public ActionResult Handle(object value) | ||
| { | ||
| return new ActionResult | ||
| { | ||
| IsSkipped = false, | ||
| Value = ((IFormattable)value).ToString(null, cultureInfo) | ||
| }; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| using System; | ||
| using System.Reflection; | ||
|
|
||
| namespace ObjectPrinting.Actions; | ||
|
|
||
| public class TrimAction : IAction | ||
| { | ||
| private readonly int maxLength; | ||
| private readonly PropertyInfo propertyToTrim; | ||
|
|
||
| public TrimAction(PropertyInfo propertyToTrim, int maxLength) | ||
| { | ||
| ArgumentOutOfRangeException.ThrowIfNegative(maxLength); | ||
|
|
||
| this.propertyToTrim = propertyToTrim; | ||
| this.maxLength = maxLength; | ||
| } | ||
|
|
||
| public bool CanHandle(PropertyInfo property) | ||
| { | ||
| return propertyToTrim == property && property.PropertyType == typeof(string); | ||
| } | ||
|
|
||
| public ActionResult Handle(object value) | ||
| { | ||
| return new ActionResult | ||
| { | ||
| IsSkipped = false, | ||
| Value = ((string)value)[..maxLength] | ||
| }; | ||
| } | ||
| } | ||
11 changes: 11 additions & 0 deletions
11
ObjectPrinting/Expected/ObjectPrinter_CustomPropertySerializer.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| Person | ||
| Id = 00000000-0000-0000-0000-000000000000 | ||
| Name = Alex | ||
| Surname = null | ||
| Height = 0 | ||
| Age = 19 years old | ||
| LastTimeOnline = 01.01.0001 0:00:00 | ||
| Father = null | ||
| Child = null | ||
| Tags = null | ||
| CustomProperties = null |
11 changes: 11 additions & 0 deletions
11
ObjectPrinting/Expected/ObjectPrinter_CustomTypeSerializer.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| Person | ||
| Id = 00000000-0000-0000-0000-000000000000 | ||
| Name = Alex - string | ||
| Surname = Brown - string | ||
| Height = 2005 | ||
| Age = 19 | ||
| LastTimeOnline = 01.01.0001 0:00:00 | ||
| Father = null | ||
| Child = null | ||
| Tags = null | ||
| CustomProperties = null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| Person | ||
| Id = 00000000-0000-0000-0000-000000000000 | ||
| Name = Alex | ||
| Surname = null | ||
| Height = 0 | ||
| LastTimeOnline = 01.01.0001 0:00:00 | ||
| Father = null | ||
| Child = null | ||
| Tags = null | ||
| CustomProperties = null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| Person | ||
| Name = Alex | ||
| Surname = null | ||
| Height = 0 | ||
| Age = 19 | ||
| LastTimeOnline = 01.01.0001 0:00:00 | ||
| Father = null | ||
| Child = null | ||
| Tags = null | ||
| CustomProperties = null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| Person | ||
| Id = 00000000-0000-0000-0000-000000000000 | ||
| Name = Alex | ||
| Surname = null | ||
| Height = 0 | ||
| Age = 19 | ||
| LastTimeOnline = 01.01.0001 0:00:00 | ||
| Father = null | ||
| Child = null | ||
| Tags = [ | ||
| [0] = tag1 | ||
| [1] = tag2 | ||
| ] | ||
| CustomProperties = null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| Person | ||
| Id = 00000000-0000-0000-0000-000000000000 | ||
| Name = Alex | ||
| Surname = null | ||
| Height = 0 | ||
| Age = 19 | ||
| LastTimeOnline = 01.01.0001 0:00:00 | ||
| Father = null | ||
| Child = null | ||
| Tags = null | ||
| CustomProperties = { | ||
| PhoneNumber = 88005553535 | ||
| HomeAddress = Novokoltsovo | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| Person | ||
| Id = 00000000-0000-0000-0000-000000000000 | ||
| Name = Alex | ||
| Surname = null | ||
| Height = 0 | ||
| Age = 19 | ||
| LastTimeOnline = 01.01.0001 0:00:00 | ||
| Father = Person | ||
| Id = 00000000-0000-0000-0000-000000000000 | ||
| Name = John | ||
| Surname = null | ||
| Height = 0 | ||
| Age = 42 | ||
| LastTimeOnline = 01.01.0001 0:00:00 | ||
| Father = null | ||
| Child = cyclic reference | ||
| Tags = null | ||
| CustomProperties = null | ||
| Child = null | ||
| Tags = null | ||
| CustomProperties = null |
11 changes: 11 additions & 0 deletions
11
ObjectPrinting/Expected/ObjectPrinter_SpecifyPropertyCulture.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| Person | ||
| Id = 00000000-0000-0000-0000-000000000000 | ||
| Name = Alex | ||
| Surname = null | ||
| Height = 185.12 | ||
| Age = 19 | ||
| LastTimeOnline = 01.01.0001 0:00:00 | ||
| Father = null | ||
| Child = null | ||
| Tags = null | ||
| CustomProperties = null |
11 changes: 11 additions & 0 deletions
11
ObjectPrinting/Expected/ObjectPrinter_SpecifyTypeCulture.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| Person | ||
| Id = 00000000-0000-0000-0000-000000000000 | ||
| Name = Alex | ||
| Surname = null | ||
| Height = 0 | ||
| Age = 19 | ||
| LastTimeOnline = 1/1/2021 12:00:00 PM | ||
| Father = null | ||
| Child = null | ||
| Tags = null | ||
| CustomProperties = null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| Person | ||
| Id = 00000000-0000-0000-0000-000000000000 | ||
| Name = Alex | ||
| Surname = VeryLongSu | ||
| Height = 0 | ||
| Age = 19 | ||
| LastTimeOnline = 01.01.0001 0:00:00 | ||
| Father = null | ||
| Child = null | ||
| Tags = null | ||
| CustomProperties = null |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.