private Type FieldDefinitionToType(Structs.Definition field, Structs.ColumnDefinition column, bool localiseStrings) { var isArray = field.arrLength != 0; switch (column.type) { case "int": { Type type = null; var signed = field.isSigned; switch (field.size) { case 8: // TODO: Are bytes ever signed in the db? type = typeof(byte); break; case 16: type = signed ? typeof(short) : typeof(ushort); break; case 32: type = signed ? typeof(int) : typeof(uint); break; case 64: type = signed ? typeof(long) : typeof(ulong); break; } return(isArray ? type.MakeArrayType() : type); } case "string": return(isArray ? typeof(string[]) : typeof(string)); case "locstring": { if (isArray && locStringSize > 1) { throw new NotSupportedException("Localised string arrays are not supported"); } return((!localiseStrings && locStringSize > 1) || isArray ? typeof(string[]) : typeof(string)); } case "float": return(isArray ? typeof(float[]) : typeof(float)); default: throw new ArgumentException("Unable to construct C# type from " + column.type); } }
private Type FieldDefinitionToType(Structs.Definition field, Structs.ColumnDefinition column, bool localiseStrings) { var isArray = field.arrLength != 0; if (field.isRelation) { return(isArray ? typeof(int[]) : typeof(int)); } switch (column.type) { case "int": { var type = field.size switch { 8 => field.isSigned ? typeof(sbyte) : typeof(byte), 16 => field.isSigned ? typeof(short) : typeof(ushort), 32 => field.isSigned ? typeof(int) : typeof(uint), 64 => field.isSigned ? typeof(long) : typeof(ulong), _ => throw new NotImplementedException("Unhandled field size of " + field.size) }; return(isArray ? type.MakeArrayType() : type); } case "string": { return(isArray ? typeof(string[]) : typeof(string)); } case "locstring": { if (isArray && LocStringSize > 1) { throw new NotSupportedException("Localised string arrays are not supported"); } return((!localiseStrings && LocStringSize > 1) || isArray ? typeof(string[]) : typeof(string)); } case "float": { return(isArray ? typeof(float[]) : typeof(float)); } default: throw new ArgumentException("Unable to construct C# type from " + column.type); } }
private static Type FieldDefinitionToType(Structs.Definition field, Structs.ColumnDefinition column) { var isArray = field.arrLength != 0; switch (column.type) { case "int": { Type type = null; var signed = field.isSigned; switch (field.size) { case 8: type = signed ? typeof(sbyte) : typeof(byte); break; case 16: type = signed ? typeof(short) : typeof(ushort); break; case 32: type = signed ? typeof(int) : typeof(uint); break; case 64: type = signed ? typeof(long) : typeof(ulong); break; } return(isArray ? type.MakeArrayType() : type); } case "string": case "locstring": return(isArray ? typeof(string[]) : typeof(string)); case "float": return(isArray ? typeof(float[]) : typeof(float)); default: throw new ArgumentException("Unable to construct C# type from " + column.type); } }