Added Descriptor Category in ITypeDescriptor.

This commit is contained in:
Virgile Bello 2015-09-02 15:24:14 +09:00
Родитель 8b082839bb
Коммит 4ea5071ea4
9 изменённых файлов: 124 добавлений и 0 удалений

Просмотреть файл

@ -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
{
/// <summary>
/// A category used by <see cref="ITypeDescriptor"/>.
/// </summary>
public enum DescriptorCategory
{
/// <summary>
/// A primitive.
/// </summary>
Primitive,
/// <summary>
/// A collection.
/// </summary>
Collection,
/// <summary>
/// An array
/// </summary>
Array,
/// <summary>
/// A dictionary
/// </summary>
Dictionary,
/// <summary>
/// An object
/// </summary>
Object,
/// <summary>
/// A nullable value
/// </summary>
Nullable,
/// <summary>
/// A custom descriptor.
/// </summary>
Custom
}
}

Просмотреть файл

@ -80,6 +80,11 @@ namespace SharpYaml.Serialization.Descriptors
toArrayMethod = listType.GetMethod("ToArray");
}
public override DescriptorCategory Category
{
get { return DescriptorCategory.Array; }
}
/// <summary>
/// Gets the type of the array element.
/// </summary>

Просмотреть файл

@ -108,6 +108,11 @@ namespace SharpYaml.Serialization.Descriptors
IsPureCollection = Count == 0;
}
public override DescriptorCategory Category
{
get { return DescriptorCategory.Collection; }
}
/// <summary>
/// Gets or sets the type of the element.
/// </summary>

Просмотреть файл

@ -102,6 +102,11 @@ namespace SharpYaml.Serialization.Descriptors
IsPureDictionary = Count == 0;
}
public override DescriptorCategory Category
{
get { return DescriptorCategory.Dictionary; }
}
/// <summary>
/// Gets a value indicating whether this instance is generic dictionary.
/// </summary>

Просмотреть файл

@ -70,6 +70,11 @@ namespace SharpYaml.Serialization.Descriptors
UnderlyingType = Nullable.GetUnderlyingType(type);
}
public override DescriptorCategory Category
{
get { return DescriptorCategory.Nullable; }
}
/// <summary>
/// Gets the type underlying type T of the nullable <see cref="Nullable{T}"/>
/// </summary>

Просмотреть файл

@ -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; }

Просмотреть файл

@ -92,6 +92,11 @@ namespace SharpYaml.Serialization.Descriptors
}
}
public override DescriptorCategory Category
{
get { return DescriptorCategory.Primitive; }
}
/// <summary>
/// Determines whether the specified type is a primitive.
/// </summary>

Просмотреть файл

@ -70,6 +70,12 @@ namespace SharpYaml.Serialization
/// <value>The member count.</value>
int Count { get; }
/// <summary>
/// Gets the category of this descriptor.
/// </summary>
/// <value>The category.</value>
DescriptorCategory Category { get; }
/// <summary>
/// Gets a value indicating whether this instance has members.
/// </summary>

Просмотреть файл

@ -59,6 +59,7 @@
<Compile Include="MemoryParser.cs" />
<Compile Include="Serialization\AnchorEventEmitter.cs" />
<Compile Include="Serialization\DefaultNamingConvention.cs" />
<Compile Include="Serialization\DescriptorCategory.cs" />
<Compile Include="Serialization\Descriptors\DefaultKeyComparer.cs" />
<Compile Include="Serialization\FlatNamingConvention.cs" />
<Compile Include="Serialization\IMemberNamingConvention.cs" />