繁体   English   中英

在 F# fsx 中找不到命名空间

[英]Namespace not found in F# fsx

我已经搜索过这个,但似乎没有人遇到与 F# .fsx 脚本没有找到命名空间完全相同的问题。 我有一个构建良好的 Common 项目,并在另一个项目中被智能感知接收,但同一个项目中的脚本声明它没有定义,即使将鼠标悬停在 #r "Common.dll" 上找到完整路径。 通用代码:

namespace Common
open System
open System.Text
open System.Security.Cryptography

module Guid =
  let swapBytes (a: byte[]) = 
Array.concat [ Array.rev a.[..3] ; Array.rev a.[4..5] ; Array.rev a.[6..7]; a.[8..15] ]

// Implementaion of http://www.ietf.org/rfc/rfc4122.txt section 4.3 version 5 (Name Based using SHA-1)
// Based on C# at https://github.com/LogosBible/Logos.Utility/blob/master/src/Logos.Utility/GuidUtility.cs
type System.Guid with
  static member FromName (guid:System.Guid) (name:string) =
    let nameBytes: byte[] = Encoding.UTF8.GetBytes name
    let nameSpaceBytes = guid.ToByteArray() |> swapBytes

    use algorithm = SHA1.Create()
    algorithm.TransformBlock (nameSpaceBytes, 0, nameSpaceBytes.Length, null, 0) |> ignore
    algorithm.TransformFinalBlock(nameBytes, 0, nameBytes.Length) |> ignore
    let hash = algorithm.Hash;

    let newGuid = Array.create 16 0uy
    Array.Copy(hash, 0, newGuid, 0, 16)

    Array.set newGuid 6 ((newGuid.[6] &&& 0x0Fuy) ||| (5uy <<< 4))
    Array.set newGuid 8 ((newGuid.[8] &&& 0x3Fuy) ||| 0x80uy)

    newGuid |> swapBytes |> System.Guid

.fsx 内容:

#I @"..\Common\bin\Debug"
#r "Common.dll"
open Common

let NamedGuid = System.Guid.FromName (Guid("190bbe82-5692-43a4-b825-079f41fc55c0"))

这是在 VS2015 中。 有什么不见了?

您还需要打开Guid模块,或使用[<AutoOpen>]属性对其进行注释。 这将解析对System.Guid.FromName的引用。

完成此操作后,您还需要打开System命名空间以访问Guid构造函数(或直接调用System.Guid )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM