From 226fb15eb1e6dced94523659d20fb3bd00021d2f Mon Sep 17 00:00:00 2001 From: PopSlime Date: Fri, 16 Dec 2022 14:55:21 +0800 Subject: [PATCH] Resource cleanup. --- Assets/AssemblyInfo.cs | 8 - Assets/AssemblyInfo.cs.meta | 11 - Assets/Cryville/Cryville.Crtr.asmdef | 16 + .../Cryville.Crtr.asmdef.meta} | 2 +- Assets/EricHaines.meta | 9 - Assets/EricHaines/TextureScale.cs | 144 --- Assets/EricHaines/TextureScale.cs.meta | 12 - .../Quaver.API/Quaver.API.asmdef} | 9 +- .../Quaver.API/Quaver.API.asmdef.meta} | 5 +- Assets/SystemExtensions.meta | 9 - Assets/SystemExtensions/gstring.cs | 1063 ----------------- Assets/SystemExtensions/gstring.cs.meta | 11 - Assets/YamlDotNet/Examples.meta | 9 - .../YamlDotNet/Examples/ConvertYamlToJson.cs | 63 - .../Examples/ConvertYamlToJson.cs.meta | 11 - .../Examples/DeserializeObjectGraph.cs | 165 --- .../Examples/DeserializeObjectGraph.cs.meta | 11 - .../DeserializingMultipleDocuments.cs | 79 -- .../DeserializingMultipleDocuments.cs.meta | 11 - .../Examples/Helpers/ExampleRunner.cs | 147 --- .../Examples/Helpers/ExampleRunner.cs.meta | 11 - .../Examples/Helpers/ITestOutputHelper.cs | 8 - .../Helpers/ITestOutputHelper.cs.meta | 12 - .../Examples/Helpers/SampleAttribute.cs | 11 - .../Examples/Helpers/SampleAttribute.cs.meta | 11 - .../YamlDotNet/Examples/LoadingAYamlStream.cs | 106 -- .../Examples/LoadingAYamlStream.cs.meta | 11 - .../Examples/SerializeObjectGraph.cs | 124 -- .../Examples/SerializeObjectGraph.cs.meta | 11 - 29 files changed, 24 insertions(+), 2076 deletions(-) delete mode 100644 Assets/AssemblyInfo.cs delete mode 100644 Assets/AssemblyInfo.cs.meta create mode 100644 Assets/Cryville/Cryville.Crtr.asmdef rename Assets/{YamlDotNet/Examples/YamlDotNet.Examples.asmdef.meta => Cryville/Cryville.Crtr.asmdef.meta} (76%) delete mode 100644 Assets/EricHaines.meta delete mode 100644 Assets/EricHaines/TextureScale.cs delete mode 100644 Assets/EricHaines/TextureScale.cs.meta rename Assets/{YamlDotNet/Examples/YamlDotNet.Examples.asmdef => Extensions/Quaver.API/Quaver.API.asmdef} (59%) rename Assets/{YamlDotNet/Examples/Helpers.meta => Extensions/Quaver.API/Quaver.API.asmdef.meta} (57%) delete mode 100644 Assets/SystemExtensions.meta delete mode 100644 Assets/SystemExtensions/gstring.cs delete mode 100644 Assets/SystemExtensions/gstring.cs.meta delete mode 100644 Assets/YamlDotNet/Examples.meta delete mode 100644 Assets/YamlDotNet/Examples/ConvertYamlToJson.cs delete mode 100644 Assets/YamlDotNet/Examples/ConvertYamlToJson.cs.meta delete mode 100644 Assets/YamlDotNet/Examples/DeserializeObjectGraph.cs delete mode 100644 Assets/YamlDotNet/Examples/DeserializeObjectGraph.cs.meta delete mode 100644 Assets/YamlDotNet/Examples/DeserializingMultipleDocuments.cs delete mode 100644 Assets/YamlDotNet/Examples/DeserializingMultipleDocuments.cs.meta delete mode 100644 Assets/YamlDotNet/Examples/Helpers/ExampleRunner.cs delete mode 100644 Assets/YamlDotNet/Examples/Helpers/ExampleRunner.cs.meta delete mode 100644 Assets/YamlDotNet/Examples/Helpers/ITestOutputHelper.cs delete mode 100644 Assets/YamlDotNet/Examples/Helpers/ITestOutputHelper.cs.meta delete mode 100644 Assets/YamlDotNet/Examples/Helpers/SampleAttribute.cs delete mode 100644 Assets/YamlDotNet/Examples/Helpers/SampleAttribute.cs.meta delete mode 100644 Assets/YamlDotNet/Examples/LoadingAYamlStream.cs delete mode 100644 Assets/YamlDotNet/Examples/LoadingAYamlStream.cs.meta delete mode 100644 Assets/YamlDotNet/Examples/SerializeObjectGraph.cs delete mode 100644 Assets/YamlDotNet/Examples/SerializeObjectGraph.cs.meta diff --git a/Assets/AssemblyInfo.cs b/Assets/AssemblyInfo.cs deleted file mode 100644 index e7bb345..0000000 --- a/Assets/AssemblyInfo.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System.Reflection; - -[assembly: AssemblyCompany("Cryville")] -[assembly: AssemblyCopyright("Copyright © Cryville 2020-2022")] -[assembly: AssemblyDefaultAlias("Cosmo Resona")] -[assembly: AssemblyProduct("Cosmo Resona")] -[assembly: AssemblyTitle("Cosmo Resona")] -[assembly: AssemblyVersion("0.5.0")] \ No newline at end of file diff --git a/Assets/AssemblyInfo.cs.meta b/Assets/AssemblyInfo.cs.meta deleted file mode 100644 index a634853..0000000 --- a/Assets/AssemblyInfo.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: a69a6c726b01961419c4835bba37a218 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Cryville/Cryville.Crtr.asmdef b/Assets/Cryville/Cryville.Crtr.asmdef new file mode 100644 index 0000000..070af81 --- /dev/null +++ b/Assets/Cryville/Cryville.Crtr.asmdef @@ -0,0 +1,16 @@ +{ + "name": "Cryville.Crtr", + "rootNamespace": "", + "references": [ + "GUID:d8ea0e0da3ad53a45b65c912ffcacab0" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": true, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Assets/YamlDotNet/Examples/YamlDotNet.Examples.asmdef.meta b/Assets/Cryville/Cryville.Crtr.asmdef.meta similarity index 76% rename from Assets/YamlDotNet/Examples/YamlDotNet.Examples.asmdef.meta rename to Assets/Cryville/Cryville.Crtr.asmdef.meta index fcf6a07..6700a69 100644 --- a/Assets/YamlDotNet/Examples/YamlDotNet.Examples.asmdef.meta +++ b/Assets/Cryville/Cryville.Crtr.asmdef.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: c23d1189efdcccd43ba976c73f20fa1d +guid: 6eb95bd93da7fd54c8c2da321efabb1f AssemblyDefinitionImporter: externalObjects: {} userData: diff --git a/Assets/EricHaines.meta b/Assets/EricHaines.meta deleted file mode 100644 index b37d36e..0000000 --- a/Assets/EricHaines.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: abad95983f1ca394a92bb061b76ebb2f -folderAsset: yes -timeCreated: 1638411493 -licenseType: Free -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/EricHaines/TextureScale.cs b/Assets/EricHaines/TextureScale.cs deleted file mode 100644 index 1edc736..0000000 --- a/Assets/EricHaines/TextureScale.cs +++ /dev/null @@ -1,144 +0,0 @@ -namespace EricHaines { - // Only works on ARGB32, RGB24 and Alpha8 textures that are marked readable - - using System.Threading; - using UnityEngine; - - public class TextureScale { - public class ThreadData { - public int start; - public int end; - public ThreadData(int s, int e) { - start = s; - end = e; - } - } - - private static Color[] texColors; - private static Color[] newColors; - private static int w; - private static float ratioX; - private static float ratioY; - private static int w2; - private static int finishCount; - private static Mutex mutex; - - public static void Point(Texture2D tex, int newWidth, int newHeight) { - ThreadedScale(tex, newWidth, newHeight, false); - } - - public static void Bilinear(Texture2D tex, int newWidth, int newHeight) { - ThreadedScale(tex, newWidth, newHeight, true); - } - - private static void ThreadedScale(Texture2D tex, int newWidth, int newHeight, bool useBilinear) { - texColors = tex.GetPixels(); - newColors = new Color[newWidth * newHeight]; - if (useBilinear) { - ratioX = 1.0f / ((float)newWidth / (tex.width - 1)); - ratioY = 1.0f / ((float)newHeight / (tex.height - 1)); - } - else { - ratioX = (float)tex.width / newWidth; - ratioY = (float)tex.height / newHeight; - } - w = tex.width; - w2 = newWidth; - var cores = Mathf.Min(SystemInfo.processorCount, newHeight); - var slice = newHeight/cores; - - finishCount = 0; - if (mutex == null) { - mutex = new Mutex(false); - } - if (cores > 1) { - int i = 0; - ThreadData threadData; - for (i = 0; i < cores - 1; i++) { - threadData = new ThreadData(slice * i, slice * (i + 1)); - ParameterizedThreadStart ts = useBilinear ? new ParameterizedThreadStart(BilinearScale) : new ParameterizedThreadStart(PointScale); - Thread thread = new Thread(ts); - thread.Start(threadData); - } - threadData = new ThreadData(slice * i, newHeight); - if (useBilinear) { - BilinearScale(threadData); - } - else { - PointScale(threadData); - } - while (finishCount < cores) { - Thread.Sleep(1); - } - } - else { - ThreadData threadData = new ThreadData(0, newHeight); - if (useBilinear) { - BilinearScale(threadData); - } - else { - PointScale(threadData); - } - } - -#if UNITY_2021_2_OR_NEWER - tex.Reinitialize(newWidth, newHeight); -#else - tex.Resize(newWidth, newHeight); -#endif - tex.SetPixels(newColors); - tex.Apply(); - - texColors = null; - newColors = null; - } - - public static void BilinearScale(object obj) { - ThreadData threadData = (ThreadData) obj; - for (var y = threadData.start; y < threadData.end; y++) { - int yFloor = (int)Mathf.Floor(y * ratioY); - var y1 = yFloor * w; - var y2 = (yFloor+1) * w; - var yw = y * w2; - - for (var x = 0; x < w2; x++) { - int xFloor = (int)Mathf.Floor(x * ratioX); - var xLerp = x * ratioX-xFloor; - newColors[yw + x] = ColorLerpUnclamped( - ColorLerpUnclamped(texColors[y1 + xFloor], texColors[y1 + xFloor + 1], xLerp), - ColorLerpUnclamped(texColors[y2 + xFloor], texColors[y2 + xFloor + 1], xLerp), - y * ratioY - yFloor - ); - } - } - - mutex.WaitOne(); - finishCount++; - mutex.ReleaseMutex(); - } - - public static void PointScale(object obj) { - ThreadData threadData = (ThreadData) obj; - for (var y = threadData.start; y < threadData.end; y++) { - var thisY = (int)(ratioY * y) * w; - var yw = y * w2; - for (var x = 0; x < w2; x++) { - newColors[yw + x] = texColors[(int)(thisY + ratioX * x)]; - } - } - - mutex.WaitOne(); - finishCount++; - mutex.ReleaseMutex(); - } - - private static Color ColorLerpUnclamped(Color c1, Color c2, float value) { - return new Color( - c1.r + (c2.r - c1.r) * value, - c1.g + (c2.g - c1.g) * value, - c1.b + (c2.b - c1.b) * value, - c1.a + (c2.a - c1.a) * value - ); - } - } -} diff --git a/Assets/EricHaines/TextureScale.cs.meta b/Assets/EricHaines/TextureScale.cs.meta deleted file mode 100644 index 152aaac..0000000 --- a/Assets/EricHaines/TextureScale.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 58e01e1e11af164408a19c1086709bd7 -timeCreated: 1638411495 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YamlDotNet/Examples/YamlDotNet.Examples.asmdef b/Assets/Extensions/Quaver.API/Quaver.API.asmdef similarity index 59% rename from Assets/YamlDotNet/Examples/YamlDotNet.Examples.asmdef rename to Assets/Extensions/Quaver.API/Quaver.API.asmdef index b68814b..53dae93 100644 --- a/Assets/YamlDotNet/Examples/YamlDotNet.Examples.asmdef +++ b/Assets/Extensions/Quaver.API/Quaver.API.asmdef @@ -1,15 +1,16 @@ { - "name": "YamlDotNet.Examples", + "name": "Quaver.API", + "rootNamespace": "", "references": [ - "YamlDotNet" + "GUID:b3f49edfedc855a48aa1a9e5d3cba438" ], "includePlatforms": [], "excludePlatforms": [], "allowUnsafeCode": false, "overrideReferences": true, "precompiledReferences": [], - "autoReferenced": false, + "autoReferenced": true, "defineConstraints": [], "versionDefines": [], - "noEngineReferences": false + "noEngineReferences": true } \ No newline at end of file diff --git a/Assets/YamlDotNet/Examples/Helpers.meta b/Assets/Extensions/Quaver.API/Quaver.API.asmdef.meta similarity index 57% rename from Assets/YamlDotNet/Examples/Helpers.meta rename to Assets/Extensions/Quaver.API/Quaver.API.asmdef.meta index 1469b29..67e3ba3 100644 --- a/Assets/YamlDotNet/Examples/Helpers.meta +++ b/Assets/Extensions/Quaver.API/Quaver.API.asmdef.meta @@ -1,7 +1,6 @@ fileFormatVersion: 2 -guid: daabd28f177eb0946b93b026e9d6e738 -folderAsset: yes -DefaultImporter: +guid: d8ea0e0da3ad53a45b65c912ffcacab0 +AssemblyDefinitionImporter: externalObjects: {} userData: assetBundleName: diff --git a/Assets/SystemExtensions.meta b/Assets/SystemExtensions.meta deleted file mode 100644 index b0846f2..0000000 --- a/Assets/SystemExtensions.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: dc2947c139e087f43b375d2510a449df -folderAsset: yes -timeCreated: 1621384032 -licenseType: Free -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/SystemExtensions/gstring.cs b/Assets/SystemExtensions/gstring.cs deleted file mode 100644 index 919c188..0000000 --- a/Assets/SystemExtensions/gstring.cs +++ /dev/null @@ -1,1063 +0,0 @@ -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using UnityEngine; - -//#define DBG - -// gstring (gcfreestring) is a string wrapper that uses pointers to mutate the string when performing misc string operations -// the purpose is to be able to perform most the common operations we do no strings (concat, format, replace, etc) -// without any allocation. -// gstring is not meant to be stored as member variables, but to quickly declare them in a 'gstring block', use them -// for whatever string operation you want, then dispose of them. -// The nice thing is that you don't have to manually dispose of gstrings, once you're in a block all assignments are -// registered so that when the block/scope ends all used gstrings are disposed. -// -// But what if you wanted to keep/store the result you calculated and not dispose of them? -// Well this is where 'intern' comes in - basically there's a runtime intern (cache) table -// of strings (similar to .NET's string const intern table). -// string str = result.Intern(); -// Which basically says, if the string is in the intern (cache) table, return it -// otherwise allocate new memory for it and store it in the table, next time we ask for it, it's there. -// The nice thing about interning is that you could pre-intern your strings via the static method gstring.Intern -// -// NOTES: -// 1- The class is not designed with concurrency/threading in mind, it's meant to be used in Unity -// 2- Cultural stuff I did not consider as well -// 3- Again, you shouldn't have gstring members in your class. All gstring instances are meant to be disposed. -// You just quickly open up a gstring.Block() and use gstrings in it, if you want to store a result you get -// back from a gstring operation use Intern - -namespace System { - public class gstring { - static Dictionary> g_cache; - static Stack g_blocks; - static List g_intern_table; - static gstring_block g_current_block; - static List g_finds; - static gstring[] g_format_args; - - const int INITIAL_BLOCK_CAPACITY = 32; - const int INITIAL_CACHE_CAPACITY = 128; - const int INITIAL_STACK_CAPACITY = 48; - const int INITIAL_INTERN_CAPACITY = 256; - const char NEW_ALLOC_CHAR = 'X'; - - [NonSerialized] string _value; - [NonSerialized] bool _disposed; - - internal gstring() { - throw new NotSupportedException(); - } - - internal gstring(int length) { - _value = new string(NEW_ALLOC_CHAR, length); - } - - static gstring() { - Initialize(INITIAL_CACHE_CAPACITY, - INITIAL_STACK_CAPACITY, - INITIAL_BLOCK_CAPACITY, - INITIAL_INTERN_CAPACITY); - - g_finds = new List(10); - g_format_args = new gstring[10]; - } - - internal void dispose() { - if (_disposed) - throw new ObjectDisposedException(this); - - // At this point there *must* be a stack whose length is equal to ours - // otherwise we wouldn't exist - var stack = g_cache[Length]; - stack.Push(this); -#if DBG - if (log != null) - log("Disposed: " + _value + " Length=" + Length + " Stack=" + stack.Count); -#endif - memcpy(_value, NEW_ALLOC_CHAR); - - _disposed = true; - } - - internal static gstring get(string value) { - if (value == null) - return null; -#if DBG - if (log != null) - log("Getting: " + value); -#endif - var result = get(value.Length); - memcpy(dst: result, src: value); - return result; - } - - internal static string __intern(string value) { - int idx = g_intern_table.IndexOf(value); - if (idx != -1) - return g_intern_table[idx]; - - string interned = new string(NEW_ALLOC_CHAR, value.Length); - memcpy(interned, value); - g_intern_table.Add(interned); -#if DBG - if (log != null) - log("Interned: " + value); -#endif - return interned; - } - - internal static gstring get(int length) { - if (g_current_block == null) - throw new InvalidOperationException("Getting gstrings must be done in a gstring_block. Make sure you do a using(gstring.block())"); - - if (length <= 0) - throw new InvalidOperationException("Invalid length: " + length); - - gstring result; - Stack stack; - if (!g_cache.TryGetValue(length, out stack)) { - stack = new Stack(INITIAL_STACK_CAPACITY); - for (int i = 0; i < INITIAL_STACK_CAPACITY; i++) - stack.Push(new gstring(length)); - g_cache[length] = stack; - result = stack.Pop(); - } - else { - if (stack.Count == 0) { - if (Log != null) - Log("Stack=0 Allocating new gstring Length=" + length); - result = new gstring(length); - } - else { - result = stack.Pop(); -#if DBG - if (log != null) - log("Popped Length=" + length + " Stack=" + stack.Count); -#endif - } - } - - result._disposed = false; - - g_current_block.push(result); - - return result; - } - - internal static int get_digit_count(int value) { - int cnt; - for (cnt = 1; (value /= 10) > 0; cnt++) ; - return cnt; - } - - internal static int internal_index_of(string input, char value, int start) { - return internal_index_of(input, value, start, input.Length - start); - } - - internal static int internal_index_of(string input, string value) { - return internal_index_of(input, value, 0, input.Length); - } - - internal static int internal_index_of(string input, string value, int start) { - return internal_index_of(input, value, start, input.Length - start); - } - - internal unsafe static gstring internal_format(string input, int num_args) { - // "{0} {1}", "Hello", "World" -> - // "xxxxxxxxxxx" - // "Helloxxxxxx" - // "Hello xxxxx" - // "Hello World" - - // "Player={0} Id={1}", "Jon", 10 -> - // "xxxxxxxxxxxxxxxx" - // "Player=xxxxxxxxx" - // "Player=Jonxxxxxx" - // "Player=Jon Id=xx" - // "Player=Jon Id=10" - - if (input == null) - throw new ArgumentNullException("value"); - - int new_len = input.Length - 3 * num_args; - - for (int i = 0; i < num_args; i++) { - gstring arg = g_format_args[i]; - new_len += arg.Length; - } - - gstring result = get(new_len); - string res_value = result._value; - - int brace_idx = -3; - for (int i = 0, j = 0, x = 0; x < num_args; x++) { - string arg = g_format_args[x]._value; - brace_idx = internal_index_of(input, '{', brace_idx + 3); - if (brace_idx == -1) - throw new InvalidOperationException("Couldn't find open brace for argument " + arg); - if (brace_idx + 2 >= input.Length || input[brace_idx + 2] != '}') - throw new InvalidOperationException("Couldn't find close brace for argument " + arg); - - fixed (char* ptr_input = input) { - fixed (char* ptr_result = res_value) { - for (int k = 0; i < new_len;) { - if (j < brace_idx) - ptr_result[i++] = ptr_input[j++]; - else { - ptr_result[i++] = arg[k++]; - if (k == arg.Length) { - j += 3; - break; - } - } - } - } - } - } - - return result; - } - - internal unsafe static int internal_index_of(string input, char value, int start, int count) { - if (start < 0 || start >= input.Length) - throw new ArgumentOutOfRangeException("start"); - - if (start + count > input.Length) - throw new ArgumentOutOfRangeException("count=" + count + " start+count=" + start + count); - - fixed (char* ptr_this = input) { - int end = start + count; - for (int i = start; i < end; i++) - if (ptr_this[i] == value) - return i; - return -1; - } - } - - internal unsafe static int internal_index_of(string input, string value, int start, int count) { - int input_len = input.Length; - - if (start < 0 || start >= input_len) - throw new ArgumentOutOfRangeException("start"); - - if (count < 0 || start + count > input_len) - throw new ArgumentOutOfRangeException("count=" + count + " start+count=" + (start + count)); - - if (count == 0) - return -1; - - fixed (char* ptr_input = input) { - fixed (char* ptr_value = value) { - int found = 0; - int end = start + count; - for (int i = start; i < end; i++) { - for (int j = 0; j < value.Length && i + j < input_len; j++) { - if (ptr_input[i + j] == ptr_value[j]) { - found++; - if (found == value.Length) - return i; - continue; - } - if (found > 0) - break; - } - } - return -1; - } - } - } - - internal unsafe static gstring internal_remove(string input, int start, int count) { - if (start < 0 || start >= input.Length) - throw new ArgumentOutOfRangeException("start=" + start + " Length=" + input.Length); - - if (count < 0 || start + count > input.Length) - throw new ArgumentOutOfRangeException("count=" + count + " start+count=" + (start + count) + " Length=" + input.Length); - - if (count == 0) - return input; - - gstring result = get(input.Length - count); - internal_remove(result, input, start, count); - return result; - } - - internal unsafe static void internal_remove(string dst, string src, int start, int count) { - fixed (char* src_ptr = src) { - fixed (char* dst_ptr = dst) { - for (int i = 0, j = 0; i < dst.Length; i++) { - if (i >= start && i < start + count) // within removal range - continue; - dst_ptr[j++] = src_ptr[i]; - } - } - } - } - - internal unsafe static gstring internal_replace(string value, string old_value, string new_value) { - // "Hello, World. There World" | World->Jon = - // "000000000000000000000" (len = orig - 2 * (world-jon) = orig - 4 - // "Hello, 00000000000000" - // "Hello, Jon00000000000" - // "Hello, Jon. There 000" - // "Hello, Jon. There Jon" - - // "Hello, World. There World" | World->Alexander = - // "000000000000000000000000000000000" (len = orig + 2 * (alexander-world) = orig + 8 - // "Hello, 00000000000000000000000000" - // "Hello, Alexander00000000000000000" - // "Hello, Alexander. There 000000000" - // "Hello, Alexander. There Alexander" - - if (old_value == null) - throw new ArgumentNullException("old_value"); - - if (new_value == null) - throw new ArgumentNullException("new_value"); - - int idx = internal_index_of(value, old_value); - if (idx == -1) - return value; - - g_finds.Clear(); - g_finds.Add(idx); - - // find all the indicies beforehand - while (idx + old_value.Length < value.Length) { - idx = internal_index_of(value, old_value, idx + old_value.Length); - if (idx == -1) - break; - g_finds.Add(idx); - } - - // calc the right new total length - int new_len; - int dif = old_value.Length - new_value.Length; - if (dif > 0) - new_len = value.Length - (g_finds.Count * dif); - else - new_len = value.Length + (g_finds.Count * -dif); - - gstring result = get(new_len); - fixed (char* ptr_this = value) { - fixed (char* ptr_result = result._value) { - for (int i = 0, x = 0, j = 0; i < new_len;) { - if (x == g_finds.Count || g_finds[x] != j) { - ptr_result[i++] = ptr_this[j++]; - } - else { - for (int n = 0; n < new_value.Length; n++) - ptr_result[i + n] = new_value[n]; - - x++; - i += new_value.Length; - j += old_value.Length; - } - } - } - } - return result; - } - - internal unsafe static gstring internal_insert(string value, char to_insert, int start, int count) { - // "HelloWorld" (to_insert=x, start=5, count=3) -> "HelloxxxWorld" - - if (start < 0 || start >= value.Length) - throw new ArgumentOutOfRangeException("start=" + start + " Length=" + value.Length); - - if (count < 0) - throw new ArgumentOutOfRangeException("count=" + count); - - if (count == 0) - return get(value); - - int new_len = value.Length + count; - gstring result = get(new_len); - fixed (char* ptr_value = value) { - fixed (char* ptr_result = result._value) { - for (int i = 0, j = 0; i < new_len; i++) { - if (i >= start && i < start + count) - ptr_result[i] = to_insert; - else - ptr_result[i] = ptr_value[j++]; - } - } - } - return result; - } - - internal unsafe static gstring internal_insert(string input, string to_insert, int start) { - if (input == null) - throw new ArgumentNullException("input"); - - if (to_insert == null) - throw new ArgumentNullException("to_insert"); - - if (start < 0 || start >= input.Length) - throw new ArgumentOutOfRangeException("start=" + start + " Length=" + input.Length); - - if (to_insert.Length == 0) - return get(input); - - int new_len = input.Length + to_insert.Length; - gstring result = get(new_len); - internal_insert(result, input, to_insert, start); - return result; - } - - internal unsafe static gstring internal_concat(string s1, string s2) { - int total_length = s1.Length + s2.Length; - gstring result = get(total_length); - fixed (char* ptr_result = result._value) { - fixed (char* ptr_s1 = s1) { - fixed (char* ptr_s2 = s2) { - memcpy(dst: ptr_result, src: ptr_s1, length: s1.Length, src_offset: 0); - memcpy(dst: ptr_result, src: ptr_s2, length: s2.Length, src_offset: s1.Length); - } - } - } - return result; - } - - internal unsafe static void internal_insert(string dst, string src, string to_insert, int start) { - fixed (char* ptr_src = src) { - fixed (char* ptr_dst = dst) { - fixed (char* ptr_to_insert = to_insert) { - for (int i = 0, j = 0, k = 0; i < dst.Length; i++) { - if (i >= start && i < start + to_insert.Length) - ptr_dst[i] = ptr_to_insert[k++]; - else - ptr_dst[i] = ptr_src[j++]; - } - } - } - } - } - - internal unsafe static void intcpy(char* dst, int value, int start, int count) { - int end = start + count; - for (int i = end - 1; i >= start; i--, value /= 10) - *(dst + i) = (char)(value % 10 + 48); - } - - internal unsafe static void memcpy(char* dst, char* src, int count) { - for (int i = 0; i < count; i++) - *(dst++) = *(src++); - } - - internal unsafe static void memcpy(string dst, char src) { - fixed (char* ptr_dst = dst) { - int len = dst.Length; - for (int i = 0; i < len; i++) - ptr_dst[i] = src; - } - } - - internal unsafe static void memcpy(string dst, char src, int index) { - fixed (char* ptr = dst) - ptr[index] = src; - } - - internal unsafe static void memcpy(string dst, string src) { - if (dst.Length != src.Length) - throw new InvalidOperationException("Length mismatch"); - - memcpy(dst, src, dst.Length, 0); - } - - internal unsafe static void memcpy(char* dst, char* src, int length, int src_offset) { - for (int i = 0; i < length; i++) - *(dst + i + src_offset) = *(src + i); - } - - internal unsafe static void memcpy(string dst, string src, int length, int src_offset) { - fixed (char* ptr_dst = dst) { - fixed (char* ptr_src = src) { - for (int i = 0; i < length; i++) - ptr_dst[i + src_offset] = ptr_src[i]; - } - } - } - - internal class gstring_block : IDisposable { - readonly Stack stack; - - internal gstring_block(int capacity) { - stack = new Stack(capacity); - } - - internal void push(gstring str) { - stack.Push(str); - } - - internal IDisposable begin() { -#if DBG - if (log != null) - log("Began block"); -#endif - return this; - } - - void IDisposable.Dispose() { -#if DBG - if (log != null) - log("Disposing block"); -#endif - while (stack.Count > 0) { - var str = stack.Pop(); - str.dispose(); - } - - gstring.g_blocks.Push(this); - } - } - - // Public API - #region - - public static Action Log = null; - - public static int DecimalAccuracy = 3; // digits after the decimal point - - public int Length { - get { return _value.Length; } - } - - public static void Initialize(int cache_capacity, int stack_capacity, int block_capacity, int intern_capacity) { - g_cache = new Dictionary>(cache_capacity); - g_blocks = new Stack(block_capacity); - g_intern_table = new List(intern_capacity); - - for (int c = 1; c < cache_capacity; c++) { - var stack = new Stack(stack_capacity); - for (int j = 0; j < stack_capacity; j++) - stack.Push(new gstring(c)); - g_cache[c] = stack; - } - - for (int i = 0; i < block_capacity; i++) { - var block = new gstring_block(block_capacity * 2); - g_blocks.Push(block); - } - } - - public static IDisposable Block() { - if (g_blocks.Count == 0) - g_current_block = new gstring_block(INITIAL_BLOCK_CAPACITY * 2); - else - g_current_block = g_blocks.Pop(); - return g_current_block.begin(); - } - - public string Intern() { - return __intern(_value); - } - - public static string Intern(string value) { - return __intern(value); - } - - public static void Intern(string[] values) { - for (int i = 0; i < values.Length; i++) - __intern(values[i]); - } - - public char this[int i] { - get { return _value[i]; } - set { memcpy(this, value, i); } - } - - public override int GetHashCode() { - return RuntimeHelpers.GetHashCode(_value); - } - - public override bool Equals(object obj) { - if (obj == null) - return ReferenceEquals(this, null); - - var gstr = obj as gstring; - if (gstr != null) - return gstr._value == this._value; - - var str = obj as string; - if (str != null) - return str == this._value; - - return false; - } - - public override string ToString() { - return _value; - } - - public static implicit operator gstring(bool value) { - return get(value ? "True" : "False"); - } - - public unsafe static implicit operator gstring(int value) { - // e.g. 125 - // first pass: count the number of digits - // then: get a gstring with length = num digits - // finally: iterate again, get the char of each digit, memcpy char to result - bool negative = value < 0; - value = Math.Abs(value); - int num_digits = get_digit_count(value); - gstring result; - if (negative) { - result = get(num_digits + 1); - fixed (char* ptr = result._value) { - *ptr = '-'; - intcpy(ptr, value, 1, num_digits); - } - } - else { - result = get(num_digits); - fixed (char* ptr = result._value) - intcpy(ptr, value, 0, num_digits); - } - return result; - } - - public unsafe static implicit operator gstring(float value) { - // e.g. 3.148 - bool negative = value < 0; - if (negative) value = -value; - int mul = (int)Math.Pow(10, DecimalAccuracy); - int number = (int)(value * mul); // gets the number as a whole, e.g. 3148 - int left_num = number / mul; // left part of the decimal point, e.g. 3 - int right_num = number % mul; // right part of the decimal pnt, e.g. 148 - int left_digit_count = get_digit_count(left_num); // e.g. 1 - int right_digit_count = get_digit_count(right_num); // e.g. 3 - int total = left_digit_count + right_digit_count + 1; // +1 for '.' - - gstring result; - if (negative) { - result = get(total + 1); // +1 for '-' - fixed (char* ptr = result._value) { - *ptr = '-'; - intcpy(ptr, left_num, 1, left_digit_count); - *(ptr + left_digit_count + 1) = '.'; - intcpy(ptr, right_num, left_digit_count + 2, right_digit_count); - } - } - else { - result = get(total); - fixed (char* ptr = result._value) { - intcpy(ptr, left_num, 0, left_digit_count); - *(ptr + left_digit_count) = '.'; - intcpy(ptr, right_num, left_digit_count + 1, right_digit_count); - } - } - return result; - } - - public static implicit operator gstring(string value) { - return get(value); - } - - public static implicit operator string(gstring value) { - return value._value; - } - - public static gstring operator +(gstring left, gstring right) { - return internal_concat(left, right); - } - - public static bool operator ==(gstring left, gstring right) { - if (ReferenceEquals(left, null)) - return ReferenceEquals(right, null); - if (ReferenceEquals(right, null)) - return false; - return left._value == right._value; - } - - public static bool operator !=(gstring left, gstring right) { - return !(left._value == right._value); - } - - public unsafe gstring ToUpper() { - var result = get(Length); - fixed (char* ptr_this = this._value) { - fixed (char* ptr_result = result._value) { - for (int i = 0; i < _value.Length; i++) { - var ch = ptr_this[i]; - if (char.IsLower(ch)) - ptr_result[i] = char.ToUpper(ch); - else - ptr_result[i] = ptr_this[i]; - } - } - } - return result; - } - - public unsafe gstring ToLower() { - var result = get(Length); - fixed (char* ptr_this = this._value) { - fixed (char* ptr_result = result._value) { - for (int i = 0; i < _value.Length; i++) { - var ch = ptr_this[i]; - if (char.IsUpper(ch)) - ptr_result[i] = char.ToLower(ch); - else - ptr_result[i] = ptr_this[i]; - } - } - } - return result; - } - - public gstring Remove(int start) { - return Remove(start, Length - start); - } - - public gstring Remove(int start, int count) { - return internal_remove(this._value, start, count); - } - - public gstring Insert(char value, int start, int count) { - return internal_insert(this._value, value, start, count); - } - - public gstring Insert(string value, int start) { - return internal_insert(this._value, value, start); - } - - public unsafe gstring Replace(char old_value, char new_value) { - gstring result = get(Length); - fixed (char* ptr_this = this._value) { - fixed (char* ptr_result = result._value) { - for (int i = 0; i < Length; i++) { - if (ptr_this[i] == old_value) - ptr_result[i] = new_value; - else - ptr_result[i] = ptr_this[i]; - } - } - } - return result; - } - - public gstring Replace(string old_value, string new_value) { - return internal_replace(this._value, old_value, new_value); - } - - public gstring Substring(int start) { - return Substring(start, Length - start); - } - - public unsafe gstring Substring(int start, int count) { - if (start < 0 || start >= Length) - throw new ArgumentOutOfRangeException("start"); - - if (count > Length) - throw new ArgumentOutOfRangeException("count"); - - gstring result = get(count); - fixed (char* src = this._value) - fixed (char* dst = result._value) - memcpy(dst, src + start, count); - - return result; - } - - public bool Contains(string value) { - return IndexOf(value) != -1; - } - - public bool Contains(char value) { - return IndexOf(value) != -1; - } - - public int LastIndexOf(string value) { - int idx = -1; - int last_find = -1; - while (true) { - idx = internal_index_of(this._value, value, idx + value.Length); - last_find = idx; - if (idx == -1 || idx + value.Length >= this._value.Length) - break; - } - return last_find; - } - - public int LastIndexOf(char value) { - int idx = -1; - int last_find = -1; - while (true) { - idx = internal_index_of(this._value, value, idx + 1); - last_find = idx; - if (idx == -1 || idx + 1 >= this._value.Length) - break; - } - return last_find; - } - - public int IndexOf(char value) { - return IndexOf(value, 0, Length); - } - - public int IndexOf(char value, int start) { - return internal_index_of(this._value, value, start); - } - - public int IndexOf(char value, int start, int count) { - return internal_index_of(this._value, value, start, count); - } - - public int IndexOf(string value) { - return IndexOf(value, 0, Length); - } - - public int IndexOf(string value, int start) { - return IndexOf(value, start, Length - start); - } - - public int IndexOf(string value, int start, int count) { - return internal_index_of(this._value, value, start, count); - } - - public unsafe bool EndsWith(string postfix) { - if (postfix == null) - throw new ArgumentNullException("postfix"); - - if (this.Length < postfix.Length) - return false; - - fixed (char* ptr_this = this._value) { - fixed (char* ptr_postfix = postfix) { - for (int i = this._value.Length - 1, j = postfix.Length - 1; j >= 0; i--, j--) - if (ptr_this[i] != ptr_postfix[j]) - return false; - } - } - - return true; - } - - public unsafe bool StartsWith(string prefix) { - if (prefix == null) - throw new ArgumentNullException("prefix"); - - if (this.Length < prefix.Length) - return false; - - fixed (char* ptr_this = this._value) { - fixed (char* ptr_prefix = prefix) { - for (int i = 0; i < prefix.Length; i++) - if (ptr_this[i] != ptr_prefix[i]) - return false; - } - } - - return true; - } - - public static int GetCacheCount(int length) { - Stack stack; - if (!g_cache.TryGetValue(length, out stack)) - return -1; - return stack.Count; - } - - public gstring Concat(gstring value) { - return internal_concat(this, value); - } - - public static gstring Concat(gstring s0, gstring s1) { return s0 + s1; } - - public static gstring Concat(gstring s0, gstring s1, gstring s2) { return s0 + s1 + s2; } - - public static gstring Concat(gstring s0, gstring s1, gstring s2, gstring s3) { return s0 + s1 + s2 + s3; } - - public static gstring Concat(gstring s0, gstring s1, gstring s2, gstring s3, gstring s4) { return s0 + s1 + s2 + s3 + s4; } - - public static gstring Concat(gstring s0, gstring s1, gstring s2, gstring s3, gstring s4, gstring s5) { return s0 + s1 + s2 + s3 + s4 + s5; } - - public static gstring Concat(gstring s0, gstring s1, gstring s2, gstring s3, gstring s4, gstring s5, gstring s6) { return s0 + s1 + s2 + s3 + s4 + s5 + s6; } - - public static gstring Concat(gstring s0, gstring s1, gstring s2, gstring s3, gstring s4, gstring s5, gstring s6, gstring s7) { return s0 + s1 + s2 + s3 + s4 + s5 + s6 + s7; } - - public static gstring Concat(gstring s0, gstring s1, gstring s2, gstring s3, gstring s4, gstring s5, gstring s6, gstring s7, gstring s8) { return s0 + s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8; } - - public static gstring Concat(gstring s0, gstring s1, gstring s2, gstring s3, gstring s4, gstring s5, gstring s6, gstring s7, gstring s8, gstring s9) { return s0 + s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9; } - - public static gstring Format(string input, gstring arg0, gstring arg1, gstring arg2, gstring arg3, gstring arg4, gstring arg5, gstring arg6, gstring arg7, gstring arg8, gstring arg9) { - if (arg0 == null) throw new ArgumentNullException("arg0"); - if (arg1 == null) throw new ArgumentNullException("arg1"); - if (arg2 == null) throw new ArgumentNullException("arg2"); - if (arg3 == null) throw new ArgumentNullException("arg3"); - if (arg4 == null) throw new ArgumentNullException("arg4"); - if (arg5 == null) throw new ArgumentNullException("arg5"); - if (arg6 == null) throw new ArgumentNullException("arg6"); - if (arg7 == null) throw new ArgumentNullException("arg7"); - if (arg8 == null) throw new ArgumentNullException("arg8"); - if (arg9 == null) throw new ArgumentNullException("arg9"); - - g_format_args[0] = arg0; - g_format_args[1] = arg1; - g_format_args[2] = arg2; - g_format_args[3] = arg3; - g_format_args[4] = arg4; - g_format_args[5] = arg5; - g_format_args[6] = arg6; - g_format_args[7] = arg7; - g_format_args[8] = arg8; - g_format_args[9] = arg9; - return internal_format(input, 10); - } - - public static gstring Format(string input, gstring arg0, gstring arg1, gstring arg2, gstring arg3, gstring arg4, gstring arg5, gstring arg6, gstring arg7, gstring arg8) { - if (arg0 == null) throw new ArgumentNullException("arg0"); - if (arg1 == null) throw new ArgumentNullException("arg1"); - if (arg2 == null) throw new ArgumentNullException("arg2"); - if (arg3 == null) throw new ArgumentNullException("arg3"); - if (arg4 == null) throw new ArgumentNullException("arg4"); - if (arg5 == null) throw new ArgumentNullException("arg5"); - if (arg6 == null) throw new ArgumentNullException("arg6"); - if (arg7 == null) throw new ArgumentNullException("arg7"); - if (arg8 == null) throw new ArgumentNullException("arg8"); - - g_format_args[0] = arg0; - g_format_args[1] = arg1; - g_format_args[2] = arg2; - g_format_args[3] = arg3; - g_format_args[4] = arg4; - g_format_args[5] = arg5; - g_format_args[6] = arg6; - g_format_args[7] = arg7; - g_format_args[8] = arg8; - return internal_format(input, 9); - } - - public static gstring Format(string input, gstring arg0, gstring arg1, gstring arg2, gstring arg3, gstring arg4, gstring arg5, gstring arg6, gstring arg7) { - if (arg0 == null) throw new ArgumentNullException("arg0"); - if (arg1 == null) throw new ArgumentNullException("arg1"); - if (arg2 == null) throw new ArgumentNullException("arg2"); - if (arg3 == null) throw new ArgumentNullException("arg3"); - if (arg4 == null) throw new ArgumentNullException("arg4"); - if (arg5 == null) throw new ArgumentNullException("arg5"); - if (arg6 == null) throw new ArgumentNullException("arg6"); - if (arg7 == null) throw new ArgumentNullException("arg7"); - - g_format_args[0] = arg0; - g_format_args[1] = arg1; - g_format_args[2] = arg2; - g_format_args[3] = arg3; - g_format_args[4] = arg4; - g_format_args[5] = arg5; - g_format_args[6] = arg6; - g_format_args[7] = arg7; - return internal_format(input, 8); - } - - public static gstring Format(string input, gstring arg0, gstring arg1, gstring arg2, gstring arg3, gstring arg4, gstring arg5, gstring arg6) { - if (arg0 == null) throw new ArgumentNullException("arg0"); - if (arg1 == null) throw new ArgumentNullException("arg1"); - if (arg2 == null) throw new ArgumentNullException("arg2"); - if (arg3 == null) throw new ArgumentNullException("arg3"); - if (arg4 == null) throw new ArgumentNullException("arg4"); - if (arg5 == null) throw new ArgumentNullException("arg5"); - if (arg6 == null) throw new ArgumentNullException("arg6"); - - g_format_args[0] = arg0; - g_format_args[1] = arg1; - g_format_args[2] = arg2; - g_format_args[3] = arg3; - g_format_args[4] = arg4; - g_format_args[5] = arg5; - g_format_args[6] = arg6; - return internal_format(input, 7); - } - - public static gstring Format(string input, gstring arg0, gstring arg1, gstring arg2, gstring arg3, gstring arg4, gstring arg5) { - if (arg0 == null) throw new ArgumentNullException("arg0"); - if (arg1 == null) throw new ArgumentNullException("arg1"); - if (arg2 == null) throw new ArgumentNullException("arg2"); - if (arg3 == null) throw new ArgumentNullException("arg3"); - if (arg4 == null) throw new ArgumentNullException("arg4"); - if (arg5 == null) throw new ArgumentNullException("arg5"); - - g_format_args[0] = arg0; - g_format_args[1] = arg1; - g_format_args[2] = arg2; - g_format_args[3] = arg3; - g_format_args[4] = arg4; - g_format_args[5] = arg5; - return internal_format(input, 6); - } - - public static gstring Format(string input, gstring arg0, gstring arg1, gstring arg2, gstring arg3, gstring arg4) { - if (arg0 == null) throw new ArgumentNullException("arg0"); - if (arg1 == null) throw new ArgumentNullException("arg1"); - if (arg2 == null) throw new ArgumentNullException("arg2"); - if (arg3 == null) throw new ArgumentNullException("arg3"); - if (arg4 == null) throw new ArgumentNullException("arg4"); - - g_format_args[0] = arg0; - g_format_args[1] = arg1; - g_format_args[2] = arg2; - g_format_args[3] = arg3; - g_format_args[4] = arg4; - return internal_format(input, 5); - } - - public static gstring Format(string input, gstring arg0, gstring arg1, gstring arg2, gstring arg3) { - if (arg0 == null) throw new ArgumentNullException("arg0"); - if (arg1 == null) throw new ArgumentNullException("arg1"); - if (arg2 == null) throw new ArgumentNullException("arg2"); - if (arg3 == null) throw new ArgumentNullException("arg3"); - - g_format_args[0] = arg0; - g_format_args[1] = arg1; - g_format_args[2] = arg2; - g_format_args[3] = arg3; - return internal_format(input, 4); - } - - public static gstring Format(string input, gstring arg0, gstring arg1, gstring arg2) { - if (arg0 == null) throw new ArgumentNullException("arg0"); - if (arg1 == null) throw new ArgumentNullException("arg1"); - if (arg2 == null) throw new ArgumentNullException("arg2"); - - g_format_args[0] = arg0; - g_format_args[1] = arg1; - g_format_args[2] = arg2; - return internal_format(input, 3); - } - - public static gstring Format(string input, gstring arg0, gstring arg1) { - if (arg0 == null) throw new ArgumentNullException("arg0"); - if (arg1 == null) throw new ArgumentNullException("arg1"); - - g_format_args[0] = arg0; - g_format_args[1] = arg1; - return internal_format(input, 2); - } - - public static gstring Format(string input, gstring arg0) { - if (arg0 == null) throw new ArgumentNullException("arg0"); - - g_format_args[0] = arg0; - return internal_format(input, 1); - } - - #endregion - - } - - public static class GStringExtensions { - public static bool IsNullOrEmpty(this gstring str) { - return str == null || str.Length == 0; - } - - public static bool IsPrefix(this gstring str, string value) { - return str.StartsWith(value); - } - - public static bool ispostfix(this gstring str, string postfix) { - return str.EndsWith(postfix); - } - } -} \ No newline at end of file diff --git a/Assets/SystemExtensions/gstring.cs.meta b/Assets/SystemExtensions/gstring.cs.meta deleted file mode 100644 index 4fbf4c4..0000000 --- a/Assets/SystemExtensions/gstring.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: d6a3a023271b82a4985d1bbcc86e6fa8 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YamlDotNet/Examples.meta b/Assets/YamlDotNet/Examples.meta deleted file mode 100644 index 88c04bf..0000000 --- a/Assets/YamlDotNet/Examples.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: f44c0df627c830e4d8e60525feb0c5a9 -folderAsset: yes -timeCreated: 1429640505 -licenseType: Store -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YamlDotNet/Examples/ConvertYamlToJson.cs b/Assets/YamlDotNet/Examples/ConvertYamlToJson.cs deleted file mode 100644 index 9a67d5b..0000000 --- a/Assets/YamlDotNet/Examples/ConvertYamlToJson.cs +++ /dev/null @@ -1,63 +0,0 @@ -// This file is part of YamlDotNet - A .NET library for YAML. -// Copyright (c) Antoine Aubry and contributors -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -// of the Software, and to permit persons to whom the Software is furnished to do -// so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using System.IO; -using Xunit.Abstractions; -using YamlDotNet.Samples.Helpers; -using YamlDotNet.Serialization; - -namespace YamlDotNet.Samples -{ - public class ConvertYamlToJson - { - private readonly ITestOutputHelper output; - - public ConvertYamlToJson(ITestOutputHelper output) - { - this.output = output; - } - - [Sample( - DisplayName = "Convert YAML to JSON", - Description = "Shows how to convert a YAML document to JSON." - )] - public void Main() - { - // convert string/file to YAML object - var r = new StringReader(@" -scalar: a scalar -sequence: - - one - - two -"); - var deserializer = new DeserializerBuilder().Build(); - var yamlObject = deserializer.Deserialize(r); - - var serializer = new SerializerBuilder() - .JsonCompatible() - .Build(); - - var json = serializer.Serialize(yamlObject); - - output.WriteLine(json); - } - } -} diff --git a/Assets/YamlDotNet/Examples/ConvertYamlToJson.cs.meta b/Assets/YamlDotNet/Examples/ConvertYamlToJson.cs.meta deleted file mode 100644 index d8ec920..0000000 --- a/Assets/YamlDotNet/Examples/ConvertYamlToJson.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 8614a029d313e6344a3ac93ddbd92dd2 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YamlDotNet/Examples/DeserializeObjectGraph.cs b/Assets/YamlDotNet/Examples/DeserializeObjectGraph.cs deleted file mode 100644 index 19b7593..0000000 --- a/Assets/YamlDotNet/Examples/DeserializeObjectGraph.cs +++ /dev/null @@ -1,165 +0,0 @@ -// This file is part of YamlDotNet - A .NET library for YAML. -// Copyright (c) Antoine Aubry and contributors -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -// of the Software, and to permit persons to whom the Software is furnished to do -// so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using System; -using System.Collections.Generic; -using System.IO; -using Xunit.Abstractions; -using YamlDotNet.Samples.Helpers; -using YamlDotNet.Serialization; -using YamlDotNet.Serialization.NamingConventions; - -namespace YamlDotNet.Samples -{ - public class DeserializeObjectGraph - { - private readonly ITestOutputHelper output; - - public DeserializeObjectGraph(ITestOutputHelper output) - { - this.output = output; - } - - [Sample( - DisplayName = "Deserializing an object graph", - Description = "Shows how to convert a YAML document to an object graph." - )] - public void Main() - { - var input = new StringReader(Document); - - var deserializer = new DeserializerBuilder() - .WithNamingConvention(CamelCaseNamingConvention.Instance) - .Build(); - - var order = deserializer.Deserialize(input); - - output.WriteLine("Order"); - output.WriteLine("-----"); - output.WriteLine(); - foreach (var item in order.Items) - { - output.WriteLine("{0}\t{1}\t{2}\t{3}", item.PartNo, item.Quantity, item.Price, item.Descrip); - } - output.WriteLine(); - - output.WriteLine("Shipping"); - output.WriteLine("--------"); - output.WriteLine(); - output.WriteLine(order.ShipTo.Street); - output.WriteLine(order.ShipTo.City); - output.WriteLine(order.ShipTo.State); - output.WriteLine(); - - output.WriteLine("Billing"); - output.WriteLine("-------"); - output.WriteLine(); - if (order.BillTo == order.ShipTo) - { - output.WriteLine("*same as shipping address*"); - } - else - { - output.WriteLine(order.ShipTo.Street); - output.WriteLine(order.ShipTo.City); - output.WriteLine(order.ShipTo.State); - } - output.WriteLine(); - - output.WriteLine("Delivery instructions"); - output.WriteLine("---------------------"); - output.WriteLine(); - output.WriteLine(order.SpecialDelivery); - } - - public class Order - { - public string Receipt { get; set; } - public DateTime Date { get; set; } - public Customer Customer { get; set; } - public List Items { get; set; } - - [YamlMember(Alias = "bill-to", ApplyNamingConventions = false)] - public Address BillTo { get; set; } - - [YamlMember(Alias = "ship-to", ApplyNamingConventions = false)] - public Address ShipTo { get; set; } - - public string SpecialDelivery { get; set; } - } - - public class Customer - { - public string Given { get; set; } - public string Family { get; set; } - } - - public class OrderItem - { - [YamlMember(Alias = "part_no", ApplyNamingConventions = false)] - public string PartNo { get; set; } - public string Descrip { get; set; } - public decimal Price { get; set; } - public int Quantity { get; set; } - } - - public class Address - { - public string Street { get; set; } - public string City { get; set; } - public string State { get; set; } - } - - private const string Document = @"--- - receipt: Oz-Ware Purchase Invoice - date: 2007-08-06 - customer: - given: Dorothy - family: Gale - - items: - - part_no: A4786 - descrip: Water Bucket (Filled) - price: 1.47 - quantity: 4 - - - part_no: E1628 - descrip: High Heeled ""Ruby"" Slippers - price: 100.27 - quantity: 1 - - bill-to: &id001 - street: |- - 123 Tornado Alley - Suite 16 - city: East Westville - state: KS - - ship-to: *id001 - - specialDelivery: > - Follow the Yellow Brick - Road to the Emerald City. - Pay no attention to the - man behind the curtain. -..."; - } -} diff --git a/Assets/YamlDotNet/Examples/DeserializeObjectGraph.cs.meta b/Assets/YamlDotNet/Examples/DeserializeObjectGraph.cs.meta deleted file mode 100644 index e0e1bb0..0000000 --- a/Assets/YamlDotNet/Examples/DeserializeObjectGraph.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: e214dfed74d68a24d86a603072744b69 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YamlDotNet/Examples/DeserializingMultipleDocuments.cs b/Assets/YamlDotNet/Examples/DeserializingMultipleDocuments.cs deleted file mode 100644 index f1af6c3..0000000 --- a/Assets/YamlDotNet/Examples/DeserializingMultipleDocuments.cs +++ /dev/null @@ -1,79 +0,0 @@ -// This file is part of YamlDotNet - A .NET library for YAML. -// Copyright (c) Antoine Aubry and contributors -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -// of the Software, and to permit persons to whom the Software is furnished to do -// so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using System.Collections.Generic; -using System.IO; -using Xunit.Abstractions; -using YamlDotNet.Core; -using YamlDotNet.Core.Events; -using YamlDotNet.Samples.Helpers; -using YamlDotNet.Serialization; - -namespace YamlDotNet.Samples -{ - public class DeserializingMultipleDocuments - { - private readonly ITestOutputHelper output; - - public DeserializingMultipleDocuments(ITestOutputHelper output) - { - this.output = output; - } - - [Sample( - DisplayName = "Deserializing multiple documents", - Description = "Explains how to load multiple YAML documents from a stream." - )] - public void Main() - { - var input = new StringReader(Document); - - var deserializer = new DeserializerBuilder().Build(); - - var parser = new Parser(input); - - // Consume the stream start event "manually" - parser.Consume(); - - while (parser.Accept(out var _)) - { - // Deserialize the document - var doc = deserializer.Deserialize>(parser); - - output.WriteLine("## Document"); - foreach (var item in doc) - { - output.WriteLine(item); - } - } - } - - private const string Document = @"--- -- Prisoner -- Goblet -- Phoenix ---- -- Memoirs -- Snow -- Ghost -..."; - } -} diff --git a/Assets/YamlDotNet/Examples/DeserializingMultipleDocuments.cs.meta b/Assets/YamlDotNet/Examples/DeserializingMultipleDocuments.cs.meta deleted file mode 100644 index df931fe..0000000 --- a/Assets/YamlDotNet/Examples/DeserializingMultipleDocuments.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: bc4609a10c8a43549a1ec4dfdb0990a4 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YamlDotNet/Examples/Helpers/ExampleRunner.cs b/Assets/YamlDotNet/Examples/Helpers/ExampleRunner.cs deleted file mode 100644 index d52fda4..0000000 --- a/Assets/YamlDotNet/Examples/Helpers/ExampleRunner.cs +++ /dev/null @@ -1,147 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Reflection; -using System.Text; -using Xunit.Abstractions; - -using UnityEngine; -using UnityEngine.Serialization; - -#if UNITY_EDITOR -using UnityEditor; -#endif - -namespace YamlDotNet.Samples.Helpers { - public class ExampleRunner : MonoBehaviour { - - private StringTestOutputHelper helper = new StringTestOutputHelper(); - - public string[] disabledTests = new string[] {}; - - private class StringTestOutputHelper : ITestOutputHelper { - private StringBuilder output = new StringBuilder(); - public void WriteLine() { - output.AppendLine(); - } - public void WriteLine(string value) { - output.AppendLine(value); - } - public void WriteLine(string format, params object[] args) { - output.AppendFormat(format, args); - output.AppendLine(); - } - - public override string ToString() { return output.ToString(); } - public void Clear() { output = new StringBuilder(); } - } - - public static string[] GetAllTestNames() { - bool skipMethods; - var results = new List(); - foreach (Type t in Assembly.GetExecutingAssembly().GetTypes()) { - if (t.Namespace == "YamlDotNet.Samples" && t.IsClass) { - skipMethods = false; - foreach (MethodInfo mi in t.GetMethods()) { - if (mi.Name == "Main") { - SampleAttribute sa = (SampleAttribute) Attribute.GetCustomAttribute(mi, typeof(SampleAttribute)); - if (sa != null) { - results.Add(t.Name); - skipMethods = true; - break; - } - } - if (skipMethods) break; - } - } - } - return results.ToArray(); - } - - public static string[] GetAllTestDisplayNames() { - bool skipMethods; - var results = new List(); - foreach (Type t in Assembly.GetExecutingAssembly().GetTypes()) { - if (t.Namespace == "YamlDotNet.Samples" && t.IsClass) { - skipMethods = false; - foreach (MethodInfo mi in t.GetMethods()) { - if (mi.Name == "Main") { - SampleAttribute sa = (SampleAttribute) Attribute.GetCustomAttribute(mi, typeof(SampleAttribute)); - if (sa != null) { - results.Add(sa.DisplayName); - skipMethods = true; - break; - } - } - if (skipMethods) break; - } - } - } - return results.ToArray(); - } - - private void Start() { - bool skipMethods; - foreach (Type t in Assembly.GetExecutingAssembly().GetTypes()) { - if (t.Namespace == "YamlDotNet.Samples" && t.IsClass && Array.IndexOf(disabledTests, t.Name) == -1) { - skipMethods = false; - foreach (MethodInfo mi in t.GetMethods()) { - if (mi.Name == "Main") { - SampleAttribute sa = (SampleAttribute) Attribute.GetCustomAttribute(mi, typeof(SampleAttribute)); - if (sa != null) { - helper.WriteLine("{0} - {1}", sa.DisplayName, sa.Description); - var testObject = t.GetConstructor(new Type[] { typeof(StringTestOutputHelper) }).Invoke(new object[] { helper }); - mi.Invoke(testObject, new object[] {}); - Debug.Log(helper.ToString()); - helper.Clear(); - skipMethods = true; - break; - } - } - if (skipMethods) break; - } - } - } - } - } - -#if UNITY_EDITOR - [CustomEditor(typeof(ExampleRunner))] - public class ExampleRunnerEditor : Editor { - private ExampleRunner runner; - private string[] allTests; - private string[] allDisplayNames; - private bool[] enabledTests; - - public void OnEnable() { - runner = (ExampleRunner) target; - - allTests = ExampleRunner.GetAllTestNames(); - allDisplayNames = ExampleRunner.GetAllTestDisplayNames(); - enabledTests = new bool[allTests.Length]; - for (int i = 0; i < allTests.Length; i++) - enabledTests[i] = Array.IndexOf(runner.disabledTests, allTests[i]) == -1; - } - - public override void OnInspectorGUI() { - int nextDisabledIndex = 0; - for (int i = 0; i < allTests.Length; i++) { - EditorGUI.BeginChangeCheck(); - if (!enabledTests[i]) - nextDisabledIndex++; - enabledTests[i] = EditorGUILayout.Toggle(allDisplayNames[i], enabledTests[i]); - if (EditorGUI.EndChangeCheck()) { - if (enabledTests[i]) { - var l = new List(runner.disabledTests); - l.Remove(allTests[i]); - runner.disabledTests = l.ToArray(); - } else { - var l = new List(runner.disabledTests); - l.Insert(nextDisabledIndex, allTests[i]); - runner.disabledTests = l.ToArray(); - } - } - } - } - } -#endif -} diff --git a/Assets/YamlDotNet/Examples/Helpers/ExampleRunner.cs.meta b/Assets/YamlDotNet/Examples/Helpers/ExampleRunner.cs.meta deleted file mode 100644 index f6e0177..0000000 --- a/Assets/YamlDotNet/Examples/Helpers/ExampleRunner.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: c7b67eba0ebbcd6418a881e3028c9901 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YamlDotNet/Examples/Helpers/ITestOutputHelper.cs b/Assets/YamlDotNet/Examples/Helpers/ITestOutputHelper.cs deleted file mode 100644 index 4b3943c..0000000 --- a/Assets/YamlDotNet/Examples/Helpers/ITestOutputHelper.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Xunit.Abstractions -{ - public interface ITestOutputHelper { - void WriteLine(); - void WriteLine(string value); - void WriteLine(string format, params object[] args); - } -} diff --git a/Assets/YamlDotNet/Examples/Helpers/ITestOutputHelper.cs.meta b/Assets/YamlDotNet/Examples/Helpers/ITestOutputHelper.cs.meta deleted file mode 100644 index 81cf805..0000000 --- a/Assets/YamlDotNet/Examples/Helpers/ITestOutputHelper.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 8bf0bb99b386041429154edb2eec127f -timeCreated: 1485606138 -licenseType: Store -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YamlDotNet/Examples/Helpers/SampleAttribute.cs b/Assets/YamlDotNet/Examples/Helpers/SampleAttribute.cs deleted file mode 100644 index 517093f..0000000 --- a/Assets/YamlDotNet/Examples/Helpers/SampleAttribute.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace YamlDotNet.Samples.Helpers -{ - /// - /// Marks a test as being a code sample. - /// - internal class SampleAttribute : System.Attribute - { - public string DisplayName { get; set; } - public string Description { get; set; } - } -} diff --git a/Assets/YamlDotNet/Examples/Helpers/SampleAttribute.cs.meta b/Assets/YamlDotNet/Examples/Helpers/SampleAttribute.cs.meta deleted file mode 100644 index df431e4..0000000 --- a/Assets/YamlDotNet/Examples/Helpers/SampleAttribute.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: de45c0081a4f5e7478f400ebc2446ce5 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YamlDotNet/Examples/LoadingAYamlStream.cs b/Assets/YamlDotNet/Examples/LoadingAYamlStream.cs deleted file mode 100644 index a546c3e..0000000 --- a/Assets/YamlDotNet/Examples/LoadingAYamlStream.cs +++ /dev/null @@ -1,106 +0,0 @@ -// This file is part of YamlDotNet - A .NET library for YAML. -// Copyright (c) Antoine Aubry and contributors -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -// of the Software, and to permit persons to whom the Software is furnished to do -// so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using System.IO; -using Xunit.Abstractions; -using YamlDotNet.RepresentationModel; -using YamlDotNet.Samples.Helpers; - -namespace YamlDotNet.Samples -{ - public class LoadingAYamlStream - { - private readonly ITestOutputHelper output; - - public LoadingAYamlStream(ITestOutputHelper output) - { - this.output = output; - } - - [Sample( - DisplayName = "Loading a YAML Stream", - Description = "Explains how to load YAML using the representation model." - )] - public void Main() - { - // Setup the input - var input = new StringReader(Document); - - // Load the stream - var yaml = new YamlStream(); - yaml.Load(input); - - // Examine the stream - var mapping = - (YamlMappingNode)yaml.Documents[0].RootNode; - - foreach (var entry in mapping.Children) - { - output.WriteLine(((YamlScalarNode)entry.Key).Value); - } - - // List all the items - var items = (YamlSequenceNode)mapping.Children[new YamlScalarNode("items")]; - foreach (YamlMappingNode item in items) - { - output.WriteLine( - "{0}\t{1}", - item.Children[new YamlScalarNode("part_no")], - item.Children[new YamlScalarNode("descrip")] - ); - } - } - - private const string Document = @"--- - receipt: Oz-Ware Purchase Invoice - date: 2007-08-06 - customer: - given: Dorothy - family: Gale - - items: - - part_no: A4786 - descrip: Water Bucket (Filled) - price: 1.47 - quantity: 4 - - - part_no: E1628 - descrip: High Heeled ""Ruby"" Slippers - price: 100.27 - quantity: 1 - - bill-to: &id001 - street: | - 123 Tornado Alley - Suite 16 - city: East Westville - state: KS - - ship-to: *id001 - - specialDelivery: > - Follow the Yellow Brick - Road to the Emerald City. - Pay no attention to the - man behind the curtain. -..."; - } -} diff --git a/Assets/YamlDotNet/Examples/LoadingAYamlStream.cs.meta b/Assets/YamlDotNet/Examples/LoadingAYamlStream.cs.meta deleted file mode 100644 index 69f370e..0000000 --- a/Assets/YamlDotNet/Examples/LoadingAYamlStream.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 28fd354d37e1bcb43baaff38988830a4 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YamlDotNet/Examples/SerializeObjectGraph.cs b/Assets/YamlDotNet/Examples/SerializeObjectGraph.cs deleted file mode 100644 index 4642307..0000000 --- a/Assets/YamlDotNet/Examples/SerializeObjectGraph.cs +++ /dev/null @@ -1,124 +0,0 @@ -// This file is part of YamlDotNet - A .NET library for YAML. -// Copyright (c) Antoine Aubry and contributors -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -// of the Software, and to permit persons to whom the Software is furnished to do -// so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using System; -using Xunit.Abstractions; -using YamlDotNet.Samples.Helpers; -using YamlDotNet.Serialization; - -namespace YamlDotNet.Samples -{ - public class SerializeObjectGraph - { - private readonly ITestOutputHelper output; - - public SerializeObjectGraph(ITestOutputHelper output) - { - this.output = output; - } - - [Sample( - DisplayName = "Serializing an object graph", - Description = "Shows how to convert an object to its YAML representation." - )] - public void Main() - { - var address = new Address - { - street = "123 Tornado Alley\nSuite 16", - city = "East Westville", - state = "KS" - }; - - var receipt = new Receipt - { - receipt = "Oz-Ware Purchase Invoice", - date = new DateTime(2007, 8, 6), - customer = new Customer - { - given = "Dorothy", - family = "Gale" - }, - items = new Item[] - { - new Item - { - part_no = "A4786", - descrip = "Water Bucket (Filled)", - price = 1.47M, - quantity = 4 - }, - new Item - { - part_no = "E1628", - descrip = "High Heeled \"Ruby\" Slippers", - price = 100.27M, - quantity = 1 - } - }, - bill_to = address, - ship_to = address, - specialDelivery = "Follow the Yellow Brick\n" + - "Road to the Emerald City.\n" + - "Pay no attention to the\n" + - "man behind the curtain." - }; - - var serializer = new SerializerBuilder().Build(); - var yaml = serializer.Serialize(receipt); - output.WriteLine(yaml); - } - } - -#pragma warning disable IDE1006 // Naming Styles - public class Address - { - public string street { get; set; } - public string city { get; set; } - public string state { get; set; } - } - - public class Receipt - { - public string receipt { get; set; } - public DateTime date { get; set; } - public Customer customer { get; set; } - public Item[] items { get; set; } - public Address bill_to { get; set; } - public Address ship_to { get; set; } - public string specialDelivery { get; set; } - } - - public class Customer - { - public string given { get; set; } - public string family { get; set; } - } - - public class Item - { - public string part_no { get; set; } - public string descrip { get; set; } - public decimal price { get; set; } - public int quantity { get; set; } - } -#pragma warning restore IDE1006 // Naming Styles -} diff --git a/Assets/YamlDotNet/Examples/SerializeObjectGraph.cs.meta b/Assets/YamlDotNet/Examples/SerializeObjectGraph.cs.meta deleted file mode 100644 index 2001daa..0000000 --- a/Assets/YamlDotNet/Examples/SerializeObjectGraph.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: dc19598abe764044f9baf52c06f5b8c9 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: