本文整理汇总了C#中System.Reflection.AssemblyName.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# AssemblyName.Contains方法的具体用法?C# AssemblyName.Contains怎么用?C# AssemblyName.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.AssemblyName
的用法示例。
在下文中一共展示了AssemblyName.Contains方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleAssemblyResolve
public static Assembly HandleAssemblyResolve(object sender, ResolveEventArgs args)
{
string assemblyName = new AssemblyName(args.Name).Name + ".dll";
if(assemblyName.Contains(".resources"))
{
//Console.WriteLine("AssemblyResolve: {0}", assemblyName);
return null;
}
string fullAssemblyName = string.Empty;
foreach(var manifestResource in Assembly.GetExecutingAssembly().GetManifestResourceNames())
{
if(manifestResource.Contains(assemblyName))
{
fullAssemblyName = manifestResource;
break;
}
}
if(fullAssemblyName == string.Empty)
return null;
using(var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(fullAssemblyName))
{
byte[] assemblyData = new byte[stream.Length];
stream.Read(assemblyData, 0, assemblyData.Length);
return Assembly.Load(assemblyData);
}
}
示例2: Run
public void Run()
{
string absoluteAssemblyDir = Path.GetFullPath(BuildAssemblyPath);
string assemblyPath = Path.Combine(absoluteAssemblyDir, BuildAssemblyName);
AppDomain.CurrentDomain.AssemblyResolve += (sender, e) =>
{
// FIXME: Imprecise
var requestedAssemblyName = new AssemblyName(e.Name).Name;
if (! requestedAssemblyName.Contains("System"))
{
string requestedAssemblyDll = requestedAssemblyName + ".dll";
foreach (string reference in References)
{
if (reference.ToLowerInvariant().Contains(requestedAssemblyDll.ToLowerInvariant()))
return Assembly.LoadFrom(reference);
}
var candidateAssemblyPath = Path.Combine(absoluteAssemblyDir, requestedAssemblyDll);
if (File.Exists(candidateAssemblyPath))
return Assembly.LoadFrom(candidateAssemblyPath);
}
return null;
};
string serializersAssemblyPath = Path.ChangeExtension(assemblyPath, ".XmlSerializers.dll");
Assembly assembly = Assembly.LoadFrom(assemblyPath);
List<Type> serializableTypes = new List<Type>();
foreach (Type type in assembly.GetExportedTypes())
{
if (type.IsDefined(typeof(XmlRootAttribute), false))
serializableTypes.Add(type);
}
List<XmlMapping> mappings = new List<XmlMapping>();
XmlReflectionImporter importer = new XmlReflectionImporter();
foreach (Type type in serializableTypes)
{
XmlMapping mapping = importer.ImportTypeMapping(type);
mappings.Add(mapping);
}
CompilerParameters compilerParameters = new CompilerParameters();
compilerParameters.TempFiles = new TempFileCollection();
compilerParameters.IncludeDebugInformation = false;
compilerParameters.GenerateInMemory = false;
compilerParameters.OutputAssembly = serializersAssemblyPath;
if (KeyFile != null)
compilerParameters.CompilerOptions += " /keyfile:\"" + KeyFile + "\"";
XmlSerializer.GenerateSerializer(serializableTypes.ToArray(),
mappings.ToArray(), compilerParameters);
}
示例3: OnAssemblyResolve
/// <summary>
/// Event handler method to resolve DLL assemblies that can't be found automatically.
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
/// <returns></returns>
internal static Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
{
Assembly assembly;
string keyName = new AssemblyName(args.Name).Name;
if (keyName.Contains(".resources"))
{
return null; // This line is what fixed the problem
}
//Go through hint paths to see if we can help add assembly references
var referenceFromHintPaths = _hintPaths.Where(p => p.EndsWith(string.Format(@"\{0}.dll", keyName)));
foreach (var hintPath in referenceFromHintPaths)
{
assembly = Assembly.LoadFile(hintPath);
if (!_libs.ContainsKey(keyName))
{
_libs.Add(keyName, assembly);
}
}
if (_libs.ContainsKey(keyName))
{
assembly = _libs[keyName]; // If DLL is loaded then don't load it again just return
return assembly;
}
string dllName = DllResourceName(keyName);
//string[] names = Assembly.GetExecutingAssembly().GetManifestResourceNames(); // Uncomment this line to debug the possible values for dllName
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(dllName))
{
if (stream == null)
{
LoggerBase.Log("Error! Unable to find '" + dllName + "'", true);
// Uncomment the next lines to show message the moment an assembly is not found. (This will also stop for .Net assemblies
//MessageBox.Show("Error! Unable to find '" + dllName + "'! Application will terminate.");
//Environment.Exit(0);
return null;
}
byte[] buffer = new BinaryReader(stream).ReadBytes((int)stream.Length);
assembly = Assembly.Load(buffer);
_libs[keyName] = assembly;
return assembly;
}
}
示例4: FindType
Type FindType(string name)
{
foreach (string use in usings)
{
name = (use != "" ? use + "." : "") + name;
if (name.Contains('.'))
{
name += ".";
int i = 0;
i = name.IndexOf('.');
string first = name.Substring(0, i);
Type t = null;
while ((t = Type.GetType(name.Substring(0, i))) == null)
{
i = name.IndexOf('.', i + 1);
}
return t;
}
else
{
Type t = Type.GetType(name);
if (t != null) return t;
}
}
throw new Exception("Type not found: " + name);
}
示例5: CurrentDomain_AssemblyResolve
/// <summary>
/// Resolve local path on HDInsight VM where the ADF .Net activity is running
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
/// <returns></returns>
public Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
var assemblyname = new AssemblyName(args.Name).Name;
if (assemblyname.Contains("Microsoft.WindowsAzure.Storage"))
{
assemblyname = "Microsoft.WindowsAzure.Storage";
var assemblyFileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), assemblyname + ".dll");
var assembly = Assembly.LoadFrom(assemblyFileName);
return assembly;
}
return null;
}