2016-04-18 11 views
1

私はこれを検索しましたが、F#.fsxスクリプトでは名前空間を見つけられないということで誰も同じ問題を抱えているようです。私は共通のプロジェクトを構築し、別のプロジェクトで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への参照が解決されます。

そして、あなたはあなたにもGuidコンストラクタにアクセスするためにSystem名前空間を開く(または直接System.Guidを呼び出す)する必要がありますが、それを行う後。

+0

Fiddlingをたくさんした後、F#Interactiveのように見えます。私は、インタラクティブで実行コマンドを使用していました。スクリプトのテキストを最初に選択すると、そのスクリプトが機能します。ファイルを右クリックすればエラーになります。インテリセンスは、Guidモジュールを開いて[]を追加した後でも、まだ警告を表示します。 –

関連する問題