2016-04-18 28 views
1

我已經搜索過了,但沒有人看到F#.fsx腳本找不到名稱空間的問題。我已經有了Common project,它可以在另一個項目中使用intellisense編譯,但是在同一個項目中的腳本聲稱它沒有定義,即使懸停在#r「Common.dll」上查找完整路徑。通用代碼:在F#中找不到名稱空間#fsx

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。什麼不見​​了?

回答

1

您還需要打開Guid模塊,或使用[<AutoOpen>]屬性對其進行註釋。這將解決對System.Guid.FromName的引用。

然後,您還需要打開System名稱空間才能訪問Guid構造函數(或直接調用System.Guid)。

+0

大量的擺弄之後,它似乎是一個F#互動的東西。我正在使用交互命令執行。如果我先選擇腳本的文本,它會起作用。如果我只是右鍵點擊文件,它會給出錯誤。即使在打開Guid模塊並添加[]之後,智能感應仍然顯示警告。 –

相關問題