コード例 #1
0
 private static Type MapIdentifierToType(DSReader reader)
 {
     var type = (TypeIdentifier)reader.Read7bUInt();
     switch(type) {
         case TypeIdentifier.Blob:
             return typeof(Blob);
         case TypeIdentifier.Compound:
             return typeof(Compound);
         case TypeIdentifier.Decimal:
             return typeof(Decimal);
         case TypeIdentifier.Dictionary:
             var kt = MapIdentifierToType(reader);
             var vt = MapIdentifierToType(reader);
             return typeof(Dictionary<,>).MakeGenericType(kt, vt);
         case TypeIdentifier.Double:
             return typeof(Double);
         case TypeIdentifier.Int:
             return typeof(SignedInteger);
         case TypeIdentifier.List:
             return typeof(List<>).MakeGenericType(MapIdentifierToType(reader));
         case TypeIdentifier.String:
             return typeof(String);
         case TypeIdentifier.UInt:
             return typeof(UnsignedInteger);
         case TypeIdentifier.Undefined:
             return typeof(StoragePremitive);
         default:
             throw new ArgumentException();
     }
 }
コード例 #2
0
 private static Func<DSReader, StoragePremitive> MapIdentifierToConstructor(DSReader reader)
 {
     var type = (TypeIdentifier)reader.Read7bUInt();
     switch(type) {
         case TypeIdentifier.Blob:
             return x => new Blob(x);
         case TypeIdentifier.Compound:
             return x => new Compound(x);
         case TypeIdentifier.Decimal:
             return x => new Decimal(x);
         case TypeIdentifier.Double:
             return x => new Double(x);
         case TypeIdentifier.Int:
             return x => new SignedInteger(x);
         case TypeIdentifier.List:
             return x => {
                 try {
                     return (StoragePremitive)typeof(List<>).MakeGenericType(MapIdentifierToType(x)).GetConstructor(new Type[] { typeof(DSReader) }).Invoke(new object[] { x });
                 } catch (System.Reflection.TargetInvocationException e) {
                     if (e.GetBaseException() is System.IO.IOException) {
                         throw new System.IO.IOException("IO Error", e.GetBaseException());
                     } else throw;
                 }
             };
         case TypeIdentifier.String:
             return x => new String(x);
         case TypeIdentifier.UInt:
             return x => new UnsignedInteger(x);
         case TypeIdentifier.Null:
             return x => null;
         case TypeIdentifier.Dictionary:
             return x => {
                 try {
                     var kt = MapIdentifierToType(reader);
                     var vt = MapIdentifierToType(reader);
                     return (StoragePremitive)typeof(Dictionary<,>).MakeGenericType(kt, vt).GetConstructor(new Type[] { typeof(DSReader) }).Invoke(new object[] { x });
                 } catch(System.Reflection.TargetInvocationException e) {
                     if (e.GetBaseException() is System.IO.IOException) {
                         throw new System.IO.IOException("IO Error", e.GetBaseException());
                     } else throw;
                 }
             };
         default:
             throw new ArgumentException();
     }
 }
コード例 #3
0
ファイル: Double.cs プロジェクト: c933103/KanColleViewer
 public Double(DSReader input) { value = input.ReadDouble(); }
コード例 #4
0
 public static StoragePremitive Parse(DSReader input)
 {
     return MapIdentifierToConstructor(input)(input);
 }
コード例 #5
0
ファイル: String.cs プロジェクト: c933103/KanColleViewer
 public String(DSReader input) { value = input.ReadString(); }
コード例 #6
0
 public SignedInteger(DSReader input) { value = input.Read7bInt(); }
コード例 #7
0
ファイル: Decimal.cs プロジェクト: c933103/KanColleViewer
 public Decimal(DSReader input)
 {
     value = input.ReadDecimal();
 }
コード例 #8
0
ファイル: Blob.cs プロジェクト: c933103/KanColleViewer
 public Blob(DSReader input)
 {
     data = new byte[(int)input.Read7bUInt()];
     input.ReadFully(data);
 }