在 XSLT C# 脚本块中添加对程序集的引用
add reference to assembly in XSLT C# script block
我正在尝试在 XSLT1.0 文档中嵌入的 C# 脚本块中使用字典。
当我尝试添加对 System.Collections.Generic 或 System.Core 的引用时,我得到一个 'metadata file not found for assembly...'
将 ref 添加到 'mscorlib' 时,似乎正在引用旧版本(?),因为我在尝试使用 Dictionary.Keys.Contains() 时遇到错误('不包含 Contains 方法) .
不用说,这段代码在 xslt 之外测试成功。
如何向 FW 3.5/4 添加适当的引用?
谢谢!
Dictionary.Keys.Contains
定义在System.Linq
命名空间,Linq定义在System.Core程序集,所以你需要正确的msxsl:assembly
和msxsl:using
元素。以下在 VS2013 XSLT 调试器中对我有用:
<msxsl:script implements-prefix="my" language="csharp">
<msxsl:assembly name="System.Core" />
<msxsl:using namespace="System.Linq" />
<msxsl:using namespace="System.Collections.Generic" />
<![CDATA[
public bool myFunc()
{
var d = new Dictionary<string, string>();
d.Add("Hello", "Goodbye");
return d.Keys.Contains("Hello");
}
]]>
</msxsl:script>
这仍然留下了一个问题,即当您可以使用 Dictionary.ContainsKey
时,您为什么使用 Dictionary.Keys.Contains
,它自 2.0 以来一直在 .NET 中并且不需要任何额外的程序集或名称空间引用.
我正在尝试在 XSLT1.0 文档中嵌入的 C# 脚本块中使用字典。 当我尝试添加对 System.Collections.Generic 或 System.Core 的引用时,我得到一个 'metadata file not found for assembly...' 将 ref 添加到 'mscorlib' 时,似乎正在引用旧版本(?),因为我在尝试使用 Dictionary.Keys.Contains() 时遇到错误('不包含 Contains 方法) . 不用说,这段代码在 xslt 之外测试成功。 如何向 FW 3.5/4 添加适当的引用? 谢谢!
Dictionary.Keys.Contains
定义在System.Linq
命名空间,Linq定义在System.Core程序集,所以你需要正确的msxsl:assembly
和msxsl:using
元素。以下在 VS2013 XSLT 调试器中对我有用:
<msxsl:script implements-prefix="my" language="csharp">
<msxsl:assembly name="System.Core" />
<msxsl:using namespace="System.Linq" />
<msxsl:using namespace="System.Collections.Generic" />
<![CDATA[
public bool myFunc()
{
var d = new Dictionary<string, string>();
d.Add("Hello", "Goodbye");
return d.Keys.Contains("Hello");
}
]]>
</msxsl:script>
这仍然留下了一个问题,即当您可以使用 Dictionary.ContainsKey
时,您为什么使用 Dictionary.Keys.Contains
,它自 2.0 以来一直在 .NET 中并且不需要任何额外的程序集或名称空间引用.