Skip to content

Commit

Permalink
#624 Fixed the Enum Type Flags Attribute.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikependon committed Oct 27, 2020
1 parent 2aad4d1 commit b42cbdf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ public void TestInsertForEnum()
Assert.AreEqual(entity.SessionId, id);

// Act
var queryResult = connection.Query<FlaggedEnumForIntCompleteTable>(id);
var queryResult = connection.Query<EnumCompleteTable>(id);

// Assert
Helper.AssertPropertiesEquality(entity, queryResult.First());
Expand Down Expand Up @@ -517,7 +517,7 @@ public void TestInsertForEnumAsIntForString()
Assert.AreEqual(entity.SessionId, id);

// Act
var queryResult = connection.Query<FlaggedEnumForIntCompleteTable>(id);
var queryResult = connection.Query<EnumAsIntForStringCompleteTable>(id);

// Assert
Helper.AssertPropertiesEquality(entity, queryResult.First());
Expand Down
10 changes: 3 additions & 7 deletions RepoDb.Core/RepoDb/Reflection/Compiler/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ internal static Expression ConvertEnumExpressionToTypeExpression(Expression expr
/// <returns></returns>
internal static Expression ConvertEnumExpressionToTypeExpressionForString(Expression expression)
{
var method = typeof(Enum).GetMethod("GetName", new[] { StaticType.Type, StaticType.Object });
var method = StaticType.Convert.GetMethod("ToString", new[] { StaticType.Object });

// Variables
var isNullExpression = (Expression)null;
Expand All @@ -671,12 +671,8 @@ internal static Expression ConvertEnumExpressionToTypeExpressionForString(Expres
}

// False
var parameters = new Expression[]
{
Expression.Constant(expression.Type.GetUnderlyingType()),
ConvertExpressionToTypeExpression(expression, StaticType.Object)
};
falseExpression = ConvertExpressionToTypeExpression(Expression.Call(method, parameters), StaticType.String);
var methodCallExpression = Expression.Call(method, ConvertExpressionToTypeExpression(expression, StaticType.Object));
falseExpression = ConvertExpressionToTypeExpression(methodCallExpression, StaticType.String);

// Call and return
return isNullExpression == null ? falseExpression :
Expand Down

0 comments on commit b42cbdf

Please sign in to comment.