首页 > 解决方案 > 基类库中的 FlagsAttribute 枚举示例?

问题描述

在基类库中是否有一个用FlagsAttribute装饰的枚举示例?最好是一些易于解释、不太晦涩的东西,也许在 System 命名空间中?

标签: .net.net-coreenums

解决方案


这里有几个不错的:

我通过搜索网络找不到这个。我写了这个脚本:

open System
open System.Reflection

let isPublicFlagsEnum (t: Type) =
    t.IsEnum && 
    t.IsPublic &&
    not(isNull(t.GetCustomAttribute(typeof<FlagsAttribute>)))

typeof<String>.Assembly.GetTypes()
|> Seq.where(isPublicFlagsEnum)
|> Seq.map(fun t -> t.FullName)
|> Seq.sort
|> Seq.iter(printfn "%s")

推荐阅读