diff --git a/.editorconfig b/.editorconfig index 0c2a84a..71746d2 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,11 +1,247 @@ root = true [*.cs] + +#### Core EditorConfig Options #### charset = utf-8 -end_of_line = lf + +# Indentation and spacing indent_size = 2 indent_style = space + +# New line preferences +end_of_line = lf insert_final_newline = true +trim_trailing_whitespace = true + +#### .NET Coding Conventions #### +dotnet_separate_import_directive_groups = false +dotnet_sort_system_directives_first = true +file_header_template = unset + +# this. and Me. preferences +dotnet_style_qualification_for_event = false +dotnet_style_qualification_for_field = false +dotnet_style_qualification_for_method = false +dotnet_style_qualification_for_property = false + +# Language keywords vs BCL types preferences +dotnet_style_predefined_type_for_locals_parameters_members = true +dotnet_style_predefined_type_for_member_access = true + +# Parentheses preferences +dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity +dotnet_style_parentheses_in_other_binary_operators = always_for_clarity +dotnet_style_parentheses_in_other_operators = never_if_unnecessary +dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity + +# Modifier preferences +dotnet_style_require_accessibility_modifiers = for_non_interface_members + +# Expression-level preferences +dotnet_style_coalesce_expression = true +dotnet_style_collection_initializer = false +dotnet_style_explicit_tuple_names = true +dotnet_style_namespace_match_folder = false +dotnet_style_null_propagation = true +dotnet_style_object_initializer = true +dotnet_style_operator_placement_when_wrapping = beginning_of_line +dotnet_style_prefer_auto_properties = true +dotnet_style_prefer_collection_expression = false +dotnet_style_prefer_compound_assignment = true +dotnet_style_prefer_conditional_expression_over_assignment = false +dotnet_style_prefer_conditional_expression_over_return = false +dotnet_style_prefer_foreach_explicit_cast_in_source = when_strongly_typed +dotnet_style_prefer_inferred_anonymous_type_member_names = true +dotnet_style_prefer_inferred_tuple_names = true +dotnet_style_prefer_is_null_check_over_reference_equality_method = true +dotnet_style_prefer_simplified_boolean_expressions = true +dotnet_style_prefer_simplified_interpolation = true + +# Field preferences +dotnet_style_readonly_field = true + +# Parameter preferences +dotnet_code_quality_unused_parameters = all:silent + +# Suppression preferences +dotnet_remove_unnecessary_suppression_exclusions = none + +# New line preferences +dotnet_style_allow_multiple_blank_lines_experimental = true +dotnet_style_allow_statement_immediately_after_block_experimental = true + +#### C# Coding Conventions #### + +# var preferences +csharp_style_var_elsewhere = false +csharp_style_var_for_built_in_types = false +csharp_style_var_when_type_is_apparent = false + +# Expression-bodied members +csharp_style_expression_bodied_accessors = true +csharp_style_expression_bodied_constructors = false +csharp_style_expression_bodied_indexers = true +csharp_style_expression_bodied_lambdas = true +csharp_style_expression_bodied_local_functions = false +csharp_style_expression_bodied_methods = when_on_single_line +csharp_style_expression_bodied_operators = false +csharp_style_expression_bodied_properties = true + +# Pattern matching preferences +csharp_style_pattern_matching_over_as_with_null_check = true +csharp_style_pattern_matching_over_is_with_cast_check = true +csharp_style_prefer_extended_property_pattern = true +csharp_style_prefer_not_pattern = true +csharp_style_prefer_pattern_matching = true +csharp_style_prefer_switch_expression = true + +# Null-checking preferences +csharp_style_conditional_delegate_call = true + +# Modifier preferences +csharp_prefer_static_local_function = true +csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async +csharp_style_prefer_readonly_struct = true +csharp_style_prefer_readonly_struct_member = true + +# Code-block preferences +csharp_prefer_braces = when_multiline +csharp_prefer_simple_using_statement = true +csharp_style_namespace_declarations = block_scoped +csharp_style_prefer_method_group_conversion = true +csharp_style_prefer_primary_constructors = false +csharp_style_prefer_top_level_statements = true + +# Expression-level preferences +csharp_prefer_simple_default_expression = true +csharp_style_deconstructed_variable_declaration = true +csharp_style_implicit_object_creation_when_type_is_apparent = false +csharp_style_inlined_variable_declaration = true +csharp_style_prefer_index_operator = true +csharp_style_prefer_local_over_anonymous_function = true +csharp_style_prefer_null_check_over_type_check = true +csharp_style_prefer_range_operator = true +csharp_style_prefer_tuple_swap = true +csharp_style_prefer_utf8_string_literals = true +csharp_style_throw_expression = true +csharp_style_unused_value_assignment_preference = discard_variable +csharp_style_unused_value_expression_statement_preference = discard_variable + +# 'using' directive preferences +csharp_using_directive_placement = outside_namespace + +# New line preferences +csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true +csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true +csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true +csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true +csharp_style_allow_embedded_statements_on_same_line_experimental = true + +#### C# Formatting Rules #### + +# New line preferences +csharp_new_line_before_catch = true +csharp_new_line_before_else = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_before_members_in_object_initializers = false +csharp_new_line_before_open_brace = all +csharp_new_line_between_query_expression_clauses = true + +# Indentation preferences +csharp_indent_block_contents = true +csharp_indent_braces = false +csharp_indent_case_contents = true +csharp_indent_case_contents_when_block = true +csharp_indent_labels = one_less_than_current +csharp_indent_switch_labels = true + +# Space preferences +csharp_space_after_cast = false +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_after_comma = true +csharp_space_after_dot = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_after_semicolon_in_for_statement = true +csharp_space_around_binary_operators = before_and_after +csharp_space_around_declaration_statements = false +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_before_comma = false +csharp_space_before_dot = false +csharp_space_before_open_square_brackets = false +csharp_space_before_semicolon_in_for_statement = false +csharp_space_between_empty_square_brackets = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_parentheses = false +csharp_space_between_square_brackets = false + +# Wrapping preferences +csharp_preserve_single_line_blocks = true +csharp_preserve_single_line_statements = true + +#### Naming styles #### + +# Naming rules + +dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion +dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface +dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i + +dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.types_should_be_pascal_case.symbols = types +dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case + +dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members +dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case + +# Symbol specifications + +dotnet_naming_symbols.interface.applicable_kinds = interface +dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.interface.required_modifiers = + +dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum +dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.types.required_modifiers = + +dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method +dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.non_field_members.required_modifiers = + +# Naming styles + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case + +dotnet_naming_style.begins_with_i.required_prefix = I +dotnet_naming_style.begins_with_i.required_suffix = +dotnet_naming_style.begins_with_i.word_separator = +dotnet_naming_style.begins_with_i.capitalization = pascal_case + +# Diagnostics +dotnet_analyzer_diagnostic.severity = warning + +dotnet_diagnostic.IDE0001.severity = none +dotnet_diagnostic.IDE0004.severity = silent +dotnet_diagnostic.IDE0005.severity = error +dotnet_diagnostic.IDE0008.severity = silent +dotnet_diagnostic.IDE0055.severity = silent +dotnet_diagnostic.IDE0160.severity = none +dotnet_diagnostic.CA1707.severity = silent +dotnet_diagnostic.CA1852.severity = none +dotnet_diagnostic.CA1805.severity = none +dotnet_diagnostic.CA1720.severity = silent +dotnet_diagnostic.CA1711.severity = silent +dotnet_diagnostic.CA1716.severity = silent [.github/**/*.yml] charset = utf-8 diff --git a/.github/workflows/tests.yml b/.github/workflows/pull-request.yml similarity index 66% rename from .github/workflows/tests.yml rename to .github/workflows/pull-request.yml index 3e0d43b..d744fce 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/pull-request.yml @@ -5,7 +5,7 @@ on: - dev jobs: - tests: + build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -19,4 +19,7 @@ jobs: run: dotnet build --no-restore src/DotTiled.sln - name: Test run: dotnet test --no-build --verbosity normal src/DotTiled.sln - \ No newline at end of file + - name: Lint style + run: dotnet format style --verify-no-changes --verbosity diagnostic src/DotTiled.sln + - name: Lint analyzers + run: dotnet format analyzers --verify-no-changes --verbosity diagnostic src/DotTiled.sln diff --git a/Makefile b/Makefile index 5e6402f..9b64573 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,22 @@ -test: - dotnet build src/DotTiled.sln - dotnet test src/DotTiled.sln - -docs-serve: - docfx docs/docfx.json --serve - -docs-build: - cp README.md docs/index.md - docfx docs/docfx.json - -BENCHMARK_SOURCES = DotTiled.Benchmark/Program.cs DotTiled.Benchmark/DotTiled.Benchmark.csproj -BENCHMARK_OUTPUTDIR = DotTiled.Benchmark/BenchmarkDotNet.Artifacts -.PHONY: benchmark -benchmark: $(BENCHMARK_OUTPUTDIR)/results/MyBenchmarks.MapLoading-report-github.md - -$(BENCHMARK_OUTPUTDIR)/results/MyBenchmarks.MapLoading-report-github.md: $(BENCHMARK_SOURCES) +test: + dotnet build src/DotTiled.sln + dotnet test src/DotTiled.sln + +docs-serve: + docfx docs/docfx.json --serve + +docs-build: + cp README.md docs/index.md + docfx docs/docfx.json + +lint: + dotnet format style --verify-no-changes src/DotTiled.sln + dotnet format analyzers --verify-no-changes src/DotTiled.sln + +BENCHMARK_SOURCES = DotTiled.Benchmark/Program.cs DotTiled.Benchmark/DotTiled.Benchmark.csproj +BENCHMARK_OUTPUTDIR = DotTiled.Benchmark/BenchmarkDotNet.Artifacts +.PHONY: benchmark +benchmark: $(BENCHMARK_OUTPUTDIR)/results/MyBenchmarks.MapLoading-report-github.md + +$(BENCHMARK_OUTPUTDIR)/results/MyBenchmarks.MapLoading-report-github.md: $(BENCHMARK_SOURCES) dotnet run --project DotTiled.Benchmark/DotTiled.Benchmark.csproj -c Release -- $(BENCHMARK_OUTPUTDIR) \ No newline at end of file diff --git a/src/DotTiled.Benchmark/Program.cs b/src/DotTiled.Benchmark/Program.cs index e04c6b1..bf67fd0 100644 --- a/src/DotTiled.Benchmark/Program.cs +++ b/src/DotTiled.Benchmark/Program.cs @@ -1,17 +1,13 @@ -using System; -using System.Collections.Immutable; using System.Runtime.CompilerServices; -using System.Security.Cryptography; using System.Text; using System.Xml; using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Columns; using BenchmarkDotNet.Configs; using BenchmarkDotNet.Order; -using BenchmarkDotNet.Reports; using BenchmarkDotNet.Running; -namespace MyBenchmarks +namespace DotTiled.Benchmark { [GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)] [CategoriesColumn] @@ -19,11 +15,11 @@ namespace MyBenchmarks [HideColumns(["StdDev", "Error", "RatioSD"])] public class MapLoading { - private string _tmxPath = @"DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.tmx"; - private string _tmxContents = ""; + private readonly string _tmxPath = @"DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.tmx"; + private readonly string _tmxContents = ""; - private string _tmjPath = @"DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.tmj"; - private string _tmjContents = ""; + private readonly string _tmjPath = @"DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.tmj"; + private readonly string _tmjContents = ""; public MapLoading() { @@ -31,11 +27,11 @@ namespace MyBenchmarks var tmxPath = Path.Combine(basePath, $"../{_tmxPath}"); var tmjPath = Path.Combine(basePath, $"../{_tmjPath}"); - _tmxContents = System.IO.File.ReadAllText(tmxPath); - _tmjContents = System.IO.File.ReadAllText(tmjPath); + _tmxContents = File.ReadAllText(tmxPath); + _tmjContents = File.ReadAllText(tmjPath); } - static string WhereAmI([CallerFilePath] string callerFilePath = "") => callerFilePath; + private static string WhereAmI([CallerFilePath] string callerFilePath = "") => callerFilePath; [BenchmarkCategory("MapFromInMemoryTmxString")] [Benchmark(Baseline = true, Description = "DotTiled")] @@ -43,7 +39,7 @@ namespace MyBenchmarks { using var stringReader = new StringReader(_tmxContents); using var xmlReader = XmlReader.Create(stringReader); - using var mapReader = new DotTiled.Serialization.Tmx.TmxMapReader(xmlReader, _ => throw new Exception(), _ => throw new Exception(), []); + using var mapReader = new DotTiled.Serialization.Tmx.TmxMapReader(xmlReader, _ => throw new NotSupportedException(), _ => throw new NotSupportedException(), []); return mapReader.ReadMap(); } @@ -51,7 +47,7 @@ namespace MyBenchmarks [Benchmark(Baseline = true, Description = "DotTiled")] public DotTiled.Model.Map LoadWithDotTiledFromInMemoryTmjString() { - using var mapReader = new DotTiled.Serialization.Tmj.TmjMapReader(_tmjContents, _ => throw new Exception(), _ => throw new Exception(), []); + using var mapReader = new DotTiled.Serialization.Tmj.TmjMapReader(_tmjContents, _ => throw new NotSupportedException(), _ => throw new NotSupportedException(), []); return mapReader.ReadMap(); } @@ -84,11 +80,11 @@ namespace MyBenchmarks { public static void Main(string[] args) { - var config = BenchmarkDotNet.Configs.DefaultConfig.Instance + var config = DefaultConfig.Instance .WithArtifactsPath(args[0]) .WithOptions(ConfigOptions.DisableOptimizationsValidator) .AddDiagnoser(BenchmarkDotNet.Diagnosers.MemoryDiagnoser.Default); - var summary = BenchmarkRunner.Run(config); + _ = BenchmarkRunner.Run(config); } } } diff --git a/src/DotTiled.Tests/Assert/AssertObject.cs b/src/DotTiled.Tests/Assert/AssertObject.cs index d982ebd..bc8e54c 100644 --- a/src/DotTiled.Tests/Assert/AssertObject.cs +++ b/src/DotTiled.Tests/Assert/AssertObject.cs @@ -24,30 +24,15 @@ public static partial class DotTiledAssert AssertObject((dynamic)expected, (dynamic)actual); } - private static void AssertObject(RectangleObject expected, RectangleObject actual) - { - Assert.True(true); // A rectangle object is the same as the abstract Object - } + private static void AssertObject(RectangleObject _, RectangleObject __) => Assert.True(true); // A rectangle object is the same as the abstract Object - private static void AssertObject(EllipseObject expected, EllipseObject actual) - { - Assert.True(true); // An ellipse object is the same as the abstract Object - } + private static void AssertObject(EllipseObject _, EllipseObject __) => Assert.True(true); // An ellipse object is the same as the abstract Object - private static void AssertObject(PointObject expected, PointObject actual) - { - Assert.True(true); // A point object is the same as the abstract Object - } + private static void AssertObject(PointObject _, PointObject __) => Assert.True(true); // A point object is the same as the abstract Object - private static void AssertObject(PolygonObject expected, PolygonObject actual) - { - AssertEqual(expected.Points, actual.Points, nameof(PolygonObject.Points)); - } + private static void AssertObject(PolygonObject expected, PolygonObject actual) => AssertEqual(expected.Points, actual.Points, nameof(PolygonObject.Points)); - private static void AssertObject(PolylineObject expected, PolylineObject actual) - { - AssertEqual(expected.Points, actual.Points, nameof(PolylineObject.Points)); - } + private static void AssertObject(PolylineObject expected, PolylineObject actual) => AssertEqual(expected.Points, actual.Points, nameof(PolylineObject.Points)); private static void AssertObject(TextObject expected, TextObject actual) { @@ -67,9 +52,5 @@ public static partial class DotTiledAssert AssertEqual(expected.Text, actual.Text, nameof(TextObject.Text)); } - private static void AssertObject(TileObject expected, TileObject actual) - { - // Attributes - AssertEqual(expected.GID, actual.GID, nameof(TileObject.GID)); - } + private static void AssertObject(TileObject expected, TileObject actual) => AssertEqual(expected.GID, actual.GID, nameof(TileObject.GID)); } diff --git a/src/DotTiled.Tests/Assert/AssertProperties.cs b/src/DotTiled.Tests/Assert/AssertProperties.cs index 16d9cdb..646d6eb 100644 --- a/src/DotTiled.Tests/Assert/AssertProperties.cs +++ b/src/DotTiled.Tests/Assert/AssertProperties.cs @@ -28,40 +28,19 @@ public static partial class DotTiledAssert AssertProperties((dynamic)actual, (dynamic)expected); } - private static void AssertProperty(StringProperty expected, StringProperty actual) - { - AssertEqual(expected.Value, actual.Value, "StringProperty.Value"); - } + private static void AssertProperty(StringProperty expected, StringProperty actual) => AssertEqual(expected.Value, actual.Value, "StringProperty.Value"); - private static void AssertProperty(IntProperty expected, IntProperty actual) - { - AssertEqual(expected.Value, actual.Value, "IntProperty.Value"); - } + private static void AssertProperty(IntProperty expected, IntProperty actual) => AssertEqual(expected.Value, actual.Value, "IntProperty.Value"); - private static void AssertProperty(FloatProperty expected, FloatProperty actual) - { - AssertEqual(expected.Value, actual.Value, "FloatProperty.Value"); - } + private static void AssertProperty(FloatProperty expected, FloatProperty actual) => AssertEqual(expected.Value, actual.Value, "FloatProperty.Value"); - private static void AssertProperty(BoolProperty expected, BoolProperty actual) - { - AssertEqual(expected.Value, actual.Value, "BoolProperty.Value"); - } + private static void AssertProperty(BoolProperty expected, BoolProperty actual) => AssertEqual(expected.Value, actual.Value, "BoolProperty.Value"); - private static void AssertProperty(ColorProperty expected, ColorProperty actual) - { - AssertEqual(expected.Value, actual.Value, "ColorProperty.Value"); - } + private static void AssertProperty(ColorProperty expected, ColorProperty actual) => AssertEqual(expected.Value, actual.Value, "ColorProperty.Value"); - private static void AssertProperty(FileProperty expected, FileProperty actual) - { - AssertEqual(expected.Value, actual.Value, "FileProperty.Value"); - } + private static void AssertProperty(FileProperty expected, FileProperty actual) => AssertEqual(expected.Value, actual.Value, "FileProperty.Value"); - private static void AssertProperty(ObjectProperty expected, ObjectProperty actual) - { - AssertEqual(expected.Value, actual.Value, "ObjectProperty.Value"); - } + private static void AssertProperty(ObjectProperty expected, ObjectProperty actual) => AssertEqual(expected.Value, actual.Value, "ObjectProperty.Value"); private static void AssertProperty(ClassProperty expected, ClassProperty actual) { diff --git a/src/DotTiled.Tests/Assert/AssertTileset.cs b/src/DotTiled.Tests/Assert/AssertTileset.cs index 3e4ab28..134cc30 100644 --- a/src/DotTiled.Tests/Assert/AssertTileset.cs +++ b/src/DotTiled.Tests/Assert/AssertTileset.cs @@ -1,5 +1,4 @@ using DotTiled.Model; -using DotTiled.Model; namespace DotTiled.Tests; diff --git a/src/DotTiled.Tests/Serialization/TestData.cs b/src/DotTiled.Tests/Serialization/TestData.cs index 30c4b9f..f6e49b5 100644 --- a/src/DotTiled.Tests/Serialization/TestData.cs +++ b/src/DotTiled.Tests/Serialization/TestData.cs @@ -1,6 +1,5 @@ using System.Xml; using DotTiled.Model; -using DotTiled.Model; namespace DotTiled.Tests; @@ -33,49 +32,14 @@ public static partial class TestData public static IEnumerable MapTests => [ - ["Serialization/TestData/Map/default_map/default-map", (string f) => TestData.DefaultMap(), Array.Empty()], - ["Serialization/TestData/Map/map_with_common_props/map-with-common-props", (string f) => TestData.MapWithCommonProps(), Array.Empty()], - ["Serialization/TestData/Map/map_with_custom_type_props/map-with-custom-type-props", (string f) => TestData.MapWithCustomTypeProps(), TestData.MapWithCustomTypePropsCustomTypeDefinitions()], - ["Serialization/TestData/Map/map_with_embedded_tileset/map-with-embedded-tileset", (string f) => TestData.MapWithEmbeddedTileset(), Array.Empty()], - ["Serialization/TestData/Map/map_with_external_tileset/map-with-external-tileset", (string f) => TestData.MapWithExternalTileset(f), Array.Empty()], - ["Serialization/TestData/Map/map_with_flippingflags/map-with-flippingflags", (string f) => TestData.MapWithFlippingFlags(f), Array.Empty()], - ["Serialization/TestData/Map/map_external_tileset_multi/map-external-tileset-multi", (string f) => TestData.MapExternalTilesetMulti(f), Array.Empty()], - ["Serialization/TestData/Map/map_external_tileset_wangset/map-external-tileset-wangset", (string f) => TestData.MapExternalTilesetWangset(f), Array.Empty()], - ["Serialization/TestData/Map/map_with_many_layers/map-with-many-layers", (string f) => TestData.MapWithManyLayers(f), Array.Empty()], - ]; - - private static CustomTypeDefinition[] typedefs = [ - new CustomClassDefinition - { - Name = "TestClass", - ID = 1, - UseAs = CustomClassUseAs.Property, - Members = [ - new StringProperty - { - Name = "Name", - Value = "" - }, - new FloatProperty - { - Name = "Amount", - Value = 0f - } - ] - }, - new CustomClassDefinition - { - Name = "Test", - ID = 2, - UseAs = CustomClassUseAs.All, - Members = [ - new ClassProperty - { - Name = "Yep", - PropertyType = "TestClass", - Properties = [] - } - ] - } + ["Serialization/TestData/Map/default_map/default-map", (string f) => DefaultMap(), Array.Empty()], + ["Serialization/TestData/Map/map_with_common_props/map-with-common-props", (string f) => MapWithCommonProps(), Array.Empty()], + ["Serialization/TestData/Map/map_with_custom_type_props/map-with-custom-type-props", (string f) => MapWithCustomTypeProps(), MapWithCustomTypePropsCustomTypeDefinitions()], + ["Serialization/TestData/Map/map_with_embedded_tileset/map-with-embedded-tileset", (string f) => MapWithEmbeddedTileset(), Array.Empty()], + ["Serialization/TestData/Map/map_with_external_tileset/map-with-external-tileset", (string f) => MapWithExternalTileset(f), Array.Empty()], + ["Serialization/TestData/Map/map_with_flippingflags/map-with-flippingflags", (string f) => MapWithFlippingFlags(f), Array.Empty()], + ["Serialization/TestData/Map/map_external_tileset_multi/map-external-tileset-multi", (string f) => MapExternalTilesetMulti(f), Array.Empty()], + ["Serialization/TestData/Map/map_external_tileset_wangset/map-external-tileset-wangset", (string f) => MapExternalTilesetWangset(f), Array.Empty()], + ["Serialization/TestData/Map/map_with_many_layers/map-with-many-layers", (string f) => MapWithManyLayers(f), Array.Empty()], ]; } diff --git a/src/DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.cs b/src/DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.cs index 4eef6de..da726bf 100644 --- a/src/DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.cs +++ b/src/DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.cs @@ -1,5 +1,4 @@ using DotTiled.Model; -using DotTiled.Model; namespace DotTiled.Tests; diff --git a/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-multi/map-external-tileset-multi.cs b/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-multi/map-external-tileset-multi.cs index 04c425a..6dac137 100644 --- a/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-multi/map-external-tileset-multi.cs +++ b/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-multi/map-external-tileset-multi.cs @@ -1,8 +1,5 @@ using System.Globalization; using DotTiled.Model; -using DotTiled.Model; -using DotTiled.Model; -using DotTiled.Model; namespace DotTiled.Tests; diff --git a/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-wangset/map-external-tileset-wangset.cs b/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-wangset/map-external-tileset-wangset.cs index a894a53..2e4bd61 100644 --- a/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-wangset/map-external-tileset-wangset.cs +++ b/src/DotTiled.Tests/Serialization/TestData/Map/map-external-tileset-wangset/map-external-tileset-wangset.cs @@ -1,7 +1,5 @@ using System.Globalization; using DotTiled.Model; -using DotTiled.Model; -using DotTiled.Model; namespace DotTiled.Tests; diff --git a/src/DotTiled.Tests/Serialization/TestData/Map/map-with-common-props/map-with-common-props.cs b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-common-props/map-with-common-props.cs index 14f95ac..ba5cf4f 100644 --- a/src/DotTiled.Tests/Serialization/TestData/Map/map-with-common-props/map-with-common-props.cs +++ b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-common-props/map-with-common-props.cs @@ -1,7 +1,5 @@ using System.Globalization; using DotTiled.Model; -using DotTiled.Model; -using DotTiled.Model; namespace DotTiled.Tests; diff --git a/src/DotTiled.Tests/Serialization/TestData/Map/map-with-custom-type-props/map-with-custom-type-props.cs b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-custom-type-props/map-with-custom-type-props.cs index e7d135c..758c5c3 100644 --- a/src/DotTiled.Tests/Serialization/TestData/Map/map-with-custom-type-props/map-with-custom-type-props.cs +++ b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-custom-type-props/map-with-custom-type-props.cs @@ -1,8 +1,5 @@ using System.Globalization; using DotTiled.Model; -using DotTiled.Model; -using DotTiled.Model; -using DotTiled.Model; namespace DotTiled.Tests; diff --git a/src/DotTiled.Tests/Serialization/TestData/Map/map-with-embedded-tileset/map-with-embedded-tileset.cs b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-embedded-tileset/map-with-embedded-tileset.cs index e9c4e73..863dc75 100644 --- a/src/DotTiled.Tests/Serialization/TestData/Map/map-with-embedded-tileset/map-with-embedded-tileset.cs +++ b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-embedded-tileset/map-with-embedded-tileset.cs @@ -1,7 +1,5 @@ using System.Globalization; using DotTiled.Model; -using DotTiled.Model; -using DotTiled.Model; namespace DotTiled.Tests; diff --git a/src/DotTiled.Tests/Serialization/TestData/Map/map-with-external-tileset/map-with-external-tileset.cs b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-external-tileset/map-with-external-tileset.cs index 055a0c9..3682b73 100644 --- a/src/DotTiled.Tests/Serialization/TestData/Map/map-with-external-tileset/map-with-external-tileset.cs +++ b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-external-tileset/map-with-external-tileset.cs @@ -1,7 +1,5 @@ using System.Globalization; using DotTiled.Model; -using DotTiled.Model; -using DotTiled.Model; namespace DotTiled.Tests; diff --git a/src/DotTiled.Tests/Serialization/TestData/Map/map-with-flippingflags/map-with-flippingflags.cs b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-flippingflags/map-with-flippingflags.cs index 96995d7..02a9fc5 100644 --- a/src/DotTiled.Tests/Serialization/TestData/Map/map-with-flippingflags/map-with-flippingflags.cs +++ b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-flippingflags/map-with-flippingflags.cs @@ -1,7 +1,5 @@ using System.Globalization; using DotTiled.Model; -using DotTiled.Model; -using DotTiled.Model; namespace DotTiled.Tests; diff --git a/src/DotTiled.Tests/Serialization/TestData/Map/map-with-many-layers/map-with-many-layers.cs b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-many-layers/map-with-many-layers.cs index 320fa48..6e4ae55 100644 --- a/src/DotTiled.Tests/Serialization/TestData/Map/map-with-many-layers/map-with-many-layers.cs +++ b/src/DotTiled.Tests/Serialization/TestData/Map/map-with-many-layers/map-with-many-layers.cs @@ -1,9 +1,5 @@ using System.Numerics; using DotTiled.Model; -using DotTiled.Model; -using DotTiled.Model; -using DotTiled.Model; -using DotTiled.Model; namespace DotTiled.Tests; diff --git a/src/DotTiled.Tests/Serialization/Tmj/TmjMapReaderTests.cs b/src/DotTiled.Tests/Serialization/Tmj/TmjMapReaderTests.cs index a856f68..bdd19e8 100644 --- a/src/DotTiled.Tests/Serialization/Tmj/TmjMapReaderTests.cs +++ b/src/DotTiled.Tests/Serialization/Tmj/TmjMapReaderTests.cs @@ -1,6 +1,4 @@ using DotTiled.Model; -using DotTiled.Model; -using DotTiled.Model; using DotTiled.Serialization.Tmj; namespace DotTiled.Tests; diff --git a/src/DotTiled.Tests/Serialization/Tmx/TmxMapReaderTests.cs b/src/DotTiled.Tests/Serialization/Tmx/TmxMapReaderTests.cs index 6a26b62..ee74718 100644 --- a/src/DotTiled.Tests/Serialization/Tmx/TmxMapReaderTests.cs +++ b/src/DotTiled.Tests/Serialization/Tmx/TmxMapReaderTests.cs @@ -1,6 +1,3 @@ -using System.Xml; -using DotTiled.Model; -using DotTiled.Model; using DotTiled.Model; using DotTiled.Serialization.Tmx; diff --git a/src/DotTiled/Model/Color.cs b/src/DotTiled/Model/Color.cs index 24cf8e5..7de0ab0 100644 --- a/src/DotTiled/Model/Color.cs +++ b/src/DotTiled/Model/Color.cs @@ -1,7 +1,6 @@ using System; using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Threading; namespace DotTiled.Model; @@ -40,7 +39,7 @@ public class Color : IParsable, IEquatable /// Thrown in case the provided string is not in a valid format. public static Color Parse(string s, IFormatProvider? provider) { - TryParse(s, provider, out var result); + _ = TryParse(s, provider, out var result); return result ?? throw new FormatException($"Invalid format for TiledColor: {s}"); } @@ -61,7 +60,7 @@ public class Color : IParsable, IEquatable return TryParse($"#{s}", provider, out result); // Format: #RRGGBB or #AARRGGBB - if (s is null || s.Length != 7 && s.Length != 9 || s[0] != '#') + if (s is null || (s.Length != 7 && s.Length != 9) || s[0] != '#') { result = default; return false; diff --git a/src/DotTiled/Serialization/Helpers.cs b/src/DotTiled/Serialization/Helpers.cs index fe401ba..c6cdefe 100644 --- a/src/DotTiled/Serialization/Helpers.cs +++ b/src/DotTiled/Serialization/Helpers.cs @@ -4,8 +4,6 @@ using System.IO; using System.IO.Compression; using System.Linq; using DotTiled.Model; -using DotTiled.Model; -using DotTiled.Model; namespace DotTiled.Serialization; diff --git a/src/DotTiled/Serialization/Tmj/Tmj.Data.cs b/src/DotTiled/Serialization/Tmj/Tmj.Data.cs index 2edb93f..c021a6c 100644 --- a/src/DotTiled/Serialization/Tmj/Tmj.Data.cs +++ b/src/DotTiled/Serialization/Tmj/Tmj.Data.cs @@ -1,9 +1,5 @@ using System; -using System.Collections.Generic; -using System.Globalization; using System.IO; -using System.IO.Compression; -using System.Linq; using System.Text.Json; using DotTiled.Model; @@ -69,7 +65,8 @@ internal partial class Tmj { DataCompression.GZip => Helpers.DecompressGZip(stream), DataCompression.ZLib => Helpers.DecompressZLib(stream), - _ => throw new JsonException($"Unsupported compression '{compression}'.") + DataCompression.ZStd => throw new NotSupportedException("ZStd compression is not supported."), + _ => throw new InvalidOperationException($"Unsupported compression '{compression}'.") }; { diff --git a/src/DotTiled/Serialization/Tmj/Tmj.Group.cs b/src/DotTiled/Serialization/Tmj/Tmj.Group.cs index 796458b..0885167 100644 --- a/src/DotTiled/Serialization/Tmj/Tmj.Group.cs +++ b/src/DotTiled/Serialization/Tmj/Tmj.Group.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Globalization; -using System.Numerics; using System.Text.Json; using DotTiled.Model; diff --git a/src/DotTiled/Serialization/Tmj/Tmj.ImageLayer.cs b/src/DotTiled/Serialization/Tmj/Tmj.ImageLayer.cs index 70d9ce4..794f2b5 100644 --- a/src/DotTiled/Serialization/Tmj/Tmj.ImageLayer.cs +++ b/src/DotTiled/Serialization/Tmj/Tmj.ImageLayer.cs @@ -1,10 +1,7 @@ -using System; using System.Collections.Generic; using System.Globalization; -using System.Numerics; using System.Text.Json; using DotTiled.Model; -using DotTiled.Model; namespace DotTiled.Serialization.Tmj; diff --git a/src/DotTiled/Serialization/Tmj/Tmj.Layer.cs b/src/DotTiled/Serialization/Tmj/Tmj.Layer.cs index fb02fe5..b9f8de0 100644 --- a/src/DotTiled/Serialization/Tmj/Tmj.Layer.cs +++ b/src/DotTiled/Serialization/Tmj/Tmj.Layer.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.Globalization; -using System.Numerics; using System.Text.Json; using DotTiled.Model; diff --git a/src/DotTiled/Serialization/Tmj/Tmj.Map.cs b/src/DotTiled/Serialization/Tmj/Tmj.Map.cs index 642d8f4..47dde3f 100644 --- a/src/DotTiled/Serialization/Tmj/Tmj.Map.cs +++ b/src/DotTiled/Serialization/Tmj/Tmj.Map.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; using System.Globalization; -using System.IO; -using System.Linq; using System.Text.Json; using DotTiled.Model; diff --git a/src/DotTiled/Serialization/Tmj/Tmj.ObjectLayer.cs b/src/DotTiled/Serialization/Tmj/Tmj.ObjectLayer.cs index ba01791..6775389 100644 --- a/src/DotTiled/Serialization/Tmj/Tmj.ObjectLayer.cs +++ b/src/DotTiled/Serialization/Tmj/Tmj.ObjectLayer.cs @@ -112,8 +112,8 @@ internal partial class Tmj var id = element.GetOptionalProperty("id", idDefault); var name = element.GetOptionalProperty("name", nameDefault); var point = element.GetOptionalProperty("point", pointDefault); - var polygon = element.GetOptionalPropertyCustom?>("polygon", e => ReadPoints(e), polygonDefault); - var polyline = element.GetOptionalPropertyCustom?>("polyline", e => ReadPoints(e), polylineDefault); + var polygon = element.GetOptionalPropertyCustom?>("polygon", ReadPoints, polygonDefault); + var polyline = element.GetOptionalPropertyCustom?>("polyline", ReadPoints, polylineDefault); var properties = element.GetOptionalPropertyCustom?>("properties", e => ReadProperties(e, customTypeDefinitions), propertiesDefault); var rotation = element.GetOptionalProperty("rotation", rotationDefault); var text = element.GetOptionalPropertyCustom("text", ReadText, null); @@ -249,12 +249,12 @@ internal partial class Tmj } internal static List ReadPoints(JsonElement element) => - element.GetValueAsList(e => - { - var x = e.GetRequiredProperty("x"); - var y = e.GetRequiredProperty("y"); - return new Vector2(x, y); - }); + element.GetValueAsList(e => + { + var x = e.GetRequiredProperty("x"); + var y = e.GetRequiredProperty("y"); + return new Vector2(x, y); + }); internal static TextObject ReadText(JsonElement element) { diff --git a/src/DotTiled/Serialization/Tmj/Tmj.Properties.cs b/src/DotTiled/Serialization/Tmj/Tmj.Properties.cs index 28aad66..0c35bbe 100644 --- a/src/DotTiled/Serialization/Tmj/Tmj.Properties.cs +++ b/src/DotTiled/Serialization/Tmj/Tmj.Properties.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Globalization; -using System.IO; using System.Linq; using System.Text.Json; using DotTiled.Model; @@ -102,8 +101,6 @@ internal partial class Tmj return resultingProps; } - internal static Dictionary CreateInstanceOfCustomClass(CustomClassDefinition customClassDefinition) - { - return customClassDefinition.Members.ToDictionary(m => m.Name, m => m.Clone()); - } + internal static Dictionary CreateInstanceOfCustomClass(CustomClassDefinition customClassDefinition) => + customClassDefinition.Members.ToDictionary(m => m.Name, m => m.Clone()); } diff --git a/src/DotTiled/Serialization/Tmj/Tmj.Template.cs b/src/DotTiled/Serialization/Tmj/Tmj.Template.cs index 100aaa2..3746b76 100644 --- a/src/DotTiled/Serialization/Tmj/Tmj.Template.cs +++ b/src/DotTiled/Serialization/Tmj/Tmj.Template.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.Globalization; -using System.Numerics; using System.Text.Json; using DotTiled.Model; diff --git a/src/DotTiled/Serialization/Tmj/Tmj.TileLayer.cs b/src/DotTiled/Serialization/Tmj/Tmj.TileLayer.cs index 3711eb2..353f7fd 100644 --- a/src/DotTiled/Serialization/Tmj/Tmj.TileLayer.cs +++ b/src/DotTiled/Serialization/Tmj/Tmj.TileLayer.cs @@ -1,7 +1,5 @@ -using System; using System.Collections.Generic; using System.Globalization; -using System.Numerics; using System.Text.Json; using DotTiled.Model; diff --git a/src/DotTiled/Serialization/Tmj/Tmj.Tileset.cs b/src/DotTiled/Serialization/Tmj/Tmj.Tileset.cs index 0d6dfc7..e0e2bd2 100644 --- a/src/DotTiled/Serialization/Tmj/Tmj.Tileset.cs +++ b/src/DotTiled/Serialization/Tmj/Tmj.Tileset.cs @@ -1,9 +1,6 @@ using System; using System.Collections.Generic; using System.Globalization; -using System.IO; -using System.IO.Compression; -using System.Linq; using System.Text.Json; using DotTiled.Model; diff --git a/src/DotTiled/Serialization/Tmj/TmjMapReader.cs b/src/DotTiled/Serialization/Tmj/TmjMapReader.cs index 8e5ddd4..c26311b 100644 --- a/src/DotTiled/Serialization/Tmj/TmjMapReader.cs +++ b/src/DotTiled/Serialization/Tmj/TmjMapReader.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.IO; -using System.Text; using System.Text.Json; using DotTiled.Model; @@ -16,7 +14,7 @@ public class TmjMapReader : IMapReader private readonly Func _externalTilesetResolver; private readonly Func _externalTemplateResolver; - private string _jsonString; + private readonly string _jsonString; private bool disposedValue; private readonly IReadOnlyCollection _customTypeDefinitions; @@ -77,6 +75,6 @@ public class TmjMapReader : IMapReader { // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method Dispose(disposing: true); - System.GC.SuppressFinalize(this); + GC.SuppressFinalize(this); } } diff --git a/src/DotTiled/Serialization/Tmj/TsjTilesetReader.cs b/src/DotTiled/Serialization/Tmj/TsjTilesetReader.cs index 84ec60e..aca5556 100644 --- a/src/DotTiled/Serialization/Tmj/TsjTilesetReader.cs +++ b/src/DotTiled/Serialization/Tmj/TsjTilesetReader.cs @@ -74,6 +74,6 @@ public class TsjTilesetReader : ITilesetReader { // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method Dispose(disposing: true); - System.GC.SuppressFinalize(this); + GC.SuppressFinalize(this); } } diff --git a/src/DotTiled/Serialization/Tmx/ExtensionsXmlReader.cs b/src/DotTiled/Serialization/Tmx/ExtensionsXmlReader.cs index ca5f836..9a8f1d9 100644 --- a/src/DotTiled/Serialization/Tmx/ExtensionsXmlReader.cs +++ b/src/DotTiled/Serialization/Tmx/ExtensionsXmlReader.cs @@ -31,10 +31,8 @@ internal static class ExtensionsXmlReader return enumParser(value); } - internal static string? GetOptionalAttribute(this XmlReader reader, string attribute, string? defaultValue = default) - { - return reader.GetAttribute(attribute) ?? defaultValue; - } + internal static string? GetOptionalAttribute(this XmlReader reader, string attribute, string? defaultValue = default) => + reader.GetAttribute(attribute) ?? defaultValue; internal static T? GetOptionalAttributeParseable(this XmlReader reader, string attribute) where T : struct, IParsable { @@ -84,7 +82,7 @@ internal static class ExtensionsXmlReader if (reader.NodeType == XmlNodeType.EndElement) continue; // At end of list, no need to read again - reader.Read(); + _ = reader.Read(); } reader.ReadEndElement(); @@ -135,6 +133,6 @@ internal static class ExtensionsXmlReader internal static void SkipXmlDeclaration(this XmlReader reader) { if (reader.NodeType == XmlNodeType.XmlDeclaration) - reader.Read(); + _ = reader.Read(); } } diff --git a/src/DotTiled/Serialization/Tmx/Tmx.Data.cs b/src/DotTiled/Serialization/Tmx/Tmx.Data.cs index 77f7d6a..e1b6111 100644 --- a/src/DotTiled/Serialization/Tmx/Tmx.Data.cs +++ b/src/DotTiled/Serialization/Tmx/Tmx.Data.cs @@ -62,10 +62,8 @@ internal partial class Tmx return (clearedGlobalTileIDs, flippingFlags); } - internal static uint[] ReadTileChildrenInWrapper(string wrapper, XmlReader reader) - { - return reader.ReadList(wrapper, "tile", (r) => r.GetOptionalAttributeParseable("gid") ?? 0).ToArray(); - } + internal static uint[] ReadTileChildrenInWrapper(string wrapper, XmlReader reader) => + reader.ReadList(wrapper, "tile", (r) => r.GetOptionalAttributeParseable("gid") ?? 0).ToArray(); internal static uint[] ReadRawData(XmlReader reader, DataEncoding encoding, DataCompression? compression) { diff --git a/src/DotTiled/Serialization/Tmx/Tmx.Map.cs b/src/DotTiled/Serialization/Tmx/Tmx.Map.cs index e7a5e35..1987bb1 100644 --- a/src/DotTiled/Serialization/Tmx/Tmx.Map.cs +++ b/src/DotTiled/Serialization/Tmx/Tmx.Map.cs @@ -25,7 +25,7 @@ internal partial class Tmx "isometric" => MapOrientation.Isometric, "staggered" => MapOrientation.Staggered, "hexagonal" => MapOrientation.Hexagonal, - _ => throw new Exception($"Unknown orientation '{s}'") + _ => throw new InvalidOperationException($"Unknown orientation '{s}'") }); var renderOrder = reader.GetOptionalAttributeEnum("renderorder", s => s switch { @@ -33,7 +33,7 @@ internal partial class Tmx "right-up" => RenderOrder.RightUp, "left-down" => RenderOrder.LeftDown, "left-up" => RenderOrder.LeftUp, - _ => throw new Exception($"Unknown render order '{s}'") + _ => throw new InvalidOperationException($"Unknown render order '{s}'") }) ?? RenderOrder.RightDown; var compressionLevel = reader.GetOptionalAttributeParseable("compressionlevel") ?? -1; var width = reader.GetRequiredAttributeParseable("width"); @@ -45,13 +45,13 @@ internal partial class Tmx { "x" => StaggerAxis.X, "y" => StaggerAxis.Y, - _ => throw new Exception($"Unknown stagger axis '{s}'") + _ => throw new InvalidOperationException($"Unknown stagger axis '{s}'") }); var staggerIndex = reader.GetOptionalAttributeEnum("staggerindex", s => s switch { "odd" => StaggerIndex.Odd, "even" => StaggerIndex.Even, - _ => throw new Exception($"Unknown stagger index '{s}'") + _ => throw new InvalidOperationException($"Unknown stagger index '{s}'") }); var parallaxOriginX = reader.GetOptionalAttributeParseable("parallaxoriginx") ?? 0.0f; var parallaxOriginY = reader.GetOptionalAttributeParseable("parallaxoriginy") ?? 0.0f; diff --git a/src/DotTiled/Serialization/Tmx/Tmx.ObjectLayer.cs b/src/DotTiled/Serialization/Tmx/Tmx.ObjectLayer.cs index 7c04edf..7a375d9 100644 --- a/src/DotTiled/Serialization/Tmx/Tmx.ObjectLayer.cs +++ b/src/DotTiled/Serialization/Tmx/Tmx.ObjectLayer.cs @@ -35,7 +35,7 @@ internal partial class Tmx { "topdown" => DrawOrder.TopDown, "index" => DrawOrder.Index, - _ => throw new Exception($"Unknown draw order '{s}'") + _ => throw new InvalidOperationException($"Unknown draw order '{s}'") }) ?? DrawOrder.TopDown; // Elements @@ -119,7 +119,7 @@ internal partial class Tmx "polygon" => () => Helpers.SetAtMostOnce(ref foundObject, ReadPolygonObject(r), "Object marker"), "polyline" => () => Helpers.SetAtMostOnce(ref foundObject, ReadPolylineObject(r), "Object marker"), "text" => () => Helpers.SetAtMostOnce(ref foundObject, ReadTextObject(r), "Object marker"), - _ => throw new Exception($"Unknown object marker '{elementName}'") + _ => throw new InvalidOperationException($"Unknown object marker '{elementName}'") }); if (foundObject is null) @@ -175,7 +175,7 @@ internal partial class Tmx return new EllipseObject { }; } - internal static EllipseObject OverrideObject(EllipseObject obj, EllipseObject foundObject) => obj; + internal static EllipseObject OverrideObject(EllipseObject obj, EllipseObject _) => obj; internal static PointObject ReadPointObject(XmlReader reader) { @@ -183,7 +183,7 @@ internal partial class Tmx return new PointObject { }; } - internal static PointObject OverrideObject(PointObject obj, PointObject foundObject) => obj; + internal static PointObject OverrideObject(PointObject obj, PointObject _) => obj; internal static PolygonObject ReadPolygonObject(XmlReader reader) { @@ -251,14 +251,14 @@ internal partial class Tmx "center" => TextHorizontalAlignment.Center, "right" => TextHorizontalAlignment.Right, "justify" => TextHorizontalAlignment.Justify, - _ => throw new Exception($"Unknown horizontal alignment '{s}'") + _ => throw new InvalidOperationException($"Unknown horizontal alignment '{s}'") }) ?? TextHorizontalAlignment.Left; var vAlign = reader.GetOptionalAttributeEnum("valign", s => s switch { "top" => TextVerticalAlignment.Top, "center" => TextVerticalAlignment.Center, "bottom" => TextVerticalAlignment.Bottom, - _ => throw new Exception($"Unknown vertical alignment '{s}'") + _ => throw new InvalidOperationException($"Unknown vertical alignment '{s}'") }) ?? TextVerticalAlignment.Top; // Elements diff --git a/src/DotTiled/Serialization/Tmx/Tmx.Properties.cs b/src/DotTiled/Serialization/Tmx/Tmx.Properties.cs index 3d5b6c4..9a748d6 100644 --- a/src/DotTiled/Serialization/Tmx/Tmx.Properties.cs +++ b/src/DotTiled/Serialization/Tmx/Tmx.Properties.cs @@ -66,8 +66,6 @@ internal partial class Tmx throw new XmlException($"Unkonwn custom class definition: {propertyType}"); } - internal static Dictionary CreateInstanceOfCustomClass(CustomClassDefinition customClassDefinition) - { - return customClassDefinition.Members.ToDictionary(m => m.Name, m => m.Clone()); - } + internal static Dictionary CreateInstanceOfCustomClass(CustomClassDefinition customClassDefinition) => + customClassDefinition.Members.ToDictionary(m => m.Name, m => m.Clone()); } diff --git a/src/DotTiled/Serialization/Tmx/Tmx.Tileset.cs b/src/DotTiled/Serialization/Tmx/Tmx.Tileset.cs index 6e43455..198f32d 100644 --- a/src/DotTiled/Serialization/Tmx/Tmx.Tileset.cs +++ b/src/DotTiled/Serialization/Tmx/Tmx.Tileset.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; using System.Xml; @@ -40,19 +41,19 @@ internal partial class Tmx "bottomleft" => ObjectAlignment.BottomLeft, "bottom" => ObjectAlignment.Bottom, "bottomright" => ObjectAlignment.BottomRight, - _ => throw new Exception($"Unknown object alignment '{s}'") + _ => throw new InvalidOperationException($"Unknown object alignment '{s}'") }) ?? ObjectAlignment.Unspecified; var renderSize = reader.GetOptionalAttributeEnum("rendersize", s => s switch { "tile" => TileRenderSize.Tile, "grid" => TileRenderSize.Grid, - _ => throw new Exception($"Unknown render size '{s}'") + _ => throw new InvalidOperationException($"Unknown render size '{s}'") }) ?? TileRenderSize.Tile; var fillMode = reader.GetOptionalAttributeEnum("fillmode", s => s switch { "stretch" => FillMode.Stretch, "preserve-aspect-fit" => FillMode.PreserveAspectFit, - _ => throw new Exception($"Unknown fill mode '{s}'") + _ => throw new InvalidOperationException($"Unknown fill mode '{s}'") }) ?? FillMode.Stretch; // Elements @@ -124,7 +125,7 @@ internal partial class Tmx "jpg" => ImageFormat.Jpg, "bmp" => ImageFormat.Bmp, "gif" => ImageFormat.Gif, - _ => throw new Exception($"Unknown image format '{s}'") + _ => throw new InvalidOperationException($"Unknown image format '{s}'") }); var source = reader.GetOptionalAttribute("source"); var transparentColor = reader.GetOptionalAttributeClass("trans"); @@ -182,7 +183,7 @@ internal partial class Tmx { "orthogonal" => GridOrientation.Orthogonal, "isometric" => GridOrientation.Isometric, - _ => throw new Exception($"Unknown orientation '{s}'") + _ => throw new InvalidOperationException($"Unknown orientation '{s}'") }) ?? GridOrientation.Orthogonal; var width = reader.GetRequiredAttributeParseable("width"); var height = reader.GetRequiredAttributeParseable("height"); @@ -255,10 +256,8 @@ internal partial class Tmx internal static List ReadWangsets( XmlReader reader, - IReadOnlyCollection customTypeDefinitions) - { - return reader.ReadList("wangsets", "wangset", r => ReadWangset(r, customTypeDefinitions)); - } + IReadOnlyCollection customTypeDefinitions) => + reader.ReadList("wangsets", "wangset", r => ReadWangset(r, customTypeDefinitions)); internal static Wangset ReadWangset( XmlReader reader, @@ -334,7 +333,7 @@ internal partial class Tmx var wangID = reader.GetRequiredAttributeParseable("wangid", s => { // Comma-separated list of indices (0-254) - var indices = s.Split(',').Select(i => byte.Parse(i)).ToArray(); + var indices = s.Split(',').Select(i => byte.Parse(i, CultureInfo.InvariantCulture)).ToArray(); if (indices.Length > 8) throw new ArgumentException("Wang ID can have at most 8 indices."); return indices; diff --git a/src/DotTiled/Serialization/Tmx/TmxMapReader.cs b/src/DotTiled/Serialization/Tmx/TmxMapReader.cs index be21580..5a99ff6 100644 --- a/src/DotTiled/Serialization/Tmx/TmxMapReader.cs +++ b/src/DotTiled/Serialization/Tmx/TmxMapReader.cs @@ -39,14 +39,11 @@ public class TmxMapReader : IMapReader _customTypeDefinitions = customTypeDefinitions ?? throw new ArgumentNullException(nameof(customTypeDefinitions)); // Prepare reader - _reader.MoveToContent(); + _ = _reader.MoveToContent(); } /// - public Map ReadMap() - { - return Tmx.ReadMap(_reader, _externalTilesetResolver, _externalTemplateResolver, _customTypeDefinitions); - } + public Map ReadMap() => Tmx.ReadMap(_reader, _externalTilesetResolver, _externalTemplateResolver, _customTypeDefinitions); /// protected virtual void Dispose(bool disposing) @@ -77,6 +74,6 @@ public class TmxMapReader : IMapReader { // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method Dispose(disposing: true); - System.GC.SuppressFinalize(this); + GC.SuppressFinalize(this); } } diff --git a/src/DotTiled/Serialization/Tmx/TsxTilesetReader.cs b/src/DotTiled/Serialization/Tmx/TsxTilesetReader.cs index 374a0d1..0034150 100644 --- a/src/DotTiled/Serialization/Tmx/TsxTilesetReader.cs +++ b/src/DotTiled/Serialization/Tmx/TsxTilesetReader.cs @@ -35,7 +35,7 @@ public class TsxTilesetReader : ITilesetReader _customTypeDefinitions = customTypeDefinitions ?? throw new ArgumentNullException(nameof(customTypeDefinitions)); // Prepare reader - _reader.MoveToContent(); + _ = _reader.MoveToContent(); } /// @@ -49,6 +49,7 @@ public class TsxTilesetReader : ITilesetReader if (disposing) { // TODO: dispose managed state (managed objects) + _reader.Dispose(); } // TODO: free unmanaged resources (unmanaged objects) and override finalizer @@ -69,6 +70,6 @@ public class TsxTilesetReader : ITilesetReader { // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method Dispose(disposing: true); - System.GC.SuppressFinalize(this); + GC.SuppressFinalize(this); } } diff --git a/src/DotTiled/Serialization/Tmx/TxTemplateReader.cs b/src/DotTiled/Serialization/Tmx/TxTemplateReader.cs index fe93244..fbaf85c 100644 --- a/src/DotTiled/Serialization/Tmx/TxTemplateReader.cs +++ b/src/DotTiled/Serialization/Tmx/TxTemplateReader.cs @@ -39,7 +39,7 @@ public class TxTemplateReader : ITemplateReader _customTypeDefinitions = customTypeDefinitions ?? throw new ArgumentNullException(nameof(customTypeDefinitions)); // Prepare reader - _reader.MoveToContent(); + _ = _reader.MoveToContent(); } /// @@ -53,6 +53,7 @@ public class TxTemplateReader : ITemplateReader if (disposing) { // TODO: dispose managed state (managed objects) + _reader.Dispose(); } // TODO: free unmanaged resources (unmanaged objects) and override finalizer @@ -73,6 +74,6 @@ public class TxTemplateReader : ITemplateReader { // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method Dispose(disposing: true); - System.GC.SuppressFinalize(this); + GC.SuppressFinalize(this); } }