コード例 #1
0
ファイル: ProtocolBuffersTest.cs プロジェクト: pipi1226/krpc
 public void IsAValidType()
 {
     Assert.IsTrue(ProtocolBuffers.IsAValidType(typeof(KRPC.Schema.KRPC.Request)));
     Assert.IsTrue(ProtocolBuffers.IsAValidType(typeof(KRPC.Schema.KRPC.Response)));
     Assert.IsTrue(ProtocolBuffers.IsAValidType(typeof(double)));
     Assert.IsTrue(ProtocolBuffers.IsAValidType(typeof(float)));
     Assert.IsTrue(ProtocolBuffers.IsAValidType(typeof(int)));
     Assert.IsTrue(ProtocolBuffers.IsAValidType(typeof(long)));
     Assert.IsTrue(ProtocolBuffers.IsAValidType(typeof(uint)));
     Assert.IsTrue(ProtocolBuffers.IsAValidType(typeof(ulong)));
     Assert.IsTrue(ProtocolBuffers.IsAValidType(typeof(bool)));
     Assert.IsTrue(ProtocolBuffers.IsAValidType(typeof(string)));
     Assert.IsTrue(ProtocolBuffers.IsAValidType(typeof(byte[])));
     Assert.IsFalse(ProtocolBuffers.IsAValidType(null));
     Assert.IsFalse(ProtocolBuffers.IsAValidType(typeof(ProtocolBuffersTest)));
 }
コード例 #2
0
 /// <summary>
 /// Return the name of the protocol buffer type for the given C# type
 /// </summary>
 public static string GetTypeName(Type type)
 {
     if (!IsAValidType(type))
     {
         throw new ArgumentException("Type is not valid");
     }
     else if (ProtocolBuffers.IsAValidType(type))
     {
         return(ProtocolBuffers.GetTypeName(type));
     }
     else if (IsAClassType(type))
     {
         return(ProtocolBuffers.GetTypeName(typeof(ulong))); // Class instance GUIDs are uint64
     }
     else if (IsAnEnumType(type))
     {
         return(ProtocolBuffers.GetTypeName(typeof(int))); // Enums are int32
     }
     else if (IsAListCollectionType(type))
     {
         return(ProtocolBuffers.GetMessageTypeName(typeof(Schema.KRPC.List)));
     }
     else if (IsADictionaryCollectionType(type))
     {
         return(ProtocolBuffers.GetMessageTypeName(typeof(Schema.KRPC.Dictionary)));
     }
     else if (IsASetCollectionType(type))
     {
         return(ProtocolBuffers.GetMessageTypeName(typeof(Schema.KRPC.Set)));
     }
     else if (IsATupleCollectionType(type))
     {
         return(ProtocolBuffers.GetMessageTypeName(typeof(Schema.KRPC.Tuple)));
     }
     else
     {
         throw new ArgumentException("Type is not valid");
     }
 }
コード例 #3
0
 /// <summary>
 /// Returns true if the given type can be used as a kRPC type
 /// </summary>
 public static bool IsAValidType(Type type)
 {
     return(ProtocolBuffers.IsAValidType(type) || IsAClassType(type) || IsAnEnumType(type) || IsACollectionType(type));
 }