123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- #region --------------- Copyright Dresser Wayne Pignone -------------
- #endregion
- using System;
- using System.IO;
- using System.Text.RegularExpressions;
- namespace Wayne.Lib
- {
-
-
-
- public static class Assemblies
- {
- #region FilePath Methods
-
-
-
-
- public static string GetFilePath()
- {
- return GetFilePath(System.Reflection.Assembly.GetCallingAssembly());
- }
-
-
-
-
-
- public static string GetFilePath(System.Reflection.Assembly assembly)
- {
- if (assembly == null)
- throw new NullReferenceException("assembly");
- return Path.GetDirectoryName(assembly.ManifestModule.FullyQualifiedName);
- }
- #endregion
- #region Resource Methods
-
-
-
-
-
-
- public static System.IO.Stream GetManifestResourceStreamWithPartialName(string knownResourceNameEnd,
- System.Reflection.Assembly assemblyWithResource)
- {
- if (knownResourceNameEnd == null)
- throw new ArgumentNullException("knownResourceNameEnd");
- if (assemblyWithResource == null)
- throw new ArgumentNullException("assemblyWithResource");
- string[] manifestResouceNames = assemblyWithResource.GetManifestResourceNames();
- string resourceName = "";
- foreach (string candidate in manifestResouceNames)
- {
- if (candidate.EndsWith(knownResourceNameEnd, StringComparison.InvariantCultureIgnoreCase))
- {
- resourceName = candidate;
- break;
- }
- }
- return assemblyWithResource.GetManifestResourceStream(resourceName);
- }
-
-
-
-
-
-
- public static System.IO.Stream GetManifestResourceStreamWithRegex(string resourceRegEx,
- System.Reflection.Assembly assemblyWithResource)
- {
- if (resourceRegEx == null)
- throw new ArgumentNullException("resourceRegEx");
- if (assemblyWithResource == null)
- throw new ArgumentNullException("assemblyWithResource");
- string[] manifestResouceNames = assemblyWithResource.GetManifestResourceNames();
- string resourceName = "";
- Regex regex = new Regex(resourceRegEx);
- foreach (string candidate in manifestResouceNames)
- {
- if (regex.IsMatch(candidate))
- {
- resourceName = candidate;
- break;
- }
- }
- return assemblyWithResource.GetManifestResourceStream(resourceName);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #endregion
- }
- }
|