From 4ea5071ea4b7cf581fcbe3a0bb81b02b7d7d4157 Mon Sep 17 00:00:00 2001 From: Virgile Bello Date: Wed, 2 Sep 2015 15:24:14 +0900 Subject: [PATCH] Added Descriptor Category in ITypeDescriptor. --- SharpYaml/Serialization/DescriptorCategory.cs | 87 +++++++++++++++++++ .../Descriptors/ArrayDescriptor.cs | 5 ++ .../Descriptors/CollectionDescriptor.cs | 5 ++ .../Descriptors/DictionaryDescriptor.cs | 5 ++ .../Descriptors/NullableDescriptor.cs | 5 ++ .../Descriptors/ObjectDescriptor.cs | 5 ++ .../Descriptors/PrimitiveDescriptor.cs | 5 ++ SharpYaml/Serialization/ITypeDescriptor.cs | 6 ++ SharpYaml/SharpYAml.csproj | 1 + 9 files changed, 124 insertions(+) create mode 100644 SharpYaml/Serialization/DescriptorCategory.cs diff --git a/SharpYaml/Serialization/DescriptorCategory.cs b/SharpYaml/Serialization/DescriptorCategory.cs new file mode 100644 index 0000000..9a94f8b --- /dev/null +++ b/SharpYaml/Serialization/DescriptorCategory.cs @@ -0,0 +1,87 @@ +// Copyright (c) 2015 SharpYaml - Alexandre Mutel +// +// 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. +// +// ------------------------------------------------------------------------------- +// SharpYaml is a fork of YamlDotNet https://github.com/aaubry/YamlDotNet +// published with the following license: +// ------------------------------------------------------------------------------- +// +// Copyright (c) 2008, 2009, 2010, 2011, 2012 Antoine Aubry +// +// 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. +namespace SharpYaml.Serialization +{ + /// + /// A category used by . + /// + public enum DescriptorCategory + { + /// + /// A primitive. + /// + Primitive, + + /// + /// A collection. + /// + Collection, + + /// + /// An array + /// + Array, + + /// + /// A dictionary + /// + Dictionary, + + /// + /// An object + /// + Object, + + /// + /// A nullable value + /// + Nullable, + + /// + /// A custom descriptor. + /// + Custom + } +} \ No newline at end of file diff --git a/SharpYaml/Serialization/Descriptors/ArrayDescriptor.cs b/SharpYaml/Serialization/Descriptors/ArrayDescriptor.cs index 1496e39..c43de9a 100644 --- a/SharpYaml/Serialization/Descriptors/ArrayDescriptor.cs +++ b/SharpYaml/Serialization/Descriptors/ArrayDescriptor.cs @@ -80,6 +80,11 @@ namespace SharpYaml.Serialization.Descriptors toArrayMethod = listType.GetMethod("ToArray"); } + public override DescriptorCategory Category + { + get { return DescriptorCategory.Array; } + } + /// /// Gets the type of the array element. /// diff --git a/SharpYaml/Serialization/Descriptors/CollectionDescriptor.cs b/SharpYaml/Serialization/Descriptors/CollectionDescriptor.cs index 6c11ddf..044c8c6 100644 --- a/SharpYaml/Serialization/Descriptors/CollectionDescriptor.cs +++ b/SharpYaml/Serialization/Descriptors/CollectionDescriptor.cs @@ -108,6 +108,11 @@ namespace SharpYaml.Serialization.Descriptors IsPureCollection = Count == 0; } + public override DescriptorCategory Category + { + get { return DescriptorCategory.Collection; } + } + /// /// Gets or sets the type of the element. /// diff --git a/SharpYaml/Serialization/Descriptors/DictionaryDescriptor.cs b/SharpYaml/Serialization/Descriptors/DictionaryDescriptor.cs index 323b810..554424d 100644 --- a/SharpYaml/Serialization/Descriptors/DictionaryDescriptor.cs +++ b/SharpYaml/Serialization/Descriptors/DictionaryDescriptor.cs @@ -102,6 +102,11 @@ namespace SharpYaml.Serialization.Descriptors IsPureDictionary = Count == 0; } + public override DescriptorCategory Category + { + get { return DescriptorCategory.Dictionary; } + } + /// /// Gets a value indicating whether this instance is generic dictionary. /// diff --git a/SharpYaml/Serialization/Descriptors/NullableDescriptor.cs b/SharpYaml/Serialization/Descriptors/NullableDescriptor.cs index faed282..10d87b4 100644 --- a/SharpYaml/Serialization/Descriptors/NullableDescriptor.cs +++ b/SharpYaml/Serialization/Descriptors/NullableDescriptor.cs @@ -70,6 +70,11 @@ namespace SharpYaml.Serialization.Descriptors UnderlyingType = Nullable.GetUnderlyingType(type); } + public override DescriptorCategory Category + { + get { return DescriptorCategory.Nullable; } + } + /// /// Gets the type underlying type T of the nullable /// diff --git a/SharpYaml/Serialization/Descriptors/ObjectDescriptor.cs b/SharpYaml/Serialization/Descriptors/ObjectDescriptor.cs index 0abf07f..bebce2a 100644 --- a/SharpYaml/Serialization/Descriptors/ObjectDescriptor.cs +++ b/SharpYaml/Serialization/Descriptors/ObjectDescriptor.cs @@ -185,6 +185,11 @@ namespace SharpYaml.Serialization.Descriptors get { return members == null ? 0 : members.Count; } } + public virtual DescriptorCategory Category + { + get { return DescriptorCategory.Object; } + } + public bool HasMembers { get { return members.Count > 0; } diff --git a/SharpYaml/Serialization/Descriptors/PrimitiveDescriptor.cs b/SharpYaml/Serialization/Descriptors/PrimitiveDescriptor.cs index 18a209c..705aeca 100644 --- a/SharpYaml/Serialization/Descriptors/PrimitiveDescriptor.cs +++ b/SharpYaml/Serialization/Descriptors/PrimitiveDescriptor.cs @@ -92,6 +92,11 @@ namespace SharpYaml.Serialization.Descriptors } } + public override DescriptorCategory Category + { + get { return DescriptorCategory.Primitive; } + } + /// /// Determines whether the specified type is a primitive. /// diff --git a/SharpYaml/Serialization/ITypeDescriptor.cs b/SharpYaml/Serialization/ITypeDescriptor.cs index 446db9d..46c880d 100644 --- a/SharpYaml/Serialization/ITypeDescriptor.cs +++ b/SharpYaml/Serialization/ITypeDescriptor.cs @@ -70,6 +70,12 @@ namespace SharpYaml.Serialization /// The member count. int Count { get; } + /// + /// Gets the category of this descriptor. + /// + /// The category. + DescriptorCategory Category { get; } + /// /// Gets a value indicating whether this instance has members. /// diff --git a/SharpYaml/SharpYAml.csproj b/SharpYaml/SharpYAml.csproj index dff9e46..7e29746 100644 --- a/SharpYaml/SharpYAml.csproj +++ b/SharpYaml/SharpYAml.csproj @@ -59,6 +59,7 @@ +