dotnetcore / dotnetcore/osharp

收集实体信息时,如果字段类型是枚举定义,枚举继承 ushort,则会报错

Open
#304 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
2.8k
Forks
763
PR merge metrics
No merged PRs in 30d

Description

### 描述一下BUG
定义一个枚举,继承 ushort
``` C#
public enum EGenderType : ushort
{
男 = 0,
女 = 1,
未知性别 = 2,
未说明性别 = 9
}
```

### 重现步骤

1. 启动,在收集实体信息时报错
```
System.InvalidCastException
HResult=0x80004002
Message=Unable to cast object of type 'AuthCenter.Core.Enums.EGenderType' to type 'System.Int32'.
Source=System.Linq
StackTrace:
在 System.Linq.Enumerable.d__68`1.MoveNext() 在 /_/src/libraries/System.Linq/src/System/Linq/Cast.cs 中: 第 55 行
在 System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items) 在 /_/src/libraries/Common/src/System/Collections/Generic/LargeArrayBuilder.SpeedOpt.cs 中: 第 112 行
在 System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source) 在 /_/src/libraries/Common/src/System/Collections/Generic/EnumerableHelpers.Linq.cs 中: 第 84 行
在 OSharp.Authorization.EntityInfos.EntityInfoBase.<>c.b__18_1(PropertyInfo property)
在 System.Linq.Enumerable.WhereSelectArrayIterator`2.ToArray() 在 /_/src/libraries/System.Linq/src/System/Linq/Where.SpeedOpt.cs 中: 第 218 行
在 OSharp.Authorization.EntityInfos.EntityInfoBase.FromType(Type entityType)
在 OSharp.Authorization.EntityInfos.EntityInfoHandlerBase`2.Initialize()
在 OSharp.Authorization.EntityInfos.EntityInfoPack.UsePack(IServiceProvider provider)
在 Microsoft.AspNetCore.Builder.ApplicationBuilderExtensions.UseOSharp(WebApplication app)
在 Schoolmate.Startup.Configure(WebApplication app) 在 D:\Workspace\QBN\Schoolmate\Schoolmate\Startup.cs 中: 第 62 行
在 Program.$(String[] args) 在 D:\Workspace\QBN\Schoolmate\Schoolmate\Program.cs 中: 第 9 行
```

### 期望行为
枚举转换时不应该粗暴的转成int

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.