0
F #에서 매우 새로 도입되었습니다. 이 클래스가 있습니다.멤버 함수에서 클래스의 멤버 변수에 할당하는 방법
namespace FsharpTestSystem
open System
open System.IO
open System.Text
open System.Diagnostics
open System.CodeDom
open Microsoft.FSharp.Compiler.SourceCodeServices
open Microsoft.FSharp.Compiler.Interactive.Shell
open Microsoft.FSharp.Compiler.SimpleSourceCodeServices
type TestSystem() =
// Intialize output and input streams
// Build command line arguments & start FSI session
let argv = [| "C:\\Program Files (x86)\\Microsoft SDKs\\F#\\4.1\\Framework\\v4.0\\fsi.exe" |]
let allArgs = Array.append argv [|"--noninteractive"|]
let sbOut = new StringBuilder()
let sbErr = new StringBuilder()
let inStream = new StringReader("")
let outStream = new StringWriter(sbOut)
let errStream = new StringWriter(sbErr)
let fsiConfig = FsiEvaluationSession.GetDefaultConfiguration()
....
이 클래스에 멤버 메서드 (함수)를 추가합니다. 하지만 나머지 멤버가 볼 수 있도록 클래스의 멤버 변수에 반환 값을 할당하려면 어떻게해야합니까? 다른 말로하면 fsis
은 다른 구성원이 사용해야합니다.
C#에서는 속성을 사용하는 것이 간단합니다. F # 시스템에 선언 할 때 fsis
이 어떻게 든 변할 수 있다고 말할 필요가 있다고 생각합니다. 해시 코드에서
type TestSystem() =
// ....
[<DefaultValue>] val mutable Fsis : FsiEvaluationSession
member __.LoadFsis() = __.Fsis <- FsiEvaluationSession.Create(fsiConfig, allArgs, inStream, outStream, errStream)
member __.UseFsis() = __.Fsis.GetHashCode()
let ts = TestSystem()
ts.LoadFsis()
ts.UseFsis()
ts.Fsis.GetHashCode()
ts.LoadFsis()
ts.UseFsis()
(I 가정) 당신만큼 당신이 .LoadFsis
하지 않는 한 그것을 사용하는 것을 볼 수 있습니다 : 이것에 대해 어떻게
member this.LoadFSI() =
fsis = FsiEvaluationSession.Create(fsiConfig, allArgs, inStream, outStream, errStream)
member this.UseFSI() =
//I need to use fsis in here.
예를 들어, 클래스 내에서 fsiConfig 등을 사용하려면 어떻게해야합니까? 당신이 원하는 것을 C#에서 간단하게 게시 할 수 있습니까? – s952163
F # 예제를 수정했습니다. 이러한 변수는 FsiEvaluationSession.Create 함수를 초기화하는 경우를 제외하고는 관계가 없습니다. 그 후에 그들은 사용되지 않습니다. – Ivan
BTW, FsiEvaluationSession.Create를 생성자에서 수행 할 수없는 이유는 거기에 넣으면 프로그램이 충돌한다는 것입니다. 멤버 함수에 넣으면 작동합니다. 그러나 다른 곳에서는 반환 값에 액세스 할 수 없습니다. – Ivan