/// <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"); } }
/// <summary> /// Return the name of the kRPC type for the given C# type /// </summary> public static string GetKRPCTypeName(Type type) { if (!IsAValidType(type)) { throw new ArgumentException("Type " + type + " does not have a kRPC type name"); } else if (IsAClassType(type)) { return("Class(" + GetClassServiceName(type) + "." + type.Name + ")"); } else if (IsAnEnumType(type)) { return("Enum(" + GetEnumServiceName(type) + "." + type.Name + ")"); } else if (IsAListCollectionType(type)) { return("List(" + GetKRPCTypeName(type.GetGenericArguments().Single()) + ")"); } else if (IsADictionaryCollectionType(type)) { return("Dictionary(" + GetKRPCTypeName(type.GetGenericArguments() [0]) + "," + GetKRPCTypeName(type.GetGenericArguments() [1]) + ")"); } else if (IsASetCollectionType(type)) { return("Set(" + GetKRPCTypeName(type.GetGenericArguments().Single()) + ")"); } else if (IsATupleCollectionType(type)) { return("Tuple(" + String.Join(",", type.GetGenericArguments().Select(t => GetKRPCTypeName(t)).ToArray()) + ")"); } else { return(ProtocolBuffers.GetTypeName(type)); } }