Click here to Skip to main content
15,886,067 members
Articles / Programming Languages / Markdown

APJSON

Rate me:
Please Sign up or sign in to vote.
4.67/5 (5 votes)
28 Aug 2013CPOL13 min read 41.6K   1.2K   34  
This is an alternative for "fastJSON"
using System;
using Apolyton.FastJson.Registry;

namespace Apolyton.FastJson.Registry
{
    /// <summary>
    /// Represents the internal property info.
    /// </summary>
    internal struct JsonPropertyInfo
    {
        /// <summary>
        /// Specifies the type of the member.
        /// </summary>
        public Type PropertyOrFieldType;
        
        /// <summary>
        /// Represents the non-nullable value behind the primary type. Normally, a cast of a value to the primary type should be possible.
        /// </summary>
        /// <example>
        /// typeof(Double?) for instance is Nullable{double} with NullableType = typeof(double).
        /// </example>
        public Type NullableType;
        
        /// <summary>
        /// Represents the first item type for generic enumerations and collections (relevant for performance).
        /// </summary>
        public Type GenericItemType;

        /// <summary>
        /// Represents all generic types of the Primary Type.
        /// </summary>
        public Type[] GenericTypes;

        /// <summary>
        /// Specifies the property of field name.
        /// </summary>
        public string PropertyOrFieldName;

        /// <summary>
        /// Specifies the json field name for the given property.
        /// </summary>
        public string JsonFieldName;

        /// <summary>
        /// True, if member type is a dictionary.
        /// </summary>
        public bool IsDictionary;

        /// <summary>
        /// Determines, if member type is value type.
        /// </summary>
        public bool IsValueType;

        /// <summary>
        /// Determines, if the type is a generic type.
        /// </summary>
        public bool IsGenericType;

        /// <summary>
        /// Determines, if the member type is an array.
        /// </summary>
        public bool IsArray;

        /// <summary>
        /// Determines, if the member type is a byte array.
        /// </summary>
        public bool IsByteArray;

        /// <summary>
        /// Detemines, if the member type is a guid.
        /// </summary>
        public bool IsGuid;

        /// <summary>
        /// Determines, if the member type is a data set.
        /// </summary>
        public bool IsDataSet;

        /// <summary>
        /// Determines, if the member type is a data table.
        /// </summary>
        public bool IsDataTable;

        /// <summary>
        /// Determines, if the member type is a hash table.
        /// </summary>
        public bool IsHashtable;

        /// <summary>
        /// Determines, if the member type is an Enum.
        /// </summary>
        public bool IsEnum;

        /// <summary>
        /// Determines, if the member type is a date time.
        /// </summary>
        public bool IsDateTime;

        /// <summary>
        /// Determines, if the member type is an int.
        /// </summary>
        public bool IsInt;

        /// <summary>
        /// Determines, if the member type is a long.
        /// </summary>
        public bool IsLong;

        /// <summary>
        /// Determines, if the member type is a string.
        /// </summary>
        public bool IsString;

        /// <summary>
        /// Determines, if the member type is a bool.
        /// </summary>
        public bool IsBool;

        /// <summary>
        /// Determines, if the member type is a class.
        /// </summary>
        public bool IsClass;

        /// <summary>
        /// Determines, if the member type is a string dictionary.
        /// </summary>
        public bool IsStringDictionary;

        /// <summary>
        /// Represents a fast set function for the property or field.
        /// </summary>
        public GenericSetterHandler Setter;

        /// <summary>
        /// Represents a fast get function for the property or field.
        /// </summary>
        public GenericGetterHandler Getter;
        
        /// <summary>
        /// Determines, if the member type is a custom type.
        /// </summary>
        public bool IsCustomType;

        /// <summary>
        /// Determines, if the member type can be written to.
        /// </summary>
        public bool CanWrite;

        /// <summary>
        /// Specifies the default value of the property. For nullable types it is 'null', for other types determined throught the activator.
        /// </summary>
        public object DefaultValue;

        /// <summary>
        /// Returns a lightweight object, which describes the serialization criteria.
        /// </summary>
        /// <returns></returns>
        internal JsonSerializationInfo ToSerializationInfo()
        {
            JsonSerializationInfo info = new JsonSerializationInfo();
            info.JsonFieldName = JsonFieldName;
            info.MemberName = PropertyOrFieldName;
            info.MemberType = PropertyOrFieldType;

            if (GenericTypes == null)
            {
                info.MemberDisplayType = PropertyOrFieldType.Name;
            }
            else
            {
                info.MemberDisplayType = String.Format("{0}<{1}>", PropertyOrFieldType.Name, GenericTypes[0].Name);
            }

            return info;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions