Support SmartEnums
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- csharp
- Domain
- backend-api-design
Research direction
Start by reviewing the DevExtreme.AspNet.Data library and the CustomFilterCompilers.RegisterBinaryExpressionCompiler example in the issue. Determine the supported SmartEnum scenarios and how native integration should cover them; done means SmartEnums work through the data layer without the custom compiler workaround.
Written by the indexing model from the issue text.
Description
Hello,
I wanted to submit a feature request for strongly typed enumerations, such as SmartEnum from Ardalis.
SmartEnums, or enhanced enums, have several advantages and can be a good alternative to default enumerations within data controls such as DataGrid, SelectBoxes and so on.
SmartEnums can be integrated into EntityFramework Core with conversions
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<Policy>()
.Property(p => p.PolicyStatus)
.HasConversion(
p => p.Value,
p => PolicyStatus.FromValue(p));
}
In the DevExpress Support Center, I have asked for help and Andrew did a great start on implementing this function
DevExtreme.AspNet.Data.Helpers.CustomFilterCompilers.RegisterBinaryExpressionCompiler(info => {
if (info.AccessorText.Contains(".") && info.Operation == "=" && info.Value is Int64) {
string accessorText = info.AccessorText.Substring(0, info.AccessorText.IndexOf("."));
var memberExpr = Expression.PropertyOrField(info.DataItemExpression, accessorText);
var memberType = memberExpr.Type;
if (typeof(Ardalis.SmartEnum.SmartEnum<>).MakeGenericType(memberType).IsAssignableFrom(memberType)) {
return Expression.MakeBinary(
ExpressionType.Equal,
Expression.Convert(Expression.Convert(memberExpr, typeof(object)), typeof(long)),
Expression.Constant(info.Value)
);
}
}
return null;
});
The problem is that it may cannot covers all possible scenarios.
The key solution would be a native integration in the DevExtreme.AspNet.Data library.
By the way, SmartEnums can also be integrated within DevExpress XPO using a custom ValueConverter
public class ProductStateConverter : ValueConverter {
public override Type StorageType => typeof(int);
public override object ConvertFromStorageType(object value) {
int.TryParse(value.ToString(), out int number);
return ProductState.TryFromValue(number, out ProductState retVal) ? retVal : null;
}
public override object ConvertToStorageType(object value) {
if (value is ProductState ruleType)
return ruleType.Value;
return null;
}
}
- Dominant language
- C#
- Stars
- 165
- Forks
- 140
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 4
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from DevExpress/DevExtreme.AspNet.Data
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
DevExpress/DevExtreme.AspNet.Data#588 · 3 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Dependency Dashboard Open
Difficulty 4/5 3-5 days Newbie friendliness 15/100
-
ES6 support Openenhancement
Difficulty 5/5 Over a week Newbie friendliness 25/100
All issues in DevExpress/DevExtreme.AspNet.Data
Similar issues
-
type/automation type/tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
t/bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
ci-failure-cause test-failure
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
area:auth FE mvp P3
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
klasolsson81/jobbliggaren#1788 ·