[Obsolete("To be converted to Type system")] // JL: Is this even possible considering it's also trying to use based on a template identifier? See Intent.Modules.HttpServiceProxy.Templates.Proxy.WebApiClientServiceProxyTemplate for an example of an approach that might work. public static string GetQualifiedName <T>(this ITypeReference typeInfo, T template, string templateIdentifier = DTOTemplate.IDENTIFIER) where T : IProjectItemTemplate, IRequireTypeResolver { var result = typeInfo.Name; if (typeInfo.Type == ReferenceType.ClassType) { var templateInstance = template.Project.Application.FindTemplateInstance <IHasClassDetails>(TemplateDependancy.OnModel <DTOModel>(templateIdentifier, x => x.Id == typeInfo.Id)); if (templateInstance != null) { return($"{templateInstance.Namespace}.{templateInstance.ClassName}"); } } else if (typeInfo.Stereotypes.Any(x => x.Name == StandardStereotypes.CSharpType)) { return(typeInfo.GetStereotypeProperty <string>(StandardStereotypes.CSharpType, "TypeName") + (typeInfo.IsNullable && typeInfo.GetStereotypeProperty(StandardStereotypes.CSharpType, "IsPrimitive", false) ? "?" : "")); } else if (typeInfo.GetStereotypeProperty <string>(StandardStereotypes.NamespaceProvider, "Namespace") != null) { return($"{typeInfo.GetStereotypeProperty<string>(StandardStereotypes.NamespaceProvider, "Namespace")}.{typeInfo.Name}"); } else if (typeInfo.Folder?.GetStereotypeProperty <string>(StandardStereotypes.NamespaceProvider, "Namespace") != null) { return($"{typeInfo.Folder.GetStereotypeProperty<string>(StandardStereotypes.NamespaceProvider, "Namespace")}.{typeInfo.Name}"); } return(template.Types.Get(typeInfo)); }
protected override string ResolveType(ITypeReference typeInfo) { var result = typeInfo.Name; if (typeInfo.Stereotypes.Any(x => x.Name == "C#")) { string typeName = typeInfo.GetStereotypeProperty <string>("C#", "Type", typeInfo.Name); string @namespace = typeInfo.GetStereotypeProperty <string>("C#", "Namespace"); result = !string.IsNullOrWhiteSpace(@namespace) ? $"{@namespace}.{typeName}" : typeName; if (typeInfo.IsNullable && (typeInfo.Type == ReferenceType.Enum || (typeInfo.Type == ReferenceType.DataType && typeInfo.GetStereotypeProperty("C#", "IsPrimitive", false)))) { result += "?"; } } else { if (typeInfo.IsNullable && typeInfo.Type == ReferenceType.Enum) { result += "?"; } } return(result); }
protected override string ResolveType(ITypeReference typeInfo) { var result = typeInfo.Name; if (typeInfo.Stereotypes.Any(x => x.Name == "Java")) { string typeName = typeInfo.GetStereotypeProperty <string>("Java", "Type"); string @namespace = typeInfo.GetStereotypeProperty <string>("Java", "Namespace"); result = !string.IsNullOrWhiteSpace(@namespace) ? $"{@namespace}.{typeName}" : typeName; } return(result); }
public static string GetQualifiedName <T>(this T template, ITypeReference typeInfo) where T : IProjectItemTemplate, IRequireTypeResolver { string result = typeInfo.Name; if (typeInfo.Type == ReferenceType.ClassType) { var templateInstance = template.Project.FindTemplateInstance <IHasClassDetails>(TemplateDependancy.OnModel <DTOModel>(TypescriptDtoTemplate.LocalIdentifier, (x) => x.Id == typeInfo.Id)) ?? template.Project.FindTemplateInstance <IHasClassDetails>(TemplateDependancy.OnModel <DTOModel>(TypescriptDtoTemplate.RemoteIdentifier, (x) => x.Id == typeInfo.Id)); if (templateInstance != null) { return($"{templateInstance.Namespace}.{templateInstance.ClassName}"); } } else if (typeInfo.HasStereotype(StandardStereotypes.TypescriptType)) { return(typeInfo.GetStereotypeProperty <string>(StandardStereotypes.TypescriptType, "TypeName")); } return(template.Types.Get(typeInfo)); }
protected override ResolvedTypeInfo ResolveType(ITypeReference typeInfo) { if (typeInfo == null) { return(null); } if (typeInfo.HasStereotype("SQL Type Override")) { return(new ResolvedTypeInfo(typeInfo.GetStereotypeProperty <string>("SQL Type Override", "Type Name"), true, null)); } string result = null; switch (typeInfo.Element.Name) { case "binary": result = "VARBINARY"; break; case "bool": result = "BIT"; break; case "byte": result = "TINYINT"; break; case "char": result = "CHAR"; break; case "date": result = "DATE"; break; case "datetime": result = "DATETIME"; break; case "datetimeoffset": result = "DATETIMEOFFSET"; break; case "decimal": result = $"DECIMAL({typeInfo.GetStereotypeProperty("Decimal Constraints", "Precision", "18")}, {typeInfo.GetStereotypeProperty("Decimal Constraints", "Scale", "2")})"; break; case "double": result = "FLOAT"; break; case "float": result = "FLOAT"; break; case "guid": result = "UNIQUEIDENTIFIER"; break; case "int": result = "INT"; break; case "long": result = "BIGINT"; break; case "object": throw new Exception("Cannot convert type 'object' to a valid SQL Data Type"); break; case "short": result = "SMALLINT"; break; case "string": var type = typeInfo.GetStereotypeProperty("Text Constraints", "SQL Data Type", "NVARCHAR").Replace("DEFAULT", "NVARCHAR"); result = $"{type}({typeInfo.GetStereotypeProperty("Text Constraints", "MaxLength", typeInfo.GetStereotypeProperty("Text Constraints", "Max Length", "MAX"))})"; break; } result += $" {(typeInfo.IsNullable ? "NULL" : "NOT NULL")}"; return(new ResolvedTypeInfo(result, true, null)); }