Exemple #1
0
        // Edited to fix issues with null List<Guid> properties in response objects
        public static void RegisterElement <T, TElement>()
        {
            RegisterBuiltin <TElement>();
            DeserializeDictionary <JsonTypeSerializer> .ParseDictionary <T, TElement>(null, null, null, null);

            DeserializeDictionary <JsonTypeSerializer> .ParseDictionary <TElement, T>(null, null, null, null);

            ToStringDictionaryMethods <T, TElement, JsonTypeSerializer> .WriteIDictionary(null, null, null, null);

            ToStringDictionaryMethods <TElement, T, JsonTypeSerializer> .WriteIDictionary(null, null, null, null);

            // Include List deserialisations from the Register<> method above.  This solves issue where List<Guid> properties on responses deserialise to null.
            // No idea why this is happening because there is no visible exception raised.  Suspect MonoTouch is swallowing an AOT exception somewhere.
            DeserializeArrayWithElements <TElement, JsonTypeSerializer> .ParseGenericArray(null, null);

            DeserializeListWithElements <TElement, JsonTypeSerializer> .ParseGenericList(null, null, null);

            // Cannot use the line below for some unknown reason - when trying to compile to run on device, mtouch bombs during native code compile.
            // Something about this line or its inner workings is offensive to mtouch. Luckily this was not needed for my List<Guide> issue.
            // DeserializeCollection<JsonTypeSerializer>.ParseCollection<TElement>(null, null, null);

            TranslateListWithElements <TElement> .LateBoundTranslateToGenericICollection(null, typeof(List <TElement>));

            TranslateListWithConvertibleElements <TElement, TElement> .LateBoundTranslateToGenericICollection(null, typeof(List <TElement>));
        }
Exemple #2
0
        public static void Register <T>()
        {
            var i          = 0;
            var serializer = JsonTypeSerializer.Instance;

            if (new List <T>() != null)
            {
                i++;
            }
            if (new T[0] != null)
            {
                i++;
            }
            if (serializer.GetParseFn <T>() != null)
            {
                i++;
            }
            if (DeserializeArray <T[], JsonTypeSerializer> .Parse != null)
            {
                i++;
            }

            JsConfig <T> .ExcludeTypeInfo = false;
            //JsConfig<T>.SerializeFn = arg => "";
            //JsConfig<T>.DeSerializeFn = arg => default(T);

            DeserializeArrayWithElements <T, JsonTypeSerializer> .ParseGenericArray(null, null);

            DeserializeCollection <JsonTypeSerializer> .ParseCollection <T>(null, null, null);

            DeserializeListWithElements <T, JsonTypeSerializer> .ParseGenericList(null, null, null);

            SpecializedQueueElements <T> .ConvertToQueue(null);

            SpecializedQueueElements <T> .ConvertToStack(null);

            WriteListsOfElements <T, JsonTypeSerializer> .WriteList(null, null);

            WriteListsOfElements <T, JsonTypeSerializer> .WriteIList(null, null);

            WriteListsOfElements <T, JsonTypeSerializer> .WriteEnumerable(null, null);

            WriteListsOfElements <T, JsonTypeSerializer> .WriteListValueType(null, null);

            WriteListsOfElements <T, JsonTypeSerializer> .WriteIListValueType(null, null);

            JsonReader <T> .Parse(null);

            JsonWriter <T> .WriteFn();

            TranslateListWithElements <T> .LateBoundTranslateToGenericICollection(null, null);

            TranslateListWithConvertibleElements <T, T> .LateBoundTranslateToGenericICollection(null, null);

            QueryStringWriter <T> .WriteObject(null, null);
        }
Exemple #3
0
    /// <summary>
    /// Parses the collection.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="value">The value.</param>
    /// <param name="createType">Type of the create.</param>
    /// <param name="parseFn">The parse function.</param>
    /// <returns>ICollection&lt;T&gt;.</returns>
    public static ICollection <T> ParseCollection <T>(ReadOnlySpan <char> value, Type createType, ParseStringSpanDelegate parseFn)
    {
        if (value.IsEmpty)
        {
            return(null);
        }

        var items = DeserializeArrayWithElements <T, TSerializer> .ParseGenericArray(value, parseFn);

        return(CollectionExtensions.CreateAndPopulate(createType, items));
    }
Exemple #4
0
    public static void InitAot <T>()
    {
        var hold = DeserializeBuiltin <T> .Parse;

        hold = DeserializeArray <T[], TSerializer> .Parse;
        DeserializeType <TSerializer> .ExtractType(default(ReadOnlySpan <char>));

        DeserializeArrayWithElements <T, TSerializer> .ParseGenericArray(default(ReadOnlySpan <char>), null);

        DeserializeCollection <TSerializer> .ParseCollection <T>(default(ReadOnlySpan <char>), null, null);

        DeserializeListWithElements <T, TSerializer> .ParseGenericList(default(ReadOnlySpan <char>), null, null);
    }
        public static void Register <T>()
        {
            var i          = 0;
            var serializer = JsonTypeSerializer.Instance;

            if (new List <T>() != null)
            {
                i++;
            }
            if (new T[0] != null)
            {
                i++;
            }
            if (serializer.GetParseFn <T>() != null)
            {
                i++;
            }
            if (DeserializeArray <T[], JsonTypeSerializer> .Parse != null)
            {
                i++;
            }

            DeserializeArrayWithElements <T, JsonTypeSerializer> .ParseGenericArray(null, null);

            DeserializeCollection <JsonTypeSerializer> .ParseCollection <T>(null, null, null);

            DeserializeListWithElements <T, JsonTypeSerializer> .ParseGenericList(null, null, null);

            SpecializedQueueElements <T> .ConvertToQueue(null);

            SpecializedQueueElements <T> .ConvertToStack(null);

            WriteListsOfElements <T, JsonTypeSerializer> .WriteList(null, null);

            WriteListsOfElements <T, JsonTypeSerializer> .WriteIList(null, null);

            WriteListsOfElements <T, JsonTypeSerializer> .WriteEnumerable(null, null);

            WriteListsOfElements <T, JsonTypeSerializer> .WriteListValueType(null, null);

            WriteListsOfElements <T, JsonTypeSerializer> .WriteIListValueType(null, null);

            JsonReader <T> .Parse(null);

            JsonWriter <T> .WriteFn();

            TranslateListWithElements <T> .LateBoundTranslateToGenericICollection(null, null);

            TranslateListWithConvertibleElements <T, T> .LateBoundTranslateToGenericICollection(null, null);
        }
Exemple #6
0
    /// <summary>
    /// Parses the string collection.
    /// </summary>
    /// <param name="value">The value.</param>
    /// <param name="createType">Type of the create.</param>
    /// <returns>ICollection&lt;System.String&gt;.</returns>
    public static ICollection <string> ParseStringCollection(ReadOnlySpan <char> value, Type createType)
    {
        var items = DeserializeArrayWithElements <string, TSerializer> .ParseGenericArray(value, Serializer.ParseString);

        return(CollectionExtensions.CreateAndPopulate(createType, items));
    }
Exemple #7
0
    /// <summary>
    /// Parses the int collection.
    /// </summary>
    /// <param name="value">The value.</param>
    /// <param name="createType">Type of the create.</param>
    /// <returns>ICollection&lt;System.Int32&gt;.</returns>
    public static ICollection <int> ParseIntCollection(ReadOnlySpan <char> value, Type createType)
    {
        var items = DeserializeArrayWithElements <int, TSerializer> .ParseGenericArray(value, x => x.ParseInt32());

        return(CollectionExtensions.CreateAndPopulate(createType, items));
    }
            internal static int Register <T, TSerializer>() where TSerializer : ITypeSerializer
            {
                var i = 0;

                if (JsonWriter <T> .WriteFn() != null)
                {
                    i++;
                }
                if (JsonWriter.Instance.GetWriteFn <T>() != null)
                {
                    i++;
                }
                if (JsonReader.Instance.GetParseFn <T>() != null)
                {
                    i++;
                }
                if (JsonReader <T> .Parse(null) != null)
                {
                    i++;
                }
                if (JsonReader <T> .GetParseFn() != null)
                {
                    i++;
                }
                //if (JsWriter.GetTypeSerializer<JsonTypeSerializer>().GetWriteFn<T>() != null) i++;
                if (new List <T>() != null)
                {
                    i++;
                }
                if (new T[0] != null)
                {
                    i++;
                }

                JsConfig <T> .ExcludeTypeInfo = false;

                if (JsConfig <T> .OnDeserializedFn != null)
                {
                    i++;
                }
                if (JsConfig <T> .HasDeserializeFn)
                {
                    i++;
                }
                if (JsConfig <T> .SerializeFn != null)
                {
                    i++;
                }
                if (JsConfig <T> .DeSerializeFn != null)
                {
                    i++;
                }
                //JsConfig<T>.SerializeFn = arg => "";
                //JsConfig<T>.DeSerializeFn = arg => default(T);
                if (TypeConfig <T> .Properties != null)
                {
                    i++;
                }



                // zhaojh
                //if (  WriteType<T, TSerializer>.testsAOT != null ) i++;

                // AOT for ServiceStack.Text.Common.ParseMethodUtilities+<GetParseFn>
                Func <string, T> t = x => default(T);

                DeserializeType <TSerializer> .ParseAbstractType <T> (null);



//*
                if (WriteType <T, TSerializer> .Write != null)
                {
                    i++;
                }
                if (WriteType <object, TSerializer> .Write != null)
                {
                    i++;
                }

                if (DeserializeBuiltin <T> .Parse != null)
                {
                    i++;
                }
                if (DeserializeArray <T[], TSerializer> .Parse != null)
                {
                    i++;
                }
                DeserializeType <TSerializer> .ExtractType(null);

                DeserializeArrayWithElements <T, TSerializer> .ParseGenericArray(null, null);

                DeserializeCollection <TSerializer> .ParseCollection <T>(null, null, null);

                DeserializeListWithElements <T, TSerializer> .ParseGenericList(null, null, null);

                SpecializedQueueElements <T> .ConvertToQueue(null);

                SpecializedQueueElements <T> .ConvertToStack(null);

//*/

                WriteListsOfElements <T, TSerializer> .WriteList(null, null);

                WriteListsOfElements <T, TSerializer> .WriteIList(null, null);

                WriteListsOfElements <T, TSerializer> .WriteEnumerable(null, null);

                WriteListsOfElements <T, TSerializer> .WriteListValueType(null, null);

                WriteListsOfElements <T, TSerializer> .WriteIListValueType(null, null);

                WriteListsOfElements <T, TSerializer> .WriteGenericArrayValueType(null, null);

                WriteListsOfElements <T, TSerializer> .WriteArray(null, null);

                TranslateListWithElements <T> .LateBoundTranslateToGenericICollection(null, null);

                TranslateListWithConvertibleElements <T, T> .LateBoundTranslateToGenericICollection(null, null);

                QueryStringWriter <T> .WriteObject(null, null);

                return(i);
            }