F#类/模块中自动生成的静态字段会阻止创建SQL CLR函数
||
我正在尝试用F#编写CLR用户定义函数,但是
CREATE ASSEMBLY
给出错误:
CREATE ASSEMBLY失败,因为在安全程序集\'MyNamespace.SqlServer.Text \'中键入\'StringMetrics \'具有静态字段\'field1776 @ \'。安全程序集中静态字段的属性必须在Visual C#中标记为只读,在Visual Basic中标记为只读,或者在Visual C ++和中间语言中标记为initonly。
这是Reflector中的外观。这不是我明确创建的字段。
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
internal static <PrivateImplementationDetails$MyNamespace-SqlServer-Text>.T1775_18Bytes@ field1776@; // data size: 18 bytes
我尝试使用模块和类。两者都在不同的地方生成场。这个字段是做什么用的?有没有办法避免其创建?我应该使用另一种方法在F#中创建CLR函数吗?可能吗
完整的代码
namespace MyNamespace.SqlServer.Text
module StringMetrics =
open System
open System.Collections.Generic
open System.Data
open System.Data.SqlTypes
[<CompiledName(\"FuzzyMatch\")>]
let fuzzyMatch (strA:SqlString) (strB:SqlString) =
if strA.IsNull || strB.IsNull then SqlInt32.Zero
else
let comparer = StringComparer.OrdinalIgnoreCase
let wordBoundaries = [|\' \'; \'\\t\'; \'\\n\'; \'\\r\'; \',\'; \':\'; \';\'; \'(\'; \')\'|]
let stringEquals a b = comparer.Equals(a, b)
let isSubstring (search:string) (find:string) = find.Length >= search.Length / 2 && search.IndexOf(find, StringComparison.OrdinalIgnoreCase) >= 0
let split (str:string) = str.Split(wordBoundaries)
let score (strA:string) (strB:string) =
if stringEquals strA strB then strA.Length * 3
else
let lenA, lenB = strA.Length, strB.Length
if strA |> isSubstring strB then lenA * 2
elif strB |> isSubstring strA then lenB * 2
else 0
let arrA, arrB = split strA.Value, split strB.Value
let dictA, dictB = Dictionary(), Dictionary()
arrA |> Seq.iteri (fun i a ->
arrB |> Seq.iteri (fun j b ->
match score a b with
| 0 -> ()
| s ->
match dictB.TryGetValue(j) with
| true, (s\', i\') -> //\'
if s > s\' then //\'
dictA.Add(i, j)
dictB.[j] <- (s, i)
| _ ->
dictA.Add(i, j)
dictB.Add(j, (s, i))))
let matchScore = dictB |> Seq.sumBy (function (KeyValue(_, (s, _))) -> s)
let nonMatchA =
arrA
|> Seq.mapi (fun i a -> i, a)
|> Seq.fold (fun s (i, a) ->
if dictA.ContainsKey(i) then s
else s + a.Length) 0
let wordsB = HashSet(seq { for (KeyValue(i, _)) in dictB -> arrB.[i] }, comparer)
let nonMatchB =
arrB |> Seq.fold (fun s b ->
if wordsB.Add(b) then s + b.Length
else s) 0
SqlInt32(matchScore - nonMatchA - nonMatchB)
没有找到相关结果
已邀请:
1 个回复
舞备联
数组生成的。如果改为将其表示为列表,并在运行时将其转换为数组,则不会生成此内部静态字段:
但是,似乎函数本身也表示为静态的,非只读的 领域:
也许使用类而不是模块可以解决此问题。