Class NeonAssemblyExtensions
Implements custom Assembly extension methods.
Namespace: Neon.Common
Assembly: Neon.Common.dll
Syntax
public static class NeonAssemblyExtensions
Methods
GetExtensionMethodsFor(Assembly, Type, bool)
Retrieves all of the extensions methods in an assembly targeting a specific type.
note
This doesn't currently support nested or generic target types.
Declaration
public static IEnumerable<MethodInfo> GetExtensionMethodsFor(this Assembly assembly, Type targetType, bool allowPrivate = false)
Parameters
Type | Name | Description |
---|---|---|
Assembly | assembly | The source assembly. |
Type | targetType | The type being extended. |
bool | allowPrivate | Optionally specifies that only private methods are to be returned as well as public ones. |
Returns
Type | Description |
---|---|
IEnumerable<MethodInfo> | The extension methods. |
GetResourceFileSystem(Assembly, string)
Returns an eumlated static file system that includes some or all of an assembly's embedded resources. This method returns the root IStaticDirectory for the file system.
Declaration
public static IStaticDirectory GetResourceFileSystem(this Assembly assembly, string resourcePrefix = null)
Parameters
Type | Name | Description |
---|---|---|
Assembly | assembly | The target assembly. |
string | resourcePrefix | Specifies the resource name prefix to be used to identify the embedded resources to be included in the static file system. See the remarks for more information. |
Returns
Type | Description |
---|---|
IStaticDirectory | The root IStaticDirectory. |
Remarks
This method maps Linux style paths (using forward not back slashes) to embedded resources in the assembly. Resources in .NET projects are embedded and named like:
where ASSEMBLY-NAME is the name of the source assembly, DIR optionally specifies the directoriea to the resource and RESOURCE-FILENAME specifies the name of the resource file.
When a .NET project is built, any source files with build actions set to Embedded Resource will be included in the assembly using the naming convention described above. The ASSEMBLY-NAMESPACE will be set to the source projects default namespace and the DIRs will be set to the relative path from the project file to the source resource file. For example, if your project is structured like:
my-project/
my-project.csproj
top-level.txt
resources/
resource1.dat
resource2.dat
tests/
test1.txt
test2.txt
samples/
sample1.txt
sample2.txt</code></pre>
and its default namespace is company.mproject, then the following resources embedded
in your project assembly:
company.my-project.top-level.txt
company.my-project.resources.resource1.dat
company.my-project.resources.resource2.dat
company.my-project.resources.tests.test1.txt
company.my-project.resources.tests.test2.txt
company.my-project.resources.samples.sample1.txt
company.my-project.resources.samples.sample2.txt
By default, calling GetResourceFileSystem(Assembly, string) on your project assembly
will return a IStaticDirectory with a directory structure holding all of the resources.
The paths are mapped from the resource names by converting any dots except for the last one into forward
slashes.
/
company/
my-project/
top-level.txt
resources/
resource1.dat
resource2.dat
tests/
test1.txt
test2.txt
samples/
sample1.txt
sample2.txt
You can also pass an optional resource name prefix so that only a subset of the resources
are included in the file system. For example, by passing company.my-project.resources,
file system returned will look like:
/
resource1.dat
resource2.dat
tests/
test1.txt
test2.txt
samples/
sample1.txt
sample2.txt
RESOURCE NAMING AMBIGUITIES
When creating the file system from resource names, it's possible to encounter situations
where it's not possible to distingish between a a directory and a file name. For example:
company.my-project.resources.resource1.dat
Here are some possibilities:
-
path is /company.my-project.resources.resource1 and the file name dat
-
path is /company.my-project.resources and the file name resource1.dat
-
path is /company.my-project and the file name .resources.resource1.dat
There is really no way for this method to know what the original resource source files
and directory paths were. To resolve this, we're going to assume that resource file
names include a file extension with a single dot and that any additional dots will form
the file's parent directory path.
note
All resource file names must include an extension to be loaded properly. If you need
a file to be loaded without an extension, save the file with the special "._"
extension like test._. This method will remove that special extension when reading
files with it.
What this means is that your resource file names must include a file extension. So, file
names like this are OK:
schema.sql
config.json
You should avoid file names like:
schema.1.sql
and use something like a dash instead so that schema won't be considered to
be part of the file's parent directory path:
schema-1.sql