Skip to content

Instantly share code, notes, and snippets.

@oyvindholmstad
Created May 8, 2014 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oyvindholmstad/d6b3a5416a2e254fa130 to your computer and use it in GitHub Desktop.
Save oyvindholmstad/d6b3a5416a2e254fa130 to your computer and use it in GitHub Desktop.
Fsharp EmbeddedResourceManager
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