本文整理汇总了C#中System.Reflection.Assembly.GetSatelliteAssembly方法的典型用法代码示例。如果您正苦于以下问题:C# Assembly.GetSatelliteAssembly方法的具体用法?C# Assembly.GetSatelliteAssembly怎么用?C# Assembly.GetSatelliteAssembly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Assembly
的用法示例。
在下文中一共展示了Assembly.GetSatelliteAssembly方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryGetSatelliteAssembly
bool TryGetSatelliteAssembly(CultureInfo culture, Assembly mainAssembly, ref Assembly satelliteAssembly)
{
try
{
satelliteAssembly = mainAssembly.GetSatelliteAssembly(culture);
return true;
}
catch (Exception)
{
return false;
}
}
示例2: GetLocalizedManifestResourceStream
public static Stream GetLocalizedManifestResourceStream(string manifestName, Assembly baseAssembly, CultureInfo culture)
{
if ((manifestName == null) || (manifestName.Length == 0))
{
throw new ArgumentNullException("manifestName");
}
if (baseAssembly == null)
{
throw new ArgumentNullException("baseAssembly");
}
if (culture == null)
{
throw new ArgumentNullException("culture");
}
Stream stream = baseAssembly.GetSatelliteAssembly(culture).GetManifestResourceStream(manifestName);
if ((stream == null) && manifestName.Contains("_"))
{
stream = baseAssembly.GetSatelliteAssembly(culture).GetManifestResourceStream(manifestName.Replace('_', ' '));
}
return stream;
}
示例3: GetLocalizedManifestResourceStreamIfExists
public static Stream GetLocalizedManifestResourceStreamIfExists(string manifestName, Assembly baseAssembly, CultureInfo culture)
{
if ((manifestName == null) || (manifestName.Length == 0))
{
throw new ArgumentNullException("manifestName");
}
if (baseAssembly == null)
{
throw new ArgumentNullException("baseAssembly");
}
if (culture == null)
{
throw new ArgumentNullException("culture");
}
try
{
return baseAssembly.GetSatelliteAssembly(culture).GetManifestResourceStream(manifestName);
}
catch (FileNotFoundException)
{
return null;
}
}
示例4: LoadSatellite
public TranslationBundle LoadSatellite(Assembly parentAssembly = null, Version assemblyVersion = null)
{
try
{
parentAssembly = parentAssembly ?? Assembly.GetEntryAssembly();
var parentAssemblyName = new AssemblyName(parentAssembly.FullName);
var assembly = parentAssembly.GetSatelliteAssembly(Culture, assemblyVersion);
var resourceNames = assembly.GetManifestResourceNames();
if (resourceNames.Length != 1)
throw new IOException("Satellite resource must contain exactly one manifest resource.");
var resourceName = string.Format("{0}.{1}.{2}", parentAssemblyName.Name, ResourceNamespace, Culture.Name);
var resourceManager = new ResourceManager(resourceName, assembly);
var obj = resourceManager.GetObject(ResourceObjectName);
if (!(obj is byte[])) throw new IOException("Invalid satellite resource object type.");
var stream = new MemoryStream((byte[])obj);
using (stream) Load(stream);
}
catch
{
if (!Silent) throw;
}
return (this);
}
示例5: ExceptionVerifier
public ExceptionVerifier(string assemblyName, ExceptionVerificationFlags flags, ITestOutputHelper output)
{
_output = output;
if (assemblyName == null)
throw new VerifyException("Assembly name cannot be null");
_verificationFlags = flags;
try
{
switch (assemblyName.ToUpper())
{
case "SYSTEM.XML":
{
var dom = new XmlDocument();
_asm = dom.GetType().GetTypeInfo().Assembly;
}
break;
//case "SYSTEM.DATA":
//{
// var ds = new DataSet();
// asm = ds.GetType().Assembly;
//}
// break;
default:
throw new FileLoadException("Cannot load assembly from " + GetRuntimeInstallDir() + assemblyName + ".dll");
//asm = Assembly.LoadFrom(GetRuntimeInstallDir() + assemblyName + ".dll");
//break;
}
if (_asm == null)
throw new VerifyException("Can not load assembly " + assemblyName);
// let's determine if this is a loc run, if it is then we need to load satellite assembly
_locAsm = null;
if (!CultureInfo.CurrentCulture.Equals(new CultureInfo("en-US")) && !CultureInfo.CurrentCulture.Equals(new CultureInfo("en")))
{
try
{
// load satellite assembly
_locAsm = _asm.GetSatelliteAssembly(new CultureInfo(CultureInfo.CurrentCulture.Parent.IetfLanguageTag));
}
catch (FileNotFoundException e1)
{
_output.WriteLine(e1.ToString());
}
catch (FileLoadException e2)
{
_output.WriteLine(e2.ToString());
}
}
}
catch (Exception e)
{
_output.WriteLine("Exception: " + e.Message);
_output.WriteLine("Stack: " + e.StackTrace);
throw new VerifyException("Error while loading assembly");
}
string[] resArray;
Stream resStream = null;
var bFound = false;
// Check that assembly manifest has resources
if (null != _locAsm)
resArray = _locAsm.GetManifestResourceNames();
else
resArray = _asm.GetManifestResourceNames();
foreach (var s in resArray)
{
if (s.EndsWith(".resources"))
{
resStream = null != _locAsm ? _locAsm.GetManifestResourceStream(s) : _asm.GetManifestResourceStream(s);
bFound = true;
if (bFound && resStream != null)
{
// Populate hashtable from resources
var resReader = new ResourceReader(resStream);
if (_resources == null)
{
_resources = new Hashtable();
}
var ide = resReader.GetEnumerator();
while (ide.MoveNext())
{
if (!_resources.ContainsKey(ide.Key.ToString()))
_resources.Add(ide.Key.ToString(), ide.Value.ToString());
}
resReader.Dispose();
}
//break;
}
}
if (!bFound || resStream == null)
throw new VerifyException("GetManifestResourceStream() failed");
}
示例6: AddAssembly
/// <summary>
/// Adds the given assembly to the included set, if and only
/// if it is not contained by the encountered set and it
/// is not a system assembly; a core HSQLDB assembly; an
/// IKVM assembly; an NUnit assembly or a TestDriven.NET
/// assembly.
/// </summary>
/// <remarks>
/// The exclusion list could be made much larger to produce
/// a higher quality included set, but at what price?
/// </remarks>
/// <param name="encountered">The assemblies encountered so far.</param>
/// <param name="included">The assemblies included so far.</param>
/// <param name="entry">The assembly to add.</param>
internal static void AddAssembly(
Set encountered,
Set included,
Assembly entry)
{
if (entry == null || encountered.contains(entry))
{
return;
}
else
{
encountered.add(entry);
}
string simpleName = entry.GetName().Name;
// ignored (performance optimization)
if (simpleName == "System"
|| simpleName == "mscorlib"
|| simpleName == "Org.Hsqldb"
|| simpleName.StartsWith("System.")
|| simpleName.StartsWith("IKVM.")
|| simpleName.StartsWith("nunit.")
|| simpleName.StartsWith("TestDriven."))
{
return;
}
else
{
included.add(entry);
}
try
{
Assembly satellite =
entry.GetSatelliteAssembly(CultureInfo.CurrentCulture);
IkvmResourceLoaderFactory.AddAssembly(
encountered,
included,
satellite);
}
catch (Exception ex)
{
#if DEBUG
Debug.WriteLine(ex);
#endif
}
AssemblyName[] referencedAssemblies
= entry.GetReferencedAssemblies();
for (int i = 0; i < referencedAssemblies.Length; i++)
{
AssemblyName assemblyName = referencedAssemblies[i];
try
{
Assembly referencedAssembly
= Assembly.Load(assemblyName);
IkvmResourceLoaderFactory.AddAssembly(
encountered,
included,
referencedAssembly);
}
catch (System.Exception ex)
{
#if DEBUG
Debug.WriteLine(ex);
#endif
}
}
}