v1.00.00
This commit is contained in:
105
AssetStudio/YAML/Utils/Extensions/IDictionaryYAMLExtensions.cs
Normal file
105
AssetStudio/YAML/Utils/Extensions/IDictionaryYAMLExtensions.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AssetStudio
|
||||
{
|
||||
public static class IDictionaryYAMLExtensions
|
||||
{
|
||||
public static YAMLNode ExportYAML(this IReadOnlyDictionary<uint, string> _this)
|
||||
{
|
||||
YAMLMappingNode node = new YAMLMappingNode();
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
node.Add(kvp.Key, kvp.Value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyDictionary<long, string> _this)
|
||||
{
|
||||
YAMLMappingNode node = new YAMLMappingNode();
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
node.Add(kvp.Key, kvp.Value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyDictionary<string, string> _this)
|
||||
{
|
||||
YAMLMappingNode node = new YAMLMappingNode();
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
node.Add(kvp.Key, kvp.Value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyDictionary<string, int> _this)
|
||||
{
|
||||
YAMLMappingNode node = new YAMLMappingNode();
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
node.Add(kvp.Key, kvp.Value);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyDictionary<string, float> _this)
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.BlockCurve);
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode map = new YAMLMappingNode();
|
||||
map.Add(kvp.Key, kvp.Value);
|
||||
node.Add(map);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyDictionary<Tuple<ushort, ushort>, float> _this)
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.BlockCurve);
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode keyNode = new YAMLMappingNode();
|
||||
keyNode.Add(kvp.Key.Item1, kvp.Key.Item2);
|
||||
YAMLMappingNode kvpMap = new YAMLMappingNode();
|
||||
kvpMap.Add("first", keyNode);
|
||||
kvpMap.Add("second", kvp.Value);
|
||||
node.Add(kvpMap);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML(this IReadOnlyDictionary<Tuple<int, long>, string> _this)
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.BlockCurve);
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode keyNode = new YAMLMappingNode();
|
||||
keyNode.Add(kvp.Key.Item1, kvp.Key.Item2);
|
||||
YAMLMappingNode kvpMap = new YAMLMappingNode();
|
||||
kvpMap.Add("first", keyNode);
|
||||
kvpMap.Add("second", kvp.Value);
|
||||
node.Add(kvpMap);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static YAMLNode ExportYAML<T>(this IReadOnlyDictionary<Tuple<T, long>, string> _this, Func<T, int> converter)
|
||||
{
|
||||
YAMLSequenceNode node = new YAMLSequenceNode(SequenceStyle.BlockCurve);
|
||||
foreach (var kvp in _this)
|
||||
{
|
||||
YAMLMappingNode keyNode = new YAMLMappingNode();
|
||||
keyNode.Add(converter(kvp.Key.Item1), kvp.Key.Item2);
|
||||
YAMLMappingNode kvpMap = new YAMLMappingNode();
|
||||
kvpMap.Add("first", keyNode);
|
||||
kvpMap.Add("second", kvp.Value);
|
||||
node.Add(kvpMap);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user