Created
May 8, 2014 07:09
-
-
Save oyvindholmstad/d6b3a5416a2e254fa130 to your computer and use it in GitHub Desktop.
Fsharp EmbeddedResourceManager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System; | |
open System.IO; | |
open System.Reflection; | |
module EmbeddedResourceManager = | |
let assembly = Assembly.GetCallingAssembly() | |
let private GetCompleteResourceName ( resourceName: string) = | |
let matches = | |
assembly.GetManifestResourceNames() | |
|> Array.toList | |
|> List.filter (fun x -> x.EndsWith(resourceName, StringComparison.CurrentCultureIgnoreCase)) | |
if List.isEmpty matches then | |
"" | |
else | |
List.nth matches 0 | |
let ReturnResourceAsAString (completeResourceName : string) = | |
use stream = assembly.GetManifestResourceStream(completeResourceName) | |
let reader = new StreamReader(stream) | |
reader.ReadToEnd() | |
let getFileLines (resourceName: string) = | |
let resourceAsString = | |
GetCompleteResourceName resourceName | |
|> ReturnResourceAsAString | |
resourceAsString.Split([|'\r'; '\n';|]) | |
|> Seq.toList |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment