@@ -624,233 +624,9 @@ internal static void InvokeReset(this Type genericType)
624624 methodInfo . Invoke ( null , null ) ;
625625 }
626626
627- #if __IOS__
628- /// <summary>
629- /// Provide hint to IOS AOT compiler to pre-compile generic classes for all your DTOs.
630- /// Just needs to be called once in a static constructor.
631- /// </summary>
632- [ MonoTouch . Foundation . Preserve ]
633- public static void InitForAot ( ) {
634- }
635-
636- [ MonoTouch . Foundation . Preserve ]
637- public static void RegisterForAot ( )
638- {
639- RegisterTypeForAot < Poco > ( ) ;
640-
641- RegisterElement < Poco , string > ( ) ;
642-
643- RegisterElement < Poco , bool > ( ) ;
644- RegisterElement < Poco , char > ( ) ;
645- RegisterElement < Poco , byte > ( ) ;
646- RegisterElement < Poco , sbyte > ( ) ;
647- RegisterElement < Poco , short > ( ) ;
648- RegisterElement < Poco , ushort > ( ) ;
649- RegisterElement < Poco , int > ( ) ;
650- RegisterElement < Poco , uint > ( ) ;
651-
652- RegisterElement < Poco , long > ( ) ;
653- RegisterElement < Poco , ulong > ( ) ;
654- RegisterElement < Poco , float > ( ) ;
655- RegisterElement < Poco , double > ( ) ;
656- RegisterElement < Poco , decimal > ( ) ;
657-
658- RegisterElement < Poco , bool ? > ( ) ;
659- RegisterElement < Poco , char ? > ( ) ;
660- RegisterElement < Poco , byte ? > ( ) ;
661- RegisterElement < Poco , sbyte ? > ( ) ;
662- RegisterElement < Poco , short ? > ( ) ;
663- RegisterElement < Poco , ushort ? > ( ) ;
664- RegisterElement < Poco , int ? > ( ) ;
665- RegisterElement < Poco , uint ? > ( ) ;
666- RegisterElement < Poco , long ? > ( ) ;
667- RegisterElement < Poco , ulong ? > ( ) ;
668- RegisterElement < Poco , float ? > ( ) ;
669- RegisterElement < Poco , double ? > ( ) ;
670- RegisterElement < Poco , decimal ? > ( ) ;
671-
672- //RegisterElement<Poco, JsonValue>();
673-
674- RegisterTypeForAot < DayOfWeek > ( ) ; // used by DateTime
675-
676- // register built in structs
677- RegisterTypeForAot < Guid > ( ) ;
678- RegisterTypeForAot < TimeSpan > ( ) ;
679- RegisterTypeForAot < DateTime > ( ) ;
680- RegisterTypeForAot < DateTime ? > ( ) ;
681- RegisterTypeForAot < TimeSpan ? > ( ) ;
682- RegisterTypeForAot < Guid ? > ( ) ;
683- }
684-
685- [ MonoTouch . Foundation . Preserve ]
686- public static void RegisterTypeForAot < T > ( )
687- {
688- AotConfig . RegisterSerializers < T > ( ) ;
689- }
690-
691- [ MonoTouch . Foundation . Preserve ]
692- static void RegisterQueryStringWriter ( )
693- {
694- var i = 0 ;
695- if ( QueryStringWriter < Poco > . WriteFn ( ) != null ) i ++ ;
696- }
697-
698- [ MonoTouch . Foundation . Preserve ]
699- internal static int RegisterElement < T , TElement > ( )
700- {
701- var i = 0 ;
702- i += AotConfig . RegisterSerializers < TElement > ( ) ;
703- AotConfig . RegisterElement < T , TElement , JsonTypeSerializer > ( ) ;
704- AotConfig . RegisterElement < T , TElement , JsvTypeSerializer > ( ) ;
705- return i ;
706- }
707-
708- ///<summary>
709- /// Class contains Ahead-of-Time (AOT) explicit class declarations which is used only to workaround "-aot-only" exceptions occured on device only.
710- /// </summary>
711- [ MonoTouch . Foundation . Preserve ( AllMembers = true ) ]
712- internal class AotConfig
713- {
714- internal static JsReader < JsonTypeSerializer > jsonReader ;
715- internal static JsWriter < JsonTypeSerializer > jsonWriter ;
716- internal static JsReader < JsvTypeSerializer > jsvReader ;
717- internal static JsWriter < JsvTypeSerializer > jsvWriter ;
718- internal static JsonTypeSerializer jsonSerializer ;
719- internal static JsvTypeSerializer jsvSerializer ;
720-
721- static AotConfig ( )
722- {
723- jsonSerializer = new JsonTypeSerializer ( ) ;
724- jsvSerializer = new JsvTypeSerializer ( ) ;
725- jsonReader = new JsReader < JsonTypeSerializer > ( ) ;
726- jsonWriter = new JsWriter < JsonTypeSerializer > ( ) ;
727- jsvReader = new JsReader < JsvTypeSerializer > ( ) ;
728- jsvWriter = new JsWriter < JsvTypeSerializer > ( ) ;
729- }
730-
731- internal static int RegisterSerializers < T > ( )
732- {
733- var i = 0 ;
734- i += Register < T , JsonTypeSerializer > ( ) ;
735- if ( jsonSerializer . GetParseFn < T > ( ) != null ) i ++ ;
736- if ( jsonSerializer . GetWriteFn < T > ( ) != null ) i ++ ;
737- if ( jsonReader . GetParseFn < T > ( ) != null ) i ++ ;
738- if ( jsonWriter . GetWriteFn < T > ( ) != null ) i ++ ;
739-
740- i += Register < T , JsvTypeSerializer > ( ) ;
741- if ( jsvSerializer . GetParseFn < T > ( ) != null ) i ++ ;
742- if ( jsvSerializer . GetWriteFn < T > ( ) != null ) i ++ ;
743- if ( jsvReader . GetParseFn < T > ( ) != null ) i ++ ;
744- if ( jsvWriter . GetWriteFn < T > ( ) != null ) i ++ ;
745-
746-
747- //RegisterCsvSerializer<T>();
748- RegisterQueryStringWriter ( ) ;
749- return i ;
750- }
751-
752- internal static void RegisterCsvSerializer < T > ( )
753- {
754- CsvSerializer < T > . WriteFn ( ) ;
755- CsvSerializer < T > . WriteObject ( null , null ) ;
756- CsvWriter < T > . Write ( null , default ( IEnumerable < T > ) ) ;
757- CsvWriter < T > . WriteRow ( null , default ( T ) ) ;
758- }
759-
760- public static ParseStringDelegate GetParseFn ( Type type )
761- {
762- var parseFn = JsonTypeSerializer . Instance . GetParseFn ( type ) ;
763- return parseFn ;
764- }
765-
766- internal static int Register < T , TSerializer > ( ) where TSerializer : ITypeSerializer
767- {
768- var i = 0 ;
769-
770- if ( JsonWriter < T > . WriteFn ( ) != null ) i ++ ;
771- if ( JsonWriter . Instance . GetWriteFn < T > ( ) != null ) i ++ ;
772- if ( JsonReader . Instance . GetParseFn < T > ( ) != null ) i ++ ;
773- if ( JsonReader < T > . Parse ( null ) != null ) i ++ ;
774- if ( JsonReader < T > . GetParseFn ( ) != null ) i ++ ;
775- //if (JsWriter.GetTypeSerializer<JsonTypeSerializer>().GetWriteFn<T>() != null) i++;
776- if ( new List < T > ( ) != null ) i ++ ;
777- if ( new T [ 0 ] != null ) i ++ ;
778-
779- JsConfig < T > . ExcludeTypeInfo = false ;
780-
781- if ( JsConfig < T > . OnDeserializedFn != null ) i ++ ;
782- if ( JsConfig < T > . HasDeserializeFn ) i ++ ;
783- if ( JsConfig < T > . SerializeFn != null ) i ++ ;
784- if ( JsConfig < T > . DeSerializeFn != null ) i ++ ;
785- //JsConfig<T>.SerializeFn = arg => "";
786- //JsConfig<T>.DeSerializeFn = arg => default(T);
787- if ( TypeConfig < T > . Properties != null ) i ++ ;
788-
789- /*
790- if (WriteType<T, TSerializer>.Write != null) i++;
791- if (WriteType<object, TSerializer>.Write != null) i++;
792-
793- if (DeserializeBuiltin<T>.Parse != null) i++;
794- if (DeserializeArray<T[], TSerializer>.Parse != null) i++;
795- DeserializeType<TSerializer>.ExtractType(null);
796- DeserializeArrayWithElements<T, TSerializer>.ParseGenericArray(null, null);
797- DeserializeCollection<TSerializer>.ParseCollection<T>(null, null, null);
798- DeserializeListWithElements<T, TSerializer>.ParseGenericList(null, null, null);
799-
800- SpecializedQueueElements<T>.ConvertToQueue(null);
801- SpecializedQueueElements<T>.ConvertToStack(null);
802- */
803-
804- WriteListsOfElements < T , TSerializer > . WriteList ( null , null ) ;
805- WriteListsOfElements < T , TSerializer > . WriteIList ( null , null ) ;
806- WriteListsOfElements < T , TSerializer > . WriteEnumerable ( null , null ) ;
807- WriteListsOfElements < T , TSerializer > . WriteListValueType ( null , null ) ;
808- WriteListsOfElements < T , TSerializer > . WriteIListValueType ( null , null ) ;
809- WriteListsOfElements < T , TSerializer > . WriteGenericArrayValueType ( null , null ) ;
810- WriteListsOfElements < T , TSerializer > . WriteArray ( null , null ) ;
811-
812- TranslateListWithElements < T > . LateBoundTranslateToGenericICollection ( null , null ) ;
813- TranslateListWithConvertibleElements < T , T > . LateBoundTranslateToGenericICollection ( null , null ) ;
814-
815- QueryStringWriter < T > . WriteObject ( null , null ) ;
816- return i ;
817- }
818-
819- internal static void RegisterElement < T , TElement , TSerializer > ( ) where TSerializer : ITypeSerializer
820- {
821- DeserializeDictionary < TSerializer > . ParseDictionary < T , TElement > ( null , null , null , null ) ;
822- DeserializeDictionary < TSerializer > . ParseDictionary < TElement , T > ( null , null , null , null ) ;
823-
824- ToStringDictionaryMethods < T , TElement , TSerializer > . WriteIDictionary ( null , null , null , null ) ;
825- ToStringDictionaryMethods < TElement , T , TSerializer > . WriteIDictionary ( null , null , null , null ) ;
826-
827- // Include List deserialisations from the Register<> method above. This solves issue where List<Guid> properties on responses deserialise to null.
828- // No idea why this is happening because there is no visible exception raised. Suspect IOS is swallowing an AOT exception somewhere.
829- DeserializeArrayWithElements < TElement , TSerializer > . ParseGenericArray ( null , null ) ;
830- DeserializeListWithElements < TElement , TSerializer > . ParseGenericList ( null , null , null ) ;
831-
832- // Cannot use the line below for some unknown reason - when trying to compile to run on device, mtouch bombs during native code compile.
833- // Something about this line or its inner workings is offensive to mtouch. Luckily this was not needed for my List<Guide> issue.
834- // DeserializeCollection<JsonTypeSerializer>.ParseCollection<TElement>(null, null, null);
835-
836- TranslateListWithElements < TElement > . LateBoundTranslateToGenericICollection ( null , typeof ( List < TElement > ) ) ;
837- TranslateListWithConvertibleElements < TElement , TElement > . LateBoundTranslateToGenericICollection ( null , typeof ( List < TElement > ) ) ;
838- }
839- }
840-
841- #endif
842-
843627 internal static HashSet < Type > __uniqueTypes = new HashSet < Type > ( ) ;
844628 }
845629
846- #if __IOS__
847- [ MonoTouch . Foundation . Preserve ( AllMembers = true ) ]
848- internal class Poco
849- {
850- public string Dummy { get ; set ; }
851- }
852- #endif
853-
854630 public class JsConfig < T >
855631 {
856632 /// <summary>
0 commit comments