private static Type[] ReadGenericArguments(this IBinaryTokenStreamReader @this, SerializationManager serializationManager, int n) { var args = new Type[n]; for (var i = 0; i < n; i++) { args[i] = @this.ReadFullTypeHeader(serializationManager); } return(args); }
/// <summary> Read a <c>Type</c> value from the stream. </summary> internal static Type ReadSpecifiedTypeHeader(this IBinaryTokenStreamReader @this, SerializationManager serializationManager) { // Assumes that the SpecifiedType token has already been read var token = @this.ReadToken(); switch (token) { case SerializationTokenType.Boolean: return(typeof(bool)); case SerializationTokenType.Int: return(typeof(int)); case SerializationTokenType.Short: return(typeof(short)); case SerializationTokenType.Long: return(typeof(long)); case SerializationTokenType.Sbyte: return(typeof(sbyte)); case SerializationTokenType.Uint: return(typeof(uint)); case SerializationTokenType.Ushort: return(typeof(ushort)); case SerializationTokenType.Ulong: return(typeof(ulong)); case SerializationTokenType.Byte: return(typeof(byte)); case SerializationTokenType.Float: return(typeof(float)); case SerializationTokenType.Double: return(typeof(double)); case SerializationTokenType.Decimal: return(typeof(decimal)); case SerializationTokenType.String: return(typeof(string)); case SerializationTokenType.Character: return(typeof(char)); case SerializationTokenType.Guid: return(typeof(Guid)); case SerializationTokenType.Date: return(typeof(DateTime)); case SerializationTokenType.TimeSpan: return(typeof(TimeSpan)); case SerializationTokenType.IpAddress: return(typeof(IPAddress)); case SerializationTokenType.IpEndPoint: return(typeof(IPEndPoint)); case SerializationTokenType.GrainId: return(typeof(GrainId)); case SerializationTokenType.ActivationId: return(typeof(ActivationId)); case SerializationTokenType.SiloAddress: return(typeof(SiloAddress)); case SerializationTokenType.ActivationAddress: return(typeof(ActivationAddress)); case SerializationTokenType.CorrelationId: return(typeof(CorrelationId)); case SerializationTokenType.Request: return(typeof(InvokeMethodRequest)); case SerializationTokenType.Response: return(typeof(Response)); case SerializationTokenType.StringObjDict: return(typeof(Dictionary <string, object>)); case SerializationTokenType.Object: return(typeof(Object)); case SerializationTokenType.Tuple + 1: return(typeof(Tuple <>).MakeGenericType(@this.ReadGenericArguments(serializationManager, 1))); case SerializationTokenType.Tuple + 2: return(typeof(Tuple <,>).MakeGenericType(@this.ReadGenericArguments(serializationManager, 2))); case SerializationTokenType.Tuple + 3: return(typeof(Tuple <, ,>).MakeGenericType(@this.ReadGenericArguments(serializationManager, 3))); case SerializationTokenType.Tuple + 4: return(typeof(Tuple <, , ,>).MakeGenericType(@this.ReadGenericArguments(serializationManager, 4))); case SerializationTokenType.Tuple + 5: return(typeof(Tuple <, , , ,>).MakeGenericType(@this.ReadGenericArguments(serializationManager, 5))); case SerializationTokenType.Tuple + 6: return(typeof(Tuple <, , , , ,>).MakeGenericType(@this.ReadGenericArguments(serializationManager, 6))); case SerializationTokenType.Tuple + 7: return(typeof(Tuple <, , , , , ,>).MakeGenericType(@this.ReadGenericArguments(serializationManager, 7))); case SerializationTokenType.Array + 1: var et1 = @this.ReadFullTypeHeader(serializationManager); return(et1.MakeArrayType()); case SerializationTokenType.Array + 2: var et2 = @this.ReadFullTypeHeader(serializationManager); return(et2.MakeArrayType(2)); case SerializationTokenType.Array + 3: var et3 = @this.ReadFullTypeHeader(serializationManager); return(et3.MakeArrayType(3)); case SerializationTokenType.Array + 4: var et4 = @this.ReadFullTypeHeader(serializationManager); return(et4.MakeArrayType(4)); case SerializationTokenType.Array + 5: var et5 = @this.ReadFullTypeHeader(serializationManager); return(et5.MakeArrayType(5)); case SerializationTokenType.Array + 6: var et6 = @this.ReadFullTypeHeader(serializationManager); return(et6.MakeArrayType(6)); case SerializationTokenType.Array + 7: var et7 = @this.ReadFullTypeHeader(serializationManager); return(et7.MakeArrayType(7)); case SerializationTokenType.Array + 8: var et8 = @this.ReadFullTypeHeader(serializationManager); return(et8.MakeArrayType(8)); case SerializationTokenType.List: return(typeof(List <>).MakeGenericType(@this.ReadGenericArguments(serializationManager, 1))); case SerializationTokenType.Dictionary: return(typeof(Dictionary <,>).MakeGenericType(@this.ReadGenericArguments(serializationManager, 2))); case SerializationTokenType.KeyValuePair: return(typeof(KeyValuePair <,>).MakeGenericType(@this.ReadGenericArguments(serializationManager, 2))); case SerializationTokenType.Set: return(typeof(HashSet <>).MakeGenericType(@this.ReadGenericArguments(serializationManager, 1))); case SerializationTokenType.SortedList: return(typeof(SortedList <,>).MakeGenericType(@this.ReadGenericArguments(serializationManager, 2))); case SerializationTokenType.SortedSet: return(typeof(SortedSet <>).MakeGenericType(@this.ReadGenericArguments(serializationManager, 1))); case SerializationTokenType.Stack: return(typeof(Stack <>).MakeGenericType(@this.ReadGenericArguments(serializationManager, 1))); case SerializationTokenType.Queue: return(typeof(Queue <>).MakeGenericType(@this.ReadGenericArguments(serializationManager, 1))); case SerializationTokenType.LinkedList: return(typeof(LinkedList <>).MakeGenericType(@this.ReadGenericArguments(serializationManager, 1))); case SerializationTokenType.Nullable: return(typeof(Nullable <>).MakeGenericType(@this.ReadGenericArguments(serializationManager, 1))); case SerializationTokenType.ByteArray: return(typeof(byte[])); case SerializationTokenType.ShortArray: return(typeof(short[])); case SerializationTokenType.IntArray: return(typeof(int[])); case SerializationTokenType.LongArray: return(typeof(long[])); case SerializationTokenType.UShortArray: return(typeof(ushort[])); case SerializationTokenType.UIntArray: return(typeof(uint[])); case SerializationTokenType.ULongArray: return(typeof(ulong[])); case SerializationTokenType.FloatArray: return(typeof(float[])); case SerializationTokenType.DoubleArray: return(typeof(double[])); case SerializationTokenType.CharArray: return(typeof(char[])); case SerializationTokenType.BoolArray: return(typeof(bool[])); case SerializationTokenType.SByteArray: return(typeof(sbyte[])); case SerializationTokenType.NamedType: var typeName = @this.ReadString(); try { return(serializationManager.ResolveTypeName(typeName)); } catch (TypeAccessException ex) { throw new TypeAccessException("Named type \"" + typeName + "\" is invalid: " + ex.Message); } default: break; } throw new SerializationException("Unexpected '" + token + "' found when expecting a type reference"); }