Click here to Skip to main content
15,891,375 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.7K   1.2K   34  
This is an alternative for "fastJSON"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Apolyton.FastJson.Data;
using System.Diagnostics;

namespace Apolyton.FastJson.Data
{
    /// <summary>
    /// Represents a json object.
    /// </summary>
    public interface IJsonValue
    {
        /// <summary>
        /// Gets the count of the members.
        /// </summary>
        /// <exception cref="NotSupportedException">If item is not enumerable and has no count.</exception>
        int Count { get; }

        /// <summary>
        /// Gets the json value type.
        /// </summary>
        JsonType Type { get; }

        /// <summary>
        /// Gets the value at the specified index.
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        /// <exception cref="NotSupportedException">If item is not a json array.</exception>
        IJsonValue this[int i] { get; }

        /// <summary>
        /// Gets the key at the specified index.
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        /// <exception cref="NotSupportedException">If item is not a json object.</exception>s
        IJsonValue this[String key] { get; }

        /// <summary>
        /// Gets the value as bool.
        /// </summary>
        /// <exception cref="NotSupportedException">If json value does not support this conversion</exception>
        /// <exception cref="InvalidCastException">If json value failed in trying to cast its interal value to this type.</exception>
        [DebuggerDisplay("Click to expand. This operation has side effects.")]
        Boolean AsBool{get;}

        /// <summary>
        /// Gets the value as bool.
        /// </summary>
        /// <exception cref="NotSupportedException">If json value does not support this conversion</exception>
        /// <exception cref="InvalidCastException">If json value failed in trying to cast its interal value to this type.</exception>
        [DebuggerDisplay("Click to expand. This operation has side effects.")]
        DateTime AsDateTime { get; }

        /// <summary>
        /// Gets the value as double precision float.
        /// </summary>
        /// <exception cref="NotSupportedException">If json value does not support this conversion</exception>
        /// <exception cref="InvalidCastException">If json value failed in trying to cast its interal value to this type.</exception>
        [DebuggerDisplay("Click to expand. This operation has side effects.")]
        Double AsDouble { get; }

        /// <summary>
        /// Gets the value as single precision float.
        /// </summary>
        /// <exception cref="NotSupportedException">If json value does not support this conversion</exception>
        /// <exception cref="InvalidCastException">If json value failed in trying to cast its interal value to this type.</exception>
        [DebuggerDisplay("Click to expand. This operation has side effects.")]
        float AsSingle{ get; }

        /// <summary>
        /// Gets the value as guid.
        /// </summary>
        /// <exception cref="NotSupportedException">If json value does not support this conversion</exception>
        /// <exception cref="InvalidCastException">If json value failed in trying to cast its interal value to this type.</exception>
        [DebuggerDisplay("Click to expand. This operation has side effects.")]
        Guid AsGuid { get; }

        /// <summary>
        /// Gets the value as integer.
        /// </summary>
        /// <exception cref="NotSupportedException">If json value does not support this conversion</exception>
        /// <exception cref="InvalidCastException">If json value failed in trying to cast its interal value to this type.</exception>
        [DebuggerDisplay("Click to expand. This operation has side effects.")]
        Int32 AsInteger { get; }

        /// <summary>
        /// Gets the value as long integer.
        /// </summary>
        /// <exception cref="NotSupportedException">If json value does not support this conversion</exception>
        /// <exception cref="InvalidCastException">If json value failed in trying to cast its interal value to this type.</exception>
        [DebuggerDisplay("Click to expand. This operation has side effects.")]
        Int64 AsLong { get; }

        /// <summary>
        /// Gets the value as short integer.
        /// </summary>
        /// <exception cref="NotSupportedException">If json value does not support this conversion</exception>
        /// <exception cref="InvalidCastException">If json value failed in trying to cast its interal value to this type.</exception>
        [DebuggerDisplay("Click to expand. This operation has side effects.")]
        Int16 AsShort { get; }

        /// <summary>
        /// Gets the value as string.
        /// </summary>
        /// <exception cref="NotSupportedException">If json value does not support this conversion</exception>
        /// <exception cref="InvalidCastException">If json value failed in trying to cast its interal value to this type.</exception>
        [DebuggerDisplay("Click to expand. This operation has side effects.")]
        String AsString { get; }

        /// <summary>
        /// Gets the value as time span.
        /// </summary>
        /// <exception cref="NotSupportedException">If json value does not support this conversion</exception>
        /// <exception cref="InvalidCastException">If json value failed in trying to cast its interal value to this type.</exception>
        [DebuggerDisplay("Click to expand. This operation has side effects.")]
        TimeSpan AsTimeSpan { get; }
    }
}

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