Example #1
0
 public void GetMessageTypeName()
 {
     Assert.AreEqual("KRPC.Request", ProtocolBuffers.GetMessageTypeName(typeof(KRPC.Schema.KRPC.Request)));
     Assert.AreEqual("KRPC.Response", ProtocolBuffers.GetMessageTypeName(typeof(KRPC.Schema.KRPC.Response)));
     Assert.Throws <ArgumentException> (() => ProtocolBuffers.GetMessageTypeName(null));
     Assert.Throws <ArgumentException> (() => ProtocolBuffers.GetMessageTypeName(typeof(string)));
     Assert.Throws <ArgumentException> (() => ProtocolBuffers.GetMessageTypeName(typeof(ProtocolBuffersTest)));
 }
Example #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");
     }
 }