-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
377 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) Huy Hoang. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
|
||
namespace Dash.Engine.DataTypes | ||
{ | ||
public class BoolDataType : IDataType | ||
{ | ||
public string Name => "bool"; | ||
public bool IsNumeric => false; | ||
public bool IsDateTime => false; | ||
public bool IsBoolean => true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) Huy Hoang. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
|
||
using System; | ||
using Dash.Extensions; | ||
|
||
namespace Dash.Engine.DataTypes | ||
{ | ||
public static class DataTypeFactory | ||
{ | ||
private static IDataType[] DashDataTypes => new IDataType[] | ||
{ | ||
new StringDataType(), | ||
new IntDataType(), | ||
new BoolDataType(), | ||
new DateTimeDataType(), | ||
new UnicodeDataType(), | ||
new GuidDataType(), | ||
new EmailDataType(), | ||
}; | ||
|
||
public static IDataType Create(string dashDataType) | ||
{ | ||
foreach (var item in DashDataTypes) | ||
{ | ||
if (item.Name.IsSame(dashDataType)) | ||
{ | ||
return item; | ||
} | ||
} | ||
|
||
throw new InvalidOperationException($"Unknown Dash data type '{dashDataType}'"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) Huy Hoang. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
|
||
namespace Dash.Engine.DataTypes | ||
{ | ||
public class DateTimeDataType : IDataType | ||
{ | ||
public string Name => "DateTime"; | ||
public bool IsNumeric => false; | ||
public bool IsDateTime => true; | ||
public bool IsBoolean => false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) Huy Hoang. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
|
||
namespace Dash.Engine.DataTypes | ||
{ | ||
public class EmailDataType : IDataType | ||
{ | ||
public string Name => "email"; | ||
public bool IsNumeric => false; | ||
public bool IsDateTime => false; | ||
public bool IsBoolean => false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) Huy Hoang. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
|
||
namespace Dash.Engine.DataTypes | ||
{ | ||
public class GuidDataType : IDataType | ||
{ | ||
public string Name => "guid"; | ||
public bool IsNumeric => false; | ||
public bool IsDateTime => false; | ||
public bool IsBoolean => false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) Huy Hoang. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
|
||
namespace Dash.Engine.DataTypes | ||
{ | ||
public class IntDataType : IDataType | ||
{ | ||
public string Name => "int"; | ||
public bool IsNumeric => true; | ||
public bool IsDateTime => false; | ||
public bool IsBoolean => false; | ||
|
||
public static IntDataType Default => new IntDataType(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) Huy Hoang. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
|
||
namespace Dash.Engine.DataTypes | ||
{ | ||
public class StringDataType : IDataType | ||
{ | ||
public string Name => "string"; | ||
public bool IsNumeric => false; | ||
public bool IsDateTime => false; | ||
public bool IsBoolean => false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) Huy Hoang. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
|
||
namespace Dash.Engine.DataTypes | ||
{ | ||
public class UnicodeDataType : IDataType | ||
{ | ||
public string Name => "unicode"; | ||
public bool IsNumeric => false; | ||
public bool IsDateTime => false; | ||
public bool IsBoolean => false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) Huy Hoang. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
|
||
namespace Dash.Engine | ||
{ | ||
/// <summary> | ||
/// Abstract representation of a Dash Data Type defined in the Model File. | ||
/// </summary> | ||
public interface IDataType | ||
{ | ||
public string Name { get; } | ||
|
||
public bool IsNumeric { get; } | ||
|
||
public bool IsDateTime { get; } | ||
|
||
bool IsBoolean { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/Dash/src/Dash/Engine/TemplateTransformers/Scriban/CSharpOutputHelpers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) Huy Hoang. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
|
||
using Dash.Engine.Models; | ||
|
||
namespace Dash.Engine.TemplateTransformers.Scriban | ||
{ | ||
public static class CSharpOutputHelpers | ||
{ | ||
public static string GetCSharpLiteral(object value) | ||
{ | ||
if (value == null) | ||
{ | ||
return "null"; | ||
} | ||
|
||
if (value is int intValue) | ||
{ | ||
return intValue.ToString(); | ||
} | ||
|
||
if (value is decimal decimalValue) | ||
{ | ||
return $"{decimalValue}m"; | ||
} | ||
|
||
var v = value.ToString()!.Replace("\"", "\\\""); | ||
return $"\"{v}\""; | ||
} | ||
|
||
public static string GetPropertyDefaultValueAssignment(object value) | ||
{ | ||
const string code = "= null!;"; | ||
|
||
if (value is ReferencedEntityModel referencedEntity) | ||
{ | ||
if (!referencedEntity.IsNullable) | ||
{ | ||
return code; | ||
} | ||
} | ||
else if (value is AttributeModel attribute) | ||
{ | ||
if (attribute.DashDataType.IsNumeric || | ||
attribute.DashDataType.IsDateTime || | ||
attribute.DashDataType.IsBoolean) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
if (!attribute.IsNullable) | ||
{ | ||
return code; | ||
} | ||
} | ||
|
||
return string.Empty; | ||
} | ||
} | ||
} |
29 changes: 0 additions & 29 deletions
29
src/Dash/src/Dash/Engine/TemplateTransformers/Scriban/GetCSharpLiteralFormatter.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.