public static NativeValue DataTypeToNativeValue(IServerProcess process, IDataType dataType) { IScalarType scalarType = dataType as IScalarType; if (scalarType != null) { NativeScalarValue nativeScalar = new NativeScalarValue(); nativeScalar.DataTypeName = ScalarTypeToDataTypeName(process.DataTypes, scalarType); return(nativeScalar); } ListType listType = dataType as ListType; if (listType != null) { NativeListValue nativeList = new NativeListValue(); return(nativeList); } RowType rowType = dataType as RowType; if (rowType != null) { NativeRowValue nativeRow = new NativeRowValue(); nativeRow.Columns = ColumnsToNativeColumns(process.DataTypes, rowType.Columns); return(nativeRow); } TableType tableType = dataType as TableType; if (tableType != null) { NativeTableValue nativeTable = new NativeTableValue(); nativeTable.Columns = ColumnsToNativeColumns(process.DataTypes, tableType.Columns); return(nativeTable); } throw new NotSupportedException(String.Format("Values of type \"{0}\" are not supported.", dataType.Name)); }
public override bool IsNullable(IType type, ITypeDefinition typeDefinition) { if (type is IScalarType) { IScalarType st = (type as IScalarType); switch (st.BaseType) { case BaseType.TypeChar: return(typeDefinition.Length == 1); case BaseType.TypeAnsiChar: case BaseType.TypeAnsiString: case BaseType.TypeDate: case BaseType.TypeDateTime: case BaseType.TypeTime: case BaseType.TypeBool: case BaseType.TypeByte: case BaseType.TypeCurrency: case BaseType.TypeDecimal: case BaseType.TypeFloat: case BaseType.TypeInt: case BaseType.TypeUuid: return(true); default: return(false); } } else if (type is IEnumerationType) { return(true); } else { return(false); } }
public override string ToTypeName(IType type, ITypeDefinition typeDefinition, IPersistence persistence, bool fullName, bool forceNullable) { if (type is IEntityType) { return(fullName ? AddBaseNamespace((type as IEntityType).Entity.FullName) : (type as IEntityType).Entity.Name); } else if (type is IEnumerationType) { string typeName = fullName ? AddBaseNamespace((type as IEnumerationType).FullName) : (type as IEnumerationType).Name; if (forceNullable) { typeName += "?"; } return(typeName); } else if (type is IScalarType) { IScalarType st = (type as IScalarType); ITypeDefinition typeDef = typeDefinition != null ? typeDefinition : st.TypeDefinition; string typeName; switch (st.BaseType) { case BaseType.TypeVoid: typeName = "void"; break; case BaseType.TypeAnsiChar: case BaseType.TypeChar: if (typeDef.Length == 1) { typeName = "char"; } else { return(String.Format("char[{0}]", typeDef.Length)); } break; case BaseType.TypeAnsiString: case BaseType.TypeString: return("string"); case BaseType.TypeDate: case BaseType.TypeDateTime: case BaseType.TypeTime: typeName = "DateTime"; break; case BaseType.TypeBinary: return(typeDef.HasLength ? String.Format("byte[{0}]", typeDef.Length) : "byte[]"); case BaseType.TypeBool: typeName = "bool"; break; case BaseType.TypeByte: typeName = "byte"; break; case BaseType.TypeCurrency: case BaseType.TypeDecimal: typeName = "decimal"; break; case BaseType.TypeFloat: typeName = "double"; break; case BaseType.TypeInt: typeName = typeDef.Length == 2 ? "short" : typeDef.Length == 8 ? "long" : "int"; break; case BaseType.TypeUuid: typeName = "Guid"; break; default: throw new GlException("Unsupported base type: {0}. {1}", st.BaseType, type); } if (!typeDef.Required || forceNullable) { return(typeName + "?"); } return(ToCollectionTypeName(typeName, typeDef)); } else { throw new GlException("Unsupported type: {0}", type); } }
public static string ScalarTypeToDataTypeName(DataTypes dataTypes, IScalarType scalarType) { if (scalarType.IsClassType) { return(scalarType.FromClassDefinition.ClassName); } if (scalarType.NativeType == NativeAccessors.AsBoolean.NativeType) { return("Boolean"); } if (scalarType.NativeType == NativeAccessors.AsByte.NativeType) { return("Byte"); } if (scalarType.NativeType == NativeAccessors.AsByteArray.NativeType) { return("Byte[]"); } if (scalarType.NativeType == NativeAccessors.AsDateTime.NativeType) { if (scalarType.Is(dataTypes.SystemDateTime) || scalarType.IsLike(dataTypes.SystemDateTime)) { return("DateTime"); } if (scalarType.Is(dataTypes.SystemDate) || scalarType.IsLike(dataTypes.SystemDate)) { return("Date"); } if (scalarType.Is(dataTypes.SystemTime) || scalarType.IsLike(dataTypes.SystemTime)) { return("Time"); } } if (scalarType.NativeType == NativeAccessors.AsDecimal.NativeType) { return("Decimal"); } if (scalarType.NativeType == NativeAccessors.AsException.NativeType) { return("Exception"); } if (scalarType.NativeType == NativeAccessors.AsGuid.NativeType) { return("Guid"); } if (scalarType.NativeType == NativeAccessors.AsInt16.NativeType) { return("Int16"); } if (scalarType.NativeType == NativeAccessors.AsInt32.NativeType) { return("Int32"); } if (scalarType.NativeType == NativeAccessors.AsInt64.NativeType) { return("Int64"); } if (scalarType.NativeType == NativeAccessors.AsString.NativeType) { return("String"); } if (scalarType.NativeType == NativeAccessors.AsTimeSpan.NativeType) { return("TimeSpan"); } throw new ArgumentException(String.Format("Scalar type \"{0}\" has no native type.", scalarType.Name)); }
public static string DataTypeToDataTypeName(DataTypes dataTypes, IDataType dataType) { IScalarType scalarType = dataType as IScalarType; if (scalarType != null) { return(ScalarTypeToDataTypeName(dataTypes, scalarType)); } ListType listType = dataType as ListType; if (listType != null) { return(String.Format("list({0})", DataTypeToDataTypeName(dataTypes, listType.ElementType))); } RowType rowType = dataType as RowType; if (rowType != null) { var sb = new StringBuilder(); sb.Append("row{"); bool first = true; foreach (Column column in rowType.Columns) { if (!first) { sb.Append(","); } else { first = false; } sb.AppendFormat("{0}:{1}", column.Name, DataTypeToDataTypeName(dataTypes, column.DataType)); } sb.Append("}"); return(sb.ToString()); } TableType tableType = dataType as TableType; if (tableType != null) { var sb = new StringBuilder(); sb.Append("table{"); bool first = true; foreach (Column column in tableType.Columns) { if (!first) { sb.Append(","); } else { first = false; } sb.AppendFormat("{0}:{1}", column.Name, DataTypeToDataTypeName(dataTypes, column.DataType)); } sb.Append("}"); return(sb.ToString()); } throw new NotSupportedException("Non-scalar-valued attributes are not supported."); }