【问题标题】:In F# type providers how do I add a static class to a provided type?在 F# 类型提供程序中,如何将静态类添加到提供的类型?
【发布时间】:2018-08-14 12:40:45
【问题描述】:

如何将一个类型添加到另一个ProvidedType,并指定该类型是一个静态类?

【问题讨论】:

    标签: f# type-providers


    【解决方案1】:

    如何做到这一点并不是很明显,但您所要做的就是以TypeAttributes 的形式添加适当的元数据属性:

    //create a providedtype
    let myStaticType = ProvidedTypeDefinition("Tags", Some typeof<obj>, isErased = false)
    
    //set the TypeAttributes on the type
    myStaticType.SetAttributes (TypeAttributes.Public ||| TypeAttributes.Class ||| TypeAttributes.Sealed ||| TypeAttributes.Abstract)
    
    //Add the static type to another type
    parentType.AddMember myStaticType
    

    静态类型只是具有抽象和密封TypeAttributes的类型

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-20
      • 1970-01-01
      相关资源
      最近更新 更多