Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
netcoreplus
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
netcoreplus
Commits
1a86b42b
Commit
1a86b42b
authored
May 16, 2019
by
阿星Plus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enum Alias Attribute
✔
✔
✔
parent
d24fe49b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
0 deletions
+54
-0
EnumAliasAttribute.cs
src/Plus/CodeAnnotations/EnumAliasAttribute.cs
+17
-0
EnumExtensions.cs
src/Plus/CodeAnnotations/EnumExtensions.cs
+37
-0
No files found.
src/Plus/CodeAnnotations/EnumAliasAttribute.cs
0 → 100644
View file @
1a86b42b
using
System
;
namespace
Plus.CodeAnnotations
{
/// <summary>
/// 枚举属性,定义别名
/// </summary>
public
class
EnumAliasAttribute
:
Attribute
{
public
string
Alias
{
get
;
set
;
}
public
EnumAliasAttribute
(
string
alias
)
{
Alias
=
alias
;
}
}
}
\ No newline at end of file
src/Plus/CodeAnnotations/EnumExtensions.cs
0 → 100644
View file @
1a86b42b
using
System
;
using
System.Reflection
;
namespace
Plus.CodeAnnotations
{
/// <summary>
/// 枚举扩展
/// </summary>
public
static
class
EnumExtensions
{
/// <summary>
/// 获取枚举别名
/// </summary>
/// <param name="_enum"></param>
/// <returns></returns>
public
static
string
ToAlias
(
this
Enum
_enum
)
{
Type
type
=
_enum
.
GetType
();
FieldInfo
field
=
type
.
GetField
(
_enum
.
ToString
());
if
(
field
==
null
)
{
return
string
.
Empty
;
}
string
result
=
string
.
Empty
;
object
[]
customAttributes
=
field
.
GetCustomAttributes
(
typeof
(
EnumAliasAttribute
),
inherit
:
false
);
object
[]
array
=
customAttributes
;
for
(
int
i
=
0
;
i
<
array
.
Length
;
i
++)
{
EnumAliasAttribute
enumAliasAttribute
=
(
EnumAliasAttribute
)
array
[
i
];
result
=
enumAliasAttribute
.
Alias
;
}
return
result
;
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment