diff --git a/.editorconfig b/.editorconfig
index 71746d2..8e747e9 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -235,6 +235,7 @@ dotnet_diagnostic.IDE0004.severity = silent
dotnet_diagnostic.IDE0005.severity = error
dotnet_diagnostic.IDE0008.severity = silent
dotnet_diagnostic.IDE0055.severity = silent
+dotnet_diagnostic.IDE0058.severity = silent
dotnet_diagnostic.IDE0160.severity = none
dotnet_diagnostic.CA1707.severity = silent
dotnet_diagnostic.CA1852.severity = none
@@ -243,7 +244,7 @@ dotnet_diagnostic.CA1720.severity = silent
dotnet_diagnostic.CA1711.severity = silent
dotnet_diagnostic.CA1716.severity = silent
-[.github/**/*.yml]
+[*.(yml|json|js)]
charset = utf-8
end_of_line = lf
indent_size = 2
diff --git a/.github/pull_request_template/dev_template.md b/.github/pull_request_template/dev_template.md
new file mode 100644
index 0000000..128b591
--- /dev/null
+++ b/.github/pull_request_template/dev_template.md
@@ -0,0 +1,15 @@
+## Description
+
+
+### Type of Change
+
+- [ ] Bug fix (non-breaking change which fixes an issue)
+- [ ] New feature (non-breaking change which adds functionality)
+- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
+- [ ] Documentation update
+
+## Checklist
+
+- [ ] Tests have been added/updated to cover new functionality.
+- [ ] Documentation has been updated for all new changes (e.g., usage examples, API documentation).
+
diff --git a/.github/pull_request_template/master_template.md b/.github/pull_request_template/master_template.md
new file mode 100644
index 0000000..28ba2d5
--- /dev/null
+++ b/.github/pull_request_template/master_template.md
@@ -0,0 +1,10 @@
+# Release vX.Y.Z
+
+
+
+## Checklist for a release PR
+
+- [ ] Version compatibility matrix has been updated.
+- [ ] Tests have been added/updated to cover new functionality.
+- [ ] Documentation has been updated for all new changes (e.g., usage examples, API documentation).
+
diff --git a/Makefile b/Makefile
index 601eda2..f7382f5 100644
--- a/Makefile
+++ b/Makefile
@@ -2,13 +2,15 @@ test:
dotnet build src/DotTiled.sln
dotnet test src/DotTiled.sln
-docs-serve:
+docs-serve: docs/index.md
docfx docs/docfx.json --serve
-docs-build:
- cp README.md docs/index.md
+docs-build: docs/index.md
docfx docs/docfx.json
+docs/index.md:
+ cp README.md docs/index.md
+
lint:
dotnet format style --verify-no-changes src/DotTiled.sln
dotnet format analyzers --verify-no-changes src/DotTiled.sln
diff --git a/README.md b/README.md
index 8739d03..6d9de13 100644
--- a/README.md
+++ b/README.md
@@ -16,10 +16,10 @@ Other similar libraries exist, and you may want to consider them for your projec
|**Comparison**|**DotTiled**|[TiledLib](https://github.com/Ragath/TiledLib.Net)|[TiledCSPlus](https://github.com/nolemretaWxd/TiledCSPlus)|[TiledSharp](https://github.com/marshallward/TiledSharp)|[TiledCS](https://github.com/TheBoneJarmer/TiledCS)|[TiledNet](https://github.com/napen123/Tiled.Net)|
|---------------------------------|:-----------------------:|:--------:|:-----------:|:----------:|:-------:|:------:|
-| Actively maintained | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
+| Actively maintained | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
| Benchmark (time)* | 1.00 | 1.83 | 2.16 | - | - | - |
| Benchmark (memory)* | 1.00 | 1.43 | 2.03 | - | - | - |
-| .NET Targets | `net8.0` |`net6.0` `net7.0`|`netstandard2.1`|`netstandard2.0`|`netstandard2.0`|`net45`|
+| .NET Targets | `net8.0` | `net8.0` |`netstandard2.1`|`netstandard2.0`|`netstandard2.0`|`net45`|
| Docs |Usage, API, XML Docs|Usage|Usage, API, XML Docs|Usage, API|Usage, XML Docs|Usage, XML Docs|
| License | MIT | MIT | MIT | Apache-2.0 | MIT | BSD 3-Clause |
diff --git a/docs/docfx.json b/docs/docfx.json
index 4c955cb..744755c 100644
--- a/docs/docfx.json
+++ b/docs/docfx.json
@@ -41,7 +41,10 @@
"_appName": "DotTiled",
"_appTitle": "DotTiled",
"_enableSearch": true,
- "pdf": true
- }
+ "pdf": false
+ },
+ "xref": [
+ "https://learn.microsoft.com/en-us/dotnet/.xrefmap.json"
+ ]
}
}
\ No newline at end of file
diff --git a/docs/docs/essentials/custom-properties.md b/docs/docs/essentials/custom-properties.md
index b18ba7f..9fc19aa 100644
--- a/docs/docs/essentials/custom-properties.md
+++ b/docs/docs/essentials/custom-properties.md
@@ -66,11 +66,14 @@ Tiled supports a variety of property types, which are represented in the DotTile
- `object` -
- `string` -
-In addition to these primitive property types, [Tiled also supports more complex property types](https://doc.mapeditor.org/en/stable/manual/custom-properties/#custom-types). These custom property types are defined in Tiled according to the linked documentation, and to work with them in DotTiled, you *must* define their equivalences as a . You must then provide a resolving function to a defined type given a custom type name, as it is defined in Tiled.
+In addition to these primitive property types, [Tiled also supports more complex property types](https://doc.mapeditor.org/en/stable/manual/custom-properties/#custom-types). These custom property types are defined in Tiled according to the linked documentation, and to work with them in DotTiled, you *must* define their equivalences as a . This is because of how Tiled handles default values for custom property types, and DotTiled needs to know these defaults to be able to populate the properties correctly.
## Custom types
-Tiled allows you to define custom property types that can be used in your maps. These custom property types can be of type `class` or `enum`. DotTiled supports custom property types by allowing you to define the equivalent in C# and then providing a custom type resolver function that will return the equivalent definition given a custom type name.
+Tiled allows you to define custom property types that can be used in your maps. These custom property types can be of type `class` or `enum`. DotTiled supports custom property types by allowing you to define the equivalent in C#. This section will guide you through how to define custom property types in DotTiled and how to map properties in loaded maps to C# classes or enums.
+
+> [!NOTE]
+> In the future, DotTiled could provide a way to configure the use of custom property types such that they aren't necessary to be defined, given that you have set the `Resolve object types and properties` setting in Tiled.
### Class properties
@@ -88,14 +91,39 @@ var monsterSpawnerDefinition = new CustomClassDefinition
Name = "MonsterSpawner",
UseAs = CustomClassUseAs.All, // Not really validated by DotTiled
Members = [ // Make sure that the default values match the Tiled UI
- new BoolProperty { Name = "enabled", Value = true },
- new IntProperty { Name = "maxSpawnAmount", Value = 10 },
- new IntProperty { Name = "minSpawnAmount", Value = 0 },
- new StringProperty { Name = "monsterNames", Value = "" }
+ new BoolProperty { Name = "Enabled", Value = true },
+ new IntProperty { Name = "MaxSpawnAmount", Value = 10 },
+ new IntProperty { Name = "MinSpawnAmount", Value = 0 },
+ new StringProperty { Name = "MonsterNames", Value = "" }
]
};
```
+Luckily, you don't have to manually define these custom class definitions, even though you most definitively can for scenarios that require it. DotTiled provides a way to automatically generate these definitions for you from a C# class. This is done by using the method, or one of its overloads. This method will generate a from a given C# class, and you can then use this definition when loading your maps.
+
+```csharp
+class MonsterSpawner
+{
+ public bool Enabled { get; set; } = true;
+ public int MaxSpawnAmount { get; set; } = 10;
+ public int MinSpawnAmount { get; set; } = 0;
+ public string MonsterNames { get; set; } = "";
+}
+
+// ...
+
+// These are all valid ways to create your custom class definitions from a C# class
+// The first two require the class to have a default, parameterless constructor
+var monsterSpawnerDefinition1 = CustomClassDefinition.FromClass();
+var monsterSpawnerDefinition2 = CustomClassDefinition.FromClass(typeof(MonsterSpawner));
+var monsterSpawnerDefinition3 = CustomClassDefinition.FromClass(() => new MonsterSpawner
+{
+ Enabled = false // This will use the property values in the instance created by a factory method as the default values
+});
+```
+
+The last one is especially useful if you have classes that may not have parameterless constructors, or if you want to provide custom default values for the properties. Finally, the generated custom class definition will be identical to the one defined manually in the first example.
+
### Enum properties
Tiled also allows you to define custom property types that work as enums. Similarly to `class` properties, you must define the equivalent in DotTiled as a . You can then return the corresponding definition in the resolving function.
@@ -110,7 +138,7 @@ The equivalent definition in DotTiled would look like the following:
var entityTypeDefinition = new CustomEnumDefinition
{
Name = "EntityType",
- StorageType = CustomEnumStorageType.String,
+ StorageType = CustomEnumStorageType.Int,
ValueAsFlags = false,
Values = [
"Bomb",
@@ -121,23 +149,9 @@ var entityTypeDefinition = new CustomEnumDefinition
};
```
-### [Future] Automatically map custom property `class` types to C# classes
-
-In the future, DotTiled will support automatically mapping custom property `class` types to C# classes. This will allow you to define a C# class that matches the structure of the `class` property in Tiled, and DotTiled will automatically map the properties of the `class` property to the properties of the C# class. This will make working with `class` properties much easier and more intuitive.
-
-The idea is to expand on the interface with a method like `GetMappedProperty(string propertyName)`, where `T` is a class that matches the structure of the `class` property in Tiled.
-
-This functionality would be accompanied by a way to automatically create a matching given a C# class or enum. Something like this would then be possible:
+Similarly to custom class definitions, you can also automatically generate custom enum definitions from C# enums. This is done by using the method, or one of its overloads. This method will generate a from a given C# enum, and you can then use this definition when loading your maps.
```csharp
-class MonsterSpawner
-{
- public bool Enabled { get; set; } = true;
- public int MaxSpawnAmount { get; set; } = 10;
- public int MinSpawnAmount { get; set; } = 0;
- public string MonsterNames { get; set; } = "";
-}
-
enum EntityType
{
Bomb,
@@ -146,16 +160,89 @@ enum EntityType
Chair
}
-var monsterSpawnerDefinition = CustomClassDefinition.FromClass();
-var entityTypeDefinition = CustomEnumDefinition.FromEnum();
-
// ...
-var map = LoadMap();
-var monsterSpawner = map.GetMappedProperty("monsterSpawnerPropertyInMap");
-var entityType = map.GetMappedProperty("entityTypePropertyInMap");
+// These are both valid ways to create your custom enum definitions from a C# enum
+var entityTypeDefinition1 = CustomEnumDefinition.FromEnum();
+var entityTypeDefinition2 = CustomEnumDefinition.FromEnum(typeof(EntityType));
```
-Finally, it might be possible to also make some kind of exporting functionality for . Given a collection of custom type definitions, DotTiled could generate a corresponding `propertytypes.json` file that you then can import into Tiled. This would make it so that you only have to define your custom property types once (in C#) and then import them into Tiled to use them in your maps.
+The generated custom enum definition will be identical to the one defined manually in the first example.
-Depending on implementation this might become something that can inhibit native AOT compilation due to potential reflection usage. Source generators could be used to mitigate this, but it is not yet clear how this will be implemented.
\ No newline at end of file
+For enum definitions, the can be used to indicate that the enum should be treated as a flags enum. This will make it so the enum definition will have `ValueAsFlags = true` and the enum values will be treated as flags when working with them in DotTiled.
+
+## Mapping properties to C# classes or enums
+
+So far, we have only discussed how to define custom property types in DotTiled, and why they are needed. However, the most important part is how you can map properties inside your maps to their corresponding C# classes or enums.
+
+The interface has two overloads of the method. These methods allow you to map a collection of properties to a given C# class. Let's look at an example:
+
+```csharp
+// Define a few Tiled compatible custom types
+enum EntityType
+{
+ Player,
+ Enemy,
+ Collectible,
+ Explosive
+}
+
+class EntityData
+{
+ public EntityType Type { get; set; } = EntityType.Player;
+ public int Health { get; set; } = 100;
+ public string Name { get; set; } = "Unnamed Entity";
+}
+
+var entityTypeDef = CustomEnumDefinition.FromEnum();
+var entityDataDef = CustomClassDefinition.FromClass();
+```
+
+The above gives us two custom type definitions that we can supply to our map loader. Given a map that looks like this:
+
+```xml
+
+
+```
+
+We can see that there is an ellipse object in the map that has the type `EntityData` and it has set the three properties to some value other than their defaults. After having loaded this map, we can map the properties of the object to the `EntityData` class like this:
+
+```csharp
+var map = LoadMap([entityTypeDef, entityDataDef]); // Load the map somehow, using DotTiled.Loader or similar
+
+// Retrieve the object layer from the map in some way
+var objectLayer = map.Layers.Skip(1).First() as ObjectLayer;
+
+// Retrieve the object from the object layer
+var entityObject = objectLayer.Objects.First();
+
+// Map the properties of the object to the EntityData class
+var entityData = entityObject.MapPropertiesTo();
+```
+
+The above snippet will map the properties of the object to the `EntityData` class using reflection based on the property names. The `entityData` object will now have the properties set to the values found in the object in the map. If a property is not found in the object, the default value of the property in the `EntityData` class will be used. It will even map the nested enum to its corresponding value in C#. This will work for several levels of depth as it performs this kind of mapping recursively. only supports mapping to classes that have a default, parameterless constructor.
+
+### [Future] Exporting custom types
+
+It might be possible to also make some kind of exporting functionality for . Given a collection of custom type definitions, DotTiled could generate a corresponding `propertytypes.json` file that you then can import into Tiled. This would make it so that you only have to define your custom property types once (in C#) and then import them into Tiled to use them in your maps.
\ No newline at end of file
diff --git a/docs/docs/essentials/loading-maps.md b/docs/docs/essentials/loading-maps.md
index b34b964..d262ec9 100644
--- a/docs/docs/essentials/loading-maps.md
+++ b/docs/docs/essentials/loading-maps.md
@@ -1,15 +1,92 @@
# Loading maps
-Loading maps with DotTiled is straightforward and easy. The class is a representation of a Tiled map, mimicking the structure of a Tiled map file. Map files can either be in the [`.tmx`/XML](https://doc.mapeditor.org/en/stable/reference/tmx-map-format/) or [`.tmj`/json](https://doc.mapeditor.org/en/stable/reference/json-map-format/) format. DotTiled supports **both** formats fully.
+Loading maps with DotTiled is very flexible and allows you as a developer to freely choose how you want to load your maps and tilesets. This guide will show you how to customize the loading process to fit your needs. As the tip below suggests, you can also use the quickstart guide if you just want to load maps from the filesystem without any particular customization.
-> [!NOTE]
-> Using the `.tmj` file format will result in not having the same amount of information as for the `.tmx` format. This is due to the fact that the `.tmj` format does not include the full information that the `.tmx` format does. This is not a problem with DotTiled, but rather a limitation of the `.tmj` format.
+> [!TIP]
+> For a quick and easy way to load maps from the filesystem, please refer to the [quickstart guide](../quickstart.md).
-## External resolution
+## File format caveats
-Tiled maps may consist of several external files, such as tilesets or object templates. In Tiled map files, they are typically referenced by their path relative to the map file. It would be annoying to have to first load all these external resources before loading a map (which is how some other similar libraries work), so loading a map with DotTiled is designed in a way that you only have to provide a function that resolves these external resources. This way, DotTiled will figure out which external resources are needed and will invoke the corresponding resolver function to load them.
+The class is a representation of a Tiled map, mimicking the structure of a Tiled XML map file. Map files can either be in the [`.tmx`/XML](https://doc.mapeditor.org/en/stable/reference/tmx-map-format/) or [`.tmj`/json](https://doc.mapeditor.org/en/stable/reference/json-map-format/) format. DotTiled supports **both** formats fully.
-Loading a map, tileset, or template will require you to specify **three** resolver functions. We'll go through each of them below.
+> [!WARNING]
+> Using the `.tmj` file format will result in (the source image for image layers) not having the same amount of information as for the `.tmx` format. This is due to the fact that the `.tmj` format does not include the full information that the `.tmx` format does. This is not a problem with DotTiled, but rather a limitation of the `.tmj` format.
+
+## The process of loading a map
+
+Loading a map with DotTiled is not a complex process, but one that at least demands a basic understanding of how Tiled maps are structured. The process can be broken down into the following flow(-ish) chart:
+
+```mermaid
+flowchart LR
+ Z{{Loading a map
+ with DotTiled}} --> A
+
+ subgraph Parsing map
+ A[(Read map)] --> B(Parse map)
+ end
+
+ subgraph Parsing tileset
+ B -.->|References
+ external tileset| C[(Read tileset)]
+ C --> D(Parse tileset) --o|Store in map| B
+ end
+
+ subgraph Parsing template
+ B -.->|References external
+ template in object| E[(Read template)]
+ E --> F(Parse template) --o|Use as template
+ for object| B
+ end
+
+ F -.-> |References
+ external tileset| C
+ F -.-> |References
+ external template| E
+```
+
+As you can see, the process is quite simple. You read the map, parse it, and then read and parse any external tilesets or templates that are referenced in the map. The tilesets and templates are then stored in the map object that is returned to you.
+
+However, because DotTiled works in the way that it does, you will need to provide a way to resolve these external resources. We'll go through how to do that in the next section.
+
+## Loading a map with
+
+When using , external resources like tilesets and templates will be resolved by the loader itself. Since Tiled saves the external resource paths relative to the map file, the loader will automatically resolve these paths and use the provided to read the external resources. Therefore, as long as the external resources are accessible in a "relative path" way using the provided , you don't have to worry about resolving them yourself.
+
+```xml
+
+
+```
+
+A map like the one above that is loaded by the following code will result in the loader calling `IResourceReader.Read("path/to/tileset.tsx")` to read the external tileset, since it will use the path relative to the map file to resolve the tileset.
+
+```csharp
+var loader = Loader.Default();
+var map = loader.LoadMap("path/to/map.tmx");
+```
+
+Additionally, the loader will use an in-memory cache to avoid loading the same tileset or template multiple times. This is done using the that is provided to the loader. If you don't provide a cache, the loader will use the by default.
+
+## Loading a map manually with
+
+While it is recommended to use the class to perform the loading of maps and tilesets, you may have certain requirements that necessitate you to load maps in a more manual way. This section will guide you through how to load a map manually without the use of the provided loader.
+
+### , , and
+
+are the three classes that you will use to read the map, tileset, and template, respectively. They are designed to be used in a way that you can provide your own resolver functions to load external resources.
+
+> [!IMPORTANT]
+> The resolving functions will get the source path of the external resource as a parameter, *in the exact way it is written in the map file*. You will have to perform your own path resolution to load the external resources.
### `Func` - Tileset resolver
@@ -38,17 +115,17 @@ Tileset ResolveTileset(string source)
### `Func` - Template resolver
-This function is used to resolve external object templates by their source path. The function should return a instance given the source path of the template. If you just want to load templates from the file system, you can use something very similar to the tileset resolver by replacing with .
+This function is used to resolve external object templates by their source path. The function should return a instance given the source path of the template. If you just want to load templates from the file system, you can use something very similar to the example tileset resolver by replacing with .
-### `Func` - Custom type resolver
+### `Func` - Custom type resolver
-This function is used to resolve custom types that are defined in Tiled maps. Please refer to the [custom properties](custom-properties.md) documentation for more information on custom types. The function should return a instance given the custom type's name.
+This function is used to resolve custom types that are defined in your Tiled maps. Please refer to the [custom properties](custom-properties.md) documentation for more information on custom types. The function should return a instance given the custom type's name.
## Putting it all together
The following classes are the readers that you will need to use to read the map, tileset, and template: , , and .
-Here is an example of how you can load a map with DotTiled:
+Here is an example of how you can load a map with DotTiled, and is very similar to how the class works:
```csharp
string mapPath = "path/to/map.tmx";
diff --git a/docs/docs/essentials/representation-model.md b/docs/docs/essentials/representation-model.md
new file mode 100644
index 0000000..88dbdff
--- /dev/null
+++ b/docs/docs/essentials/representation-model.md
@@ -0,0 +1,17 @@
+# Representation model
+
+Tiled map files contain various types of data, such as tilesets, layers, and object groups. The representation model is a way to represent this data in a structured way. By using the `.tmx` file format as inspiration, the representation model is a collection of classes which mimic the structure of a Tiled map file.
+
+Certain properties throughout the representation model are marked as *optional* by being either wrapped in a or by having a set default value.
+
+- Properties that make use of the [required](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/required) keyword must be present in the file, otherwise an error will be raised.
+- Properties that have default values will use the default value if the property is not present in the file, and are not marked as required or optional since you must not provide a value for them.
+- Properties that are wrapped in may or may not be present in the file, and have no default value.
+
+## Version compatibility
+
+The representation model is designed to be compatible with the latest version of Tiled. This means that it may not be able to read files from older versions of Tiled, or files that use features that are not yet supported by the representation model. However, here is a table of which versions of Tiled are supported by which versions of DotTiled.
+
+| Tiled version | Compatible DotTiled version(s) |
+|---------------|--------------------------------|
+| 1.11 | 0.1.0, 0.2.0 |
\ No newline at end of file
diff --git a/docs/docs/quickstart.md b/docs/docs/quickstart.md
index 8d067eb..c43031b 100644
--- a/docs/docs/quickstart.md
+++ b/docs/docs/quickstart.md
@@ -6,41 +6,64 @@ Install DotTiled from NuGet:
dotnet add package DotTiled
```
-Load a map from file system:
+Use the `DotTiled` namespace (if you want).
```csharp
-string mapPath = "path/to/map.tmx";
-string mapDirectory = Path.GetDirectoryName(mapPath);
-
-Tileset ResolveTileset(string source)
-{
- string tilesetPath = Path.Combine(mapDirectory, source);
- using var tilesetFileReader = new StreamReader(tilesetPath);
- var tilesetString = tilesetReader.ReadToEnd();
- using var tilesetReader = new TilesetReader(tilesetString, ResolveTileset, ResolveTemplate, ResolveCustomType);
- return tilesetReader.ReadTileset();
-}
-
-Template ResolveTemplate(string source)
-{
- string templatePath = Path.Combine(mapDirectory, source);
- using var templateFileReader = new StreamReader(templatePath);
- var templateString = templateReader.ReadToEnd();
- using var templateReader = new TemplateReader(templateString, ResolveTileset, ResolveTemplate, ResolveCustomType);
- return templateReader.ReadTemplate();
-}
-
-ICustomTypeDefinition ResolveCustomType(string name)
-{
- var allDefinedTypes = [ ... ];
- return allDefinedTypes.FirstOrDefault(type => type.Name == name);
-}
-
-using var mapFileReader = new StreamReader(mapPath);
-var mapString = mapFileReader.ReadToEnd();
-using var mapReader = new MapReader(mapString, ResolveTileset, ResolveTemplate, ResolveCustomType);
-
-var map = mapReader.ReadMap();
+using DotTiled;
```
-If the above looks intimidating, don't worry! DotTiled is designed to be flexible and allow you to load maps from any source, such as a database or a custom file format. The above example is just one way to load a map from a file system. Please look at [Loading Maps](essentials/loading-maps.md) for more information on how to load maps from different sources.
\ No newline at end of file
+Or fully qualify all `DotTiled` types e.g. `DotTiled.Loader`.
+
+## Loading a map from the file system
+
+This will create a loader that will load files from the underlying file system using . It will also be configured to use an in-memory cache to avoid loading the same tileset or template multiple times using .
+
+```csharp
+var loader = Loader.Default();
+var map = loader.LoadMap("path/to/map.tmx");
+```
+
+## Loading a map from a different source
+
+If you want to load resources (maps, tilesets, templates) from a different source than the underlying file system, you can override the that is being used with your own implementation of .
+
+```csharp
+var loader = Loader.DefaultWith(
+ resourceReader: new MyCustomResourceReader());
+var map = loader.LoadMap("path/to/map.tmx");
+```
+
+## Caching resources
+
+Similarly, you can override the that is being used with your own implementation of .
+
+```csharp
+var loader = Loader.DefaultWith(
+ resourceReader: new MyCustomResourceReader(),
+ resourceCache: new MyCustomResourceCache());
+var map = loader.LoadMap("path/to/map.tmx");
+```
+
+## Custom types
+
+If you have custom types in your map, you can provide any `IEnumerable` to the loader. This will allow the loader to deserialize the custom types in your map.
+
+```csharp
+var monsterSpawnerDef = new CustomClassDefinition { ... };
+var chestDef = new CustomClassDefinition
+{
+ Name = "Chest",
+ UseAs = CustomClassUseAs.All,
+ Members = [
+ new IntProperty { Name = "coins", Value = 0 },
+ new BoolProperty { Name = "locked", Value = true }
+ ]
+};
+
+var loader = Loader.DefaultWith(
+ customTypeDefinitions: [monsterSpawnerDef, chestDef]);
+var map = loader.LoadMap("path/to/map.tmx");
+
+var chest = map.GetProperty("chest").Value;
+var coinsToSpawn = chest.GetProperty("coins").Value;
+```
\ No newline at end of file
diff --git a/docs/docs/toc.yml b/docs/docs/toc.yml
index 6a04547..5b190b8 100644
--- a/docs/docs/toc.yml
+++ b/docs/docs/toc.yml
@@ -4,4 +4,5 @@
- name: Essentials
- href: essentials/loading-maps.md
+- href: essentials/representation-model.md
- href: essentials/custom-properties.md
\ No newline at end of file
diff --git a/docs/template/public/main.js b/docs/template/public/main.js
new file mode 100644
index 0000000..7ab60f9
--- /dev/null
+++ b/docs/template/public/main.js
@@ -0,0 +1,9 @@
+export default {
+ iconLinks: [
+ {
+ icon: 'github',
+ href: 'https://github.com/dcronqvist/DotTiled',
+ title: 'GitHub'
+ }
+ ]
+}
\ No newline at end of file
diff --git a/src/DotTiled.Tests/Assert/AssertCustomTypes.cs b/src/DotTiled.Tests/Assert/AssertCustomTypes.cs
new file mode 100644
index 0000000..19eae5b
--- /dev/null
+++ b/src/DotTiled.Tests/Assert/AssertCustomTypes.cs
@@ -0,0 +1,23 @@
+namespace DotTiled.Tests;
+
+public static partial class DotTiledAssert
+{
+ internal static void AssertCustomClassDefinitionEqual(CustomClassDefinition expected, CustomClassDefinition actual)
+ {
+ AssertEqual(expected.ID, actual.ID, nameof(CustomClassDefinition.ID));
+ AssertEqual(expected.Name, actual.Name, nameof(CustomClassDefinition.Name));
+ AssertEqual(expected.Color, actual.Color, nameof(CustomClassDefinition.Color));
+ AssertEqual(expected.DrawFill, actual.DrawFill, nameof(CustomClassDefinition.DrawFill));
+ AssertEqual(expected.UseAs, actual.UseAs, nameof(CustomClassDefinition.UseAs));
+ AssertProperties(expected.Members, actual.Members);
+ }
+
+ internal static void AssertCustomEnumDefinitionEqual(CustomEnumDefinition expected, CustomEnumDefinition actual)
+ {
+ AssertEqual(expected.ID, actual.ID, nameof(CustomEnumDefinition.ID));
+ AssertEqual(expected.Name, actual.Name, nameof(CustomEnumDefinition.Name));
+ AssertEqual(expected.StorageType, actual.StorageType, nameof(CustomEnumDefinition.StorageType));
+ AssertEqual(expected.ValueAsFlags, actual.ValueAsFlags, nameof(CustomEnumDefinition.ValueAsFlags));
+ AssertListOrdered(expected.Values, actual.Values, nameof(CustomEnumDefinition.Values));
+ }
+}
diff --git a/src/DotTiled.Tests/Assert/AssertData.cs b/src/DotTiled.Tests/Assert/AssertData.cs
index 31ffff2..6e8aaa2 100644
--- a/src/DotTiled.Tests/Assert/AssertData.cs
+++ b/src/DotTiled.Tests/Assert/AssertData.cs
@@ -2,7 +2,7 @@ namespace DotTiled.Tests;
public static partial class DotTiledAssert
{
- internal static void AssertData(Data? expected, Data? actual)
+ internal static void AssertData(Data expected, Data actual)
{
if (expected is null)
{
@@ -18,14 +18,7 @@ public static partial class DotTiledAssert
// Data
AssertEqual(expected.GlobalTileIDs, actual.GlobalTileIDs, nameof(Data.GlobalTileIDs));
AssertEqual(expected.FlippingFlags, actual.FlippingFlags, nameof(Data.FlippingFlags));
-
- if (expected.Chunks is not null)
- {
- Assert.NotNull(actual.Chunks);
- AssertEqual(expected.Chunks.Length, actual.Chunks.Length, "Chunks.Length");
- for (var i = 0; i < expected.Chunks.Length; i++)
- AssertChunk(expected.Chunks[i], actual.Chunks[i]);
- }
+ AssertOptionalsEqual(expected.Chunks, actual.Chunks, nameof(Data.Chunks), (a, b) => AssertListOrdered(a, b, nameof(Chunk), AssertChunk));
}
private static void AssertChunk(Chunk expected, Chunk actual)
diff --git a/src/DotTiled.Tests/Assert/AssertImage.cs b/src/DotTiled.Tests/Assert/AssertImage.cs
index a674faa..6bb5f4e 100644
--- a/src/DotTiled.Tests/Assert/AssertImage.cs
+++ b/src/DotTiled.Tests/Assert/AssertImage.cs
@@ -2,7 +2,7 @@ namespace DotTiled.Tests;
public static partial class DotTiledAssert
{
- internal static void AssertImage(Image? expected, Image? actual)
+ internal static void AssertImage(Image expected, Image actual)
{
if (expected is null)
{
diff --git a/src/DotTiled.Tests/Assert/AssertLayer.cs b/src/DotTiled.Tests/Assert/AssertLayer.cs
index 5432d62..7dc8011 100644
--- a/src/DotTiled.Tests/Assert/AssertLayer.cs
+++ b/src/DotTiled.Tests/Assert/AssertLayer.cs
@@ -2,7 +2,7 @@ namespace DotTiled.Tests;
public static partial class DotTiledAssert
{
- internal static void AssertLayer(BaseLayer? expected, BaseLayer? actual)
+ internal static void AssertLayer(BaseLayer expected, BaseLayer actual)
{
if (expected is null)
{
diff --git a/src/DotTiled.Tests/Assert/AssertMap.cs b/src/DotTiled.Tests/Assert/AssertMap.cs
index 0110f51..bc87002 100644
--- a/src/DotTiled.Tests/Assert/AssertMap.cs
+++ b/src/DotTiled.Tests/Assert/AssertMap.cs
@@ -5,7 +5,69 @@ namespace DotTiled.Tests;
public static partial class DotTiledAssert
{
- private static void AssertEqual(T expected, T actual, string nameof)
+ internal static void AssertListOrdered(IList expected, IList actual, string nameof, Action assertEqual = null)
+ {
+ if (expected is null)
+ {
+ Assert.Null(actual);
+ return;
+ }
+
+ Assert.NotNull(actual);
+ AssertEqual(expected.Count, actual.Count, $"{nameof}.Count");
+
+ for (var i = 0; i < expected.Count; i++)
+ {
+ if (assertEqual is not null)
+ {
+ assertEqual(expected[i], actual[i]);
+ continue;
+ }
+ AssertEqual(expected[i], actual[i], $"{nameof}[{i}]");
+ }
+ }
+
+ internal static void AssertOptionalsEqual(
+ Optional expected,
+ Optional actual,
+ string nameof,
+ Action assertEqual)
+ {
+ if (expected is null)
+ {
+ Assert.Null(actual);
+ return;
+ }
+
+ if (expected.HasValue)
+ {
+ Assert.True(actual.HasValue, $"Expected {nameof} to have a value");
+ assertEqual(expected.Value, actual.Value);
+ return;
+ }
+
+ Assert.False(actual.HasValue, $"Expected {nameof} to not have a value");
+ }
+
+ internal static void AssertEqual(Optional expected, Optional actual, string nameof)
+ {
+ if (expected is null)
+ {
+ Assert.Null(actual);
+ return;
+ }
+
+ if (expected.HasValue)
+ {
+ Assert.True(actual.HasValue, $"Expected {nameof} to have a value");
+ AssertEqual(expected.Value, actual.Value, nameof);
+ return;
+ }
+
+ Assert.False(actual.HasValue, $"Expected {nameof} to not have a value");
+ }
+
+ internal static void AssertEqual(T expected, T actual, string nameof)
{
if (expected == null)
{
diff --git a/src/DotTiled.Tests/Assert/AssertProperties.cs b/src/DotTiled.Tests/Assert/AssertProperties.cs
index 843d8d0..9454486 100644
--- a/src/DotTiled.Tests/Assert/AssertProperties.cs
+++ b/src/DotTiled.Tests/Assert/AssertProperties.cs
@@ -2,7 +2,7 @@ namespace DotTiled.Tests;
public static partial class DotTiledAssert
{
- internal static void AssertProperties(IList? expected, IList? actual)
+ internal static void AssertProperties(IList expected, IList actual)
{
if (expected is null)
{
diff --git a/src/DotTiled.Tests/Assert/AssertTileset.cs b/src/DotTiled.Tests/Assert/AssertTileset.cs
index 4646a85..607b542 100644
--- a/src/DotTiled.Tests/Assert/AssertTileset.cs
+++ b/src/DotTiled.Tests/Assert/AssertTileset.cs
@@ -4,7 +4,6 @@ public static partial class DotTiledAssert
{
internal static void AssertTileset(Tileset expected, Tileset actual)
{
- // Attributes
AssertEqual(expected.Version, actual.Version, nameof(Tileset.Version));
AssertEqual(expected.TiledVersion, actual.TiledVersion, nameof(Tileset.TiledVersion));
AssertEqual(expected.FirstGID, actual.FirstGID, nameof(Tileset.FirstGID));
@@ -21,29 +20,16 @@ public static partial class DotTiledAssert
AssertEqual(expected.RenderSize, actual.RenderSize, nameof(Tileset.RenderSize));
AssertEqual(expected.FillMode, actual.FillMode, nameof(Tileset.FillMode));
- // At most one of
- AssertImage(expected.Image, actual.Image);
- AssertTileOffset(expected.TileOffset, actual.TileOffset);
- AssertGrid(expected.Grid, actual.Grid);
+ AssertOptionalsEqual(expected.Image, actual.Image, nameof(Tileset.Image), AssertImage);
+ AssertOptionalsEqual(expected.TileOffset, actual.TileOffset, nameof(Tileset.TileOffset), AssertTileOffset);
+ AssertOptionalsEqual(expected.Grid, actual.Grid, nameof(Tileset.Grid), AssertGrid);
AssertProperties(expected.Properties, actual.Properties);
- // TODO: AssertTerrainTypes(actual.TerrainTypes, expected.TerrainTypes);
- if (expected.Wangsets is not null)
- {
- Assert.NotNull(actual.Wangsets);
- AssertEqual(expected.Wangsets.Count, actual.Wangsets.Count, "Wangsets.Count");
- for (var i = 0; i < expected.Wangsets.Count; i++)
- AssertWangset(expected.Wangsets[i], actual.Wangsets[i]);
- }
- AssertTransformations(expected.Transformations, actual.Transformations);
-
- // Any number of
- Assert.NotNull(actual.Tiles);
- AssertEqual(expected.Tiles.Count, actual.Tiles.Count, "Tiles.Count");
- for (var i = 0; i < expected.Tiles.Count; i++)
- AssertTile(expected.Tiles[i], actual.Tiles[i]);
+ AssertListOrdered(expected.Wangsets, actual.Wangsets, nameof(Tileset.Wangsets), AssertWangset);
+ AssertOptionalsEqual(expected.Transformations, actual.Transformations, nameof(Tileset.Transformations), AssertTransformations);
+ AssertListOrdered(expected.Tiles, actual.Tiles, nameof(Tileset.Tiles), AssertTile);
}
- private static void AssertTileOffset(TileOffset? expected, TileOffset? actual)
+ private static void AssertTileOffset(TileOffset expected, TileOffset actual)
{
if (expected is null)
{
@@ -57,7 +43,7 @@ public static partial class DotTiledAssert
AssertEqual(expected.Y, actual.Y, nameof(TileOffset.Y));
}
- private static void AssertGrid(Grid? expected, Grid? actual)
+ private static void AssertGrid(Grid expected, Grid actual)
{
if (expected is null)
{
@@ -74,27 +60,17 @@ public static partial class DotTiledAssert
private static void AssertWangset(Wangset expected, Wangset actual)
{
- // Attributes
AssertEqual(expected.Name, actual.Name, nameof(Wangset.Name));
AssertEqual(expected.Class, actual.Class, nameof(Wangset.Class));
AssertEqual(expected.Tile, actual.Tile, nameof(Wangset.Tile));
- // At most one of
AssertProperties(expected.Properties, actual.Properties);
- if (expected.WangColors is not null)
- {
- Assert.NotNull(actual.WangColors);
- AssertEqual(expected.WangColors.Count, actual.WangColors.Count, "WangColors.Count");
- for (var i = 0; i < expected.WangColors.Count; i++)
- AssertWangColor(expected.WangColors[i], actual.WangColors[i]);
- }
- for (var i = 0; i < expected.WangTiles.Count; i++)
- AssertWangTile(expected.WangTiles[i], actual.WangTiles[i]);
+ AssertListOrdered(expected.WangColors, actual.WangColors, nameof(Wangset.WangColors), AssertWangColor);
+ AssertListOrdered(expected.WangTiles, actual.WangTiles, nameof(Wangset.WangTiles), AssertWangTile);
}
private static void AssertWangColor(WangColor expected, WangColor actual)
{
- // Attributes
AssertEqual(expected.Name, actual.Name, nameof(WangColor.Name));
AssertEqual(expected.Class, actual.Class, nameof(WangColor.Class));
AssertEqual(expected.Color, actual.Color, nameof(WangColor.Color));
@@ -106,12 +82,11 @@ public static partial class DotTiledAssert
private static void AssertWangTile(WangTile expected, WangTile actual)
{
- // Attributes
AssertEqual(expected.TileID, actual.TileID, nameof(WangTile.TileID));
AssertEqual(expected.WangID, actual.WangID, nameof(WangTile.WangID));
}
- private static void AssertTransformations(Transformations? expected, Transformations? actual)
+ private static void AssertTransformations(Transformations expected, Transformations actual)
{
if (expected is null)
{
@@ -119,7 +94,6 @@ public static partial class DotTiledAssert
return;
}
- // Attributes
Assert.NotNull(actual);
AssertEqual(expected.HFlip, actual.HFlip, nameof(Transformations.HFlip));
AssertEqual(expected.VFlip, actual.VFlip, nameof(Transformations.VFlip));
@@ -129,7 +103,6 @@ public static partial class DotTiledAssert
private static void AssertTile(Tile expected, Tile actual)
{
- // Attributes
AssertEqual(expected.ID, actual.ID, nameof(Tile.ID));
AssertEqual(expected.Type, actual.Type, nameof(Tile.Type));
AssertEqual(expected.Probability, actual.Probability, nameof(Tile.Probability));
@@ -138,22 +111,14 @@ public static partial class DotTiledAssert
AssertEqual(expected.Width, actual.Width, nameof(Tile.Width));
AssertEqual(expected.Height, actual.Height, nameof(Tile.Height));
- // Elements
AssertProperties(expected.Properties, actual.Properties);
- AssertImage(expected.Image, actual.Image);
- AssertLayer((BaseLayer?)expected.ObjectLayer, (BaseLayer?)actual.ObjectLayer);
- if (expected.Animation is not null)
- {
- Assert.NotNull(actual.Animation);
- AssertEqual(expected.Animation.Count, actual.Animation.Count, "Animation.Count");
- for (var i = 0; i < expected.Animation.Count; i++)
- AssertFrame(expected.Animation[i], actual.Animation[i]);
- }
+ AssertOptionalsEqual(expected.Image, actual.Image, nameof(Tile.Image), AssertImage);
+ AssertOptionalsEqual(expected.ObjectLayer, actual.ObjectLayer, nameof(Tile.ObjectLayer), (a, b) => AssertLayer((BaseLayer)a, (BaseLayer)b));
+ AssertListOrdered(expected.Animation, actual.Animation, nameof(Tile.Animation), AssertFrame);
}
private static void AssertFrame(Frame expected, Frame actual)
{
- // Attributes
AssertEqual(expected.TileID, actual.TileID, nameof(Frame.TileID));
AssertEqual(expected.Duration, actual.Duration, nameof(Frame.Duration));
}
diff --git a/src/DotTiled.Tests/DotTiled.Tests.csproj b/src/DotTiled.Tests/DotTiled.Tests.csproj
index faa22d4..552a423 100644
--- a/src/DotTiled.Tests/DotTiled.Tests.csproj
+++ b/src/DotTiled.Tests/DotTiled.Tests.csproj
@@ -3,7 +3,6 @@
net8.0enable
- enablefalsetrue
@@ -12,6 +11,7 @@
+
@@ -26,7 +26,12 @@
-
+
+
+
+
+
+
diff --git a/src/DotTiled.Tests/IntegrationTests/CustomTypes/FromTypeUsedInLoaderTests.cs b/src/DotTiled.Tests/IntegrationTests/CustomTypes/FromTypeUsedInLoaderTests.cs
new file mode 100644
index 0000000..dae9464
--- /dev/null
+++ b/src/DotTiled.Tests/IntegrationTests/CustomTypes/FromTypeUsedInLoaderTests.cs
@@ -0,0 +1,180 @@
+using DotTiled.Serialization;
+using NSubstitute;
+
+namespace DotTiled.Tests;
+
+public class FromTypeUsedInLoaderTests
+{
+ private sealed class TestClass
+ {
+ public string Name { get; set; } = "John Doe";
+ public int Age { get; set; } = 42;
+ }
+
+ [Fact]
+ public void LoadMap_MapHasClassAndClassIsDefined_ReturnsCorrectMap()
+ {
+ // Arrange
+ var resourceReader = Substitute.For();
+ resourceReader.Read("map.tmx").Returns(
+ """
+
+
+ """);
+ var classDefinition = CustomClassDefinition.FromClass();
+ var loader = Loader.DefaultWith(
+ resourceReader: resourceReader,
+ customTypeDefinitions: [classDefinition]);
+ var expectedMap = new Map
+ {
+ Class = "TestClass",
+ Orientation = MapOrientation.Orthogonal,
+ Width = 5,
+ Height = 5,
+ TileWidth = 32,
+ TileHeight = 32,
+ Infinite = false,
+ ParallaxOriginX = 0,
+ ParallaxOriginY = 0,
+ RenderOrder = RenderOrder.RightDown,
+ CompressionLevel = -1,
+ BackgroundColor = new Color { R = 0, G = 0, B = 0, A = 0 },
+ Version = "1.10",
+ TiledVersion = "1.11.0",
+ NextLayerID = 2,
+ NextObjectID = 1,
+ Layers = [
+ new TileLayer
+ {
+ ID = 1,
+ Name = "Tile Layer 1",
+ Width = 5,
+ Height = 5,
+ Data = new Data
+ {
+ Encoding = DataEncoding.Csv,
+ GlobalTileIDs = new Optional([
+ 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0
+ ]),
+ FlippingFlags = new Optional([
+ FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
+ FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
+ FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
+ FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
+ FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None
+ ])
+ }
+ }
+ ],
+ Properties = [
+ new StringProperty { Name = "Name", Value = "John Doe" },
+ new IntProperty { Name = "Age", Value = 42 }
+ ]
+ };
+
+ // Act
+ var result = loader.LoadMap("map.tmx");
+
+ // Assert
+ DotTiledAssert.AssertMap(expectedMap, result);
+ }
+
+ [Fact]
+ public void LoadMap_MapHasClassAndClassIsDefinedAndFieldIsOverridenFromDefault_ReturnsCorrectMap()
+ {
+ // Arrange
+ var resourceReader = Substitute.For();
+ resourceReader.Read("map.tmx").Returns(
+ """
+
+
+ """);
+ var classDefinition = CustomClassDefinition.FromClass();
+ var loader = Loader.DefaultWith(
+ resourceReader: resourceReader,
+ customTypeDefinitions: [classDefinition]);
+ var expectedMap = new Map
+ {
+ Class = "TestClass",
+ Orientation = MapOrientation.Orthogonal,
+ Width = 5,
+ Height = 5,
+ TileWidth = 32,
+ TileHeight = 32,
+ Infinite = false,
+ ParallaxOriginX = 0,
+ ParallaxOriginY = 0,
+ RenderOrder = RenderOrder.RightDown,
+ CompressionLevel = -1,
+ BackgroundColor = new Color { R = 0, G = 0, B = 0, A = 0 },
+ Version = "1.10",
+ TiledVersion = "1.11.0",
+ NextLayerID = 2,
+ NextObjectID = 1,
+ Layers = [
+ new TileLayer
+ {
+ ID = 1,
+ Name = "Tile Layer 1",
+ Width = 5,
+ Height = 5,
+ Data = new Data
+ {
+ Encoding = DataEncoding.Csv,
+ GlobalTileIDs = new Optional([
+ 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0
+ ]),
+ FlippingFlags = new Optional([
+ FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
+ FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
+ FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
+ FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
+ FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None
+ ])
+ }
+ }
+ ],
+ Properties = [
+ new StringProperty { Name = "Name", Value = "John Doe" },
+ new IntProperty { Name = "Age", Value = 42 }
+ ]
+ };
+
+ // Act
+ var result = loader.LoadMap("map.tmx");
+
+ // Assert
+ DotTiledAssert.AssertMap(expectedMap, result);
+ }
+}
diff --git a/src/DotTiled.Tests/Serialization/TestData.cs b/src/DotTiled.Tests/Serialization/TestData.cs
deleted file mode 100644
index 7f68c9e..0000000
--- a/src/DotTiled.Tests/Serialization/TestData.cs
+++ /dev/null
@@ -1,45 +0,0 @@
-using System.Xml;
-
-namespace DotTiled.Tests;
-
-public static partial class TestData
-{
- public static XmlReader GetXmlReaderFor(string testDataFile)
- {
- var fullyQualifiedTestDataFile = $"DotTiled.Tests.{ConvertPathToAssemblyResourcePath(testDataFile)}";
- using var stream = typeof(TestData).Assembly.GetManifestResourceStream(fullyQualifiedTestDataFile)
- ?? throw new ArgumentException($"Test data file '{fullyQualifiedTestDataFile}' not found");
-
- using var stringReader = new StreamReader(stream);
- var xml = stringReader.ReadToEnd();
- var xmlStringReader = new StringReader(xml);
- return XmlReader.Create(xmlStringReader);
- }
-
- public static string GetRawStringFor(string testDataFile)
- {
- var fullyQualifiedTestDataFile = $"DotTiled.Tests.{ConvertPathToAssemblyResourcePath(testDataFile)}";
- using var stream = typeof(TestData).Assembly.GetManifestResourceStream(fullyQualifiedTestDataFile)
- ?? throw new ArgumentException($"Test data file '{fullyQualifiedTestDataFile}' not found");
-
- using var stringReader = new StreamReader(stream);
- return stringReader.ReadToEnd();
- }
-
- private static string ConvertPathToAssemblyResourcePath(string path) =>
- path.Replace("/", ".").Replace("\\", ".").Replace(" ", "_");
-
- public static IEnumerable