Reputation: 45295
I would like to use F# to develop windows 8.1 universal app. So I have created F# portable library. But unfortunately I can not open Windows.Storage namespace on it.
Then I have created C# Windows Apps Class Library where I have implemented the function I was needed:
public static async Task<string> ReadFileToString(string filename)
{
StorageFile file = await StorageFile.GetFileFromPathAsync(filename);
string fileContent = "";
fileContent = await FileIO.ReadTextAsync(file);
return fileContent;
}
Then I want to Add Reference in my F# Portable Library to this C# Library but get the error message, that
"it is impossible because the project is designed for platform (.NETCore) which different from current (.NETPortable)"
It is possible to use F# to develop windows 8 universal app ?
Upvotes: 2
Views: 340
Reputation: 45295
Here is the solution I have found.
Here is code of f# library:
namespace PortableLibrary1
open PCLStorage
type MyClass() =
member this.Do (filename : string) (text : string) =
let folder = FileSystem.Current.LocalStorage
async {
let! result = Async.AwaitTask(folder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting))
result.WriteAllTextAsync(text) |> ignore
} |> Async.RunSynchronously
And here is a C# Store App code:
private void Button_Click(object sender, RoutedEventArgs e)
{
MyClass cls = new MyClass();
cls.Do("uuu.ii", "message of me");
}
Upvotes: 1