public static string GetTypescriptTypeName(this ITypeSymbol type, TypeToEdmTypeCollectionBehavior typeToEdmTypeCollectionBehavior) { if (type == null) { throw new ArgumentNullException(nameof(type)); } type = type.GetUnderlyingTypeSymbol(); string typeName = type.Name; if (typeName == nameof(String)) // string { return("string"); } else if (typeName == nameof(DateTimeOffset)) { return("Date"); } else if (typeName == nameof(Boolean)) // bool { return("boolean"); } if (typeName == nameof(Int16)) // short { return("number"); } if (typeName == nameof(Int32)) // int { return("number"); } if (typeName == nameof(Int64)) // long { return("string"); } if (typeName == nameof(Guid)) { return("string"); } if (typeName == nameof(Decimal)) // decimal { return("string"); } if (typeName == nameof(Single)) // float { return("number"); } if (typeName == nameof(Byte)) // byte { return("number"); } if (typeName == nameof(Double)) // double { return("number"); } if (typeName == "Dictionary") { return("any"); } else { if (type.IsQueryableType() || type.IsCollectionType()) { switch (typeToEdmTypeCollectionBehavior) { case TypeToEdmTypeCollectionBehavior.UseJayDataNonGenericQueryable: throw new InvalidOperationException(); case TypeToEdmTypeCollectionBehavior.UseJayDataGenericQueryable: return($"$data.Queryable<{type.GetElementType().GetTypescriptTypeName(TypeToEdmTypeCollectionBehavior.NA)}>"); case TypeToEdmTypeCollectionBehavior.UseArray: throw new InvalidOperationException(); case TypeToEdmTypeCollectionBehavior.UseTypeScriptGenericArray: return($"Array<{type.GetElementType().GetTypescriptTypeName(TypeToEdmTypeCollectionBehavior.NA)}>"); case TypeToEdmTypeCollectionBehavior.UseODataCollection: throw new InvalidOperationException(); case TypeToEdmTypeCollectionBehavior.NA: throw new InvalidOperationException(); } } return(type.ToDisplayString()); } }
public static string GetEdmTypeName(this ITypeSymbol type, TypeToEdmTypeCollectionBehavior typeToEdmTypeCollectionBehavior, NullableFlowState?topLevelNullability = null) { if (type == null) { throw new ArgumentNullException(nameof(type)); } type = type.GetUnderlyingTypeSymbol(); string typeName = type.Name; if (typeName == nameof(String)) { return("Edm.String"); } else if (typeName == nameof(DateTimeOffset)) { return("Edm.DateTimeOffset"); } else if (typeName == nameof(Boolean)) { return("Edm.Boolean"); } if (typeName == nameof(Int16)) { return("Edm.Int16"); } if (typeName == nameof(Int32)) { return("Edm.Int32"); } if (typeName == nameof(Int64)) { return("Edm.Int64"); } if (typeName == nameof(Guid)) { return("Edm.Guid"); } if (typeName == nameof(Decimal)) { return("Edm.Decimal"); } if (typeName == nameof(Single)) { return("Edm.Single"); } if (typeName == nameof(Byte)) { return("Edm.Byte"); } if (typeName == nameof(Double)) { return("Edm.Double"); } if (typeName == "Dictionary") { return("$data.Object"); } else { if (type.IsQueryableType() || type.IsCollectionType()) { switch (typeToEdmTypeCollectionBehavior) { case TypeToEdmTypeCollectionBehavior.UseJayDataNonGenericQueryable: return("$data.Queryable"); case TypeToEdmTypeCollectionBehavior.UseJayDataGenericQueryable: return($"$data.Queryable<{type.GetEdmElementTypeName()}>"); case TypeToEdmTypeCollectionBehavior.UseArray: return("Array"); case TypeToEdmTypeCollectionBehavior.UseTypeScriptGenericArray: return($"Array<{type.GetEdmElementTypeName()}>"); case TypeToEdmTypeCollectionBehavior.UseODataCollection: return($"Collection({type.GetEdmElementTypeName()})"); case TypeToEdmTypeCollectionBehavior.NA: throw new InvalidOperationException(); } } return(topLevelNullability != null?type.ToDisplayString(topLevelNullability.Value) : type.ToDisplayString()); } }