EmbeddedSharpFiles 2.0.0

dotnet add package EmbeddedSharpFiles --version 2.0.0
NuGet\Install-Package EmbeddedSharpFiles -Version 2.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EmbeddedSharpFiles" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EmbeddedSharpFiles --version 2.0.0
#r "nuget: EmbeddedSharpFiles, 2.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install EmbeddedSharpFiles as a Cake Addin
#addin nuget:?package=EmbeddedSharpFiles&version=2.0.0

// Install EmbeddedSharpFiles as a Cake Tool
#tool nuget:?package=EmbeddedSharpFiles&version=2.0.0

EmbeddedSharpFiles

EmbeddedSharpFiles is a .NET Standard 2.0 compatible library to manage embedded files in loaded assemblies.

Usage

Note: EmbeddedSharpFiles is not able to automatically read all embedded files

First, we have to create an EmbeddedFile instance referencing our embedded file. We have to pass both the containing assembly and the namespace. As both are contained in the Type class you can also pass a Type instance

var embeddedFile = new EmbeddedFile("myembedded-file-name.bin", typeof(SomeClassInTheNamespace));

If the resource lies in a subfolder, the folder is part of the name:

var embeddedFile = new EmbeddedFile("myResourceFolder.myembedded-file-name.bin", typeof(SomeClassInTheNamespace));

Now this instance can be used to either get the stream to the content, the string contained in the embedded file, or it can directly be extracted to a certain file. The content string is created using UTF-8.

using(var contentStream = embeddedFile.ContentStream)
{
	//...
}
var content = embeddedFile.ContentString;
embeddedFile.ExtractTo(@"C:\Foo\Bar\myextractedfile.bin");

//If no file name is stored in the EmbeddedFile instance and no
//file name is passed to .ExtractTo, the resource name is used.
embeddedFile.ExtractToDirectory(@"C:\Foo\Bar"); // -> Extracts to C:\Foo\Bar\myebedded-file-name.bin

//While .ExtractTo and .ExtractToDirectory will throw an exception if something goes wrong,
//.TryExtractTo and .TryExtractToDirectory will catch exceptions and return a bool indicating
//whether extraction was successfull
embeddedFile.TryExtractToDirectory(@"C:\Foo\Bar", "myextractedfile.bin");

EmbeddedFileDictionary

To store and globally access your embedded files from different classes, instances or modules, there's the EmbeddedFileDictionary. Basically, it's just a .NET Dictionary<string, EmbeddedFile> with some managing code around it.

To store and retrieve embedded files, use methods .GetFile and .SetFile. If a requested entry isn't found, null is returned.

EmbeddedDictionary.SetFile("myembedded-file", embeddedFile);
/* ... */

var file = EmbeddedFileDictionary.GetFile("myembedded-file");
Events

EmbeddedFileDictionary provides some events to inject into get- and set-calls, but these currently aren't documented.

Logging

EmbeddedSharpFiles provides a logging interface so the main application can log actions done by this library.

It is as simple as the static class GenericSharpLoading provides the event OnLog which is fired every time the library would log something.

Along with the message, a log level is given, which is just a string containing the word DEBUG, INFO, WARNING or ERROR. These strings will probably always be the same, but if you want to process it, I would recommend to use the class GenericSharpLoading.LogLevel (nested class) and its four constants DEBUG, INFO, WARNING or ERROR which names are guaranteed to be never changed.

Example

class MyClass
{
	void Init()
	{
		GenericSharpLoading.GenericSharpLoading.OnLog += this.Log;

		//...
	}

	void Log(string message, string logLevel)
	{
		Console.WriteLine($"[MyApplication][{logLevel}] {message}");
	}
}

License

EmbeddedSharpFiles is licensed under the MIT License

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 749 1/13/2019
1.0.0 918 5/6/2018