在提供的类型上获取编译错误 [英] Getting compile error on provided type

查看:72
本文介绍了在提供的类型上获取编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用TypeProvider来读取XSD文件,并为XSD中定义的每种类型提供一种类型.但是我在下面的代码中有问题

I'm working on a TypeProvider that reads an XSD file and provides a type for each type defined in the XSD. However I have a problem in the below code

type schema = XmlProviders.Schema<"file.xsd">
type Bazzer = {
    Sum : XmlProviders.bar
}

在最后一行,我得到一个编译错误,指出XmlProviders.bar不存在. 我如何定义类型的实现如下

on the last line I get a compilation error saying that XmlProviders.bar does not exist. The implementation of how I define the types are as follows

let defineType (xType : XElement) =
    let name = xType.Attribute(XName.Get "name").Value
    let t = ProvidedTypeDefinition(thisAssembly,
                                       ns,
                                       name,
                                       baseType = Some typeof<obj>)

    let ctor = ProvidedConstructor(parameters = [ ], 
                                   InvokeCode= (fun args -> <@@ "" :> obj @@>))
    t.AddMember ctor



 do provider.DefineStaticParameters(parameters, fun tyName args ->

    let filename = args.[0] :?> string
    let main = ProvidedTypeDefinition(thisAssembly,ns,
                                       tyName,
                                       baseType = Some typeof<obj>)

    //Elements is a list of XElement
    elements |> List.map defineType |> ignore
    main

我知道创建了XmlProviders.bar类型,因为如果我在defineType provider.AddMember t中添加额外的行,则会出现错误提示

I know that a XmlProviders.bar type is created because if I add an additional line to defineType provider.AddMember t then I get an error saying

类型提供程序'XmlProviders.SampleTypeProvider'报告了一个错误:'XmlProviders.bar'的容器类型已经设置为'XmlProviders.Schema'

The type provider 'XmlProviders.SampleTypeProvider' reported an error: container type for 'XmlProviders.bar' was already set to 'XmlProviders.Schema'

XmlProviders.Schema是由provider

对于为什么编译器抱怨类型不存在而我有些迷惑,如果我显式添加它,我会得到一个错误,即它已经存在

I'm a bit lost on why the compiler complains that the type is not there while if I explicitly add it I get the error that it's already there

推荐答案

找到了答案,所以对于那些遇到相同情况的人

Found the answer, so to those that end in the same situation

线

let t = ProvidedTypeDefinition(thisAssembly,
                                   ns,
                                   name,
                                   baseType = Some typeof<obj>)

其中定义嵌套类型的位置应没有程序集和名称空间

where the nested type is defined should be without assembly and namespace

let t = ProvidedTypeDefinition(name,baseType = Some typeof<obj>)

这篇关于在提供的类型上获取编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆