本文整理汇总了C#中System.Reflection.Assembly类的典型用法代码示例。如果您正苦于以下问题:C# Assembly类的具体用法?C# Assembly怎么用?C# Assembly使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Assembly类属于System.Reflection命名空间,在下文中一共展示了Assembly类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Build
public Test Build(string assemblyName, string testName, bool autoSuites)
{
if (testName == null || testName == string.Empty)
return Build(assemblyName, autoSuites);
// Change currentDirectory in case assembly references unmanaged dlls
// and so that any addins are able to access the directory easily.
using (new DirectorySwapper(Path.GetDirectoryName(assemblyName)))
{
this.assembly = Load(assemblyName);
if (assembly == null) return null;
// If provided test name is actually the name of
// a type, we handle it specially
Type testType = assembly.GetType(testName);
if (testType != null)
return Build(assemblyName, testType, autoSuites);
// Assume that testName is a namespace and get all fixtures in it
IList fixtures = GetFixtures(assembly, testName);
if (fixtures.Count > 0)
return BuildTestAssembly(assemblyName, fixtures, autoSuites);
return null;
}
}
示例2: AddFromAssembly
public static IServiceCollection AddFromAssembly(this IServiceCollection serviceCollection, Assembly assembly)
{
var builder = new ServiceDescriptorsBuilder().AddSourceAssembly(assembly);
BuildAndFill(serviceCollection, builder);
return serviceCollection;
}
示例3: SearchPackageHandler
public static int SearchPackageHandler(Assembly ass)
{
int count = 0;
m_packagesHandlers.Clear();
Type[] tList = ass.GetTypes();
string interfaceStr = typeof(IPackageHandler).ToString();
foreach (Type type in tList)
{
if (type.IsClass != true) continue;
if (type.GetInterface(interfaceStr) == null) continue;
PackageHandlerAttribute[] atts = (PackageHandlerAttribute[])type.GetCustomAttributes(typeof(PackageHandlerAttribute), true);
if (atts.Length > 0)
{
count++;
RegisterPacketHandler(atts[0].Code, (IPackageHandler)Activator.CreateInstance(type));
//m_packagesHandlers[atts[0].Code] = (IPackageHandler)Activator.CreateInstance(type);
}
}
return count;
}
示例4: TryCreatingIndexesOrRedirectToErrorPage
private static void TryCreatingIndexesOrRedirectToErrorPage(Assembly[] indexAssemblies, string errorUrl)
{
try
{
foreach (var assembly in indexAssemblies)
IndexCreation.CreateIndexes(assembly, DocumentStore);
}
catch (WebException e)
{
var socketException = e.InnerException as SocketException;
if (socketException == null)
throw;
switch (socketException.SocketErrorCode)
{
case SocketError.AddressNotAvailable:
case SocketError.NetworkDown:
case SocketError.NetworkUnreachable:
case SocketError.ConnectionAborted:
case SocketError.ConnectionReset:
case SocketError.TimedOut:
case SocketError.ConnectionRefused:
case SocketError.HostDown:
case SocketError.HostUnreachable:
case SocketError.HostNotFound:
HttpContext.Current.Response.Redirect(errorUrl);
break;
default:
throw;
}
}
}
示例5: GameLoader
public GameLoader(string fileName, Assembly [] preloads, Action<string> die)
{
Game = new Game(this, die);
string extention = null;
try
{
extention = fileName.Substring(fileName.LastIndexOf('.'));
}
catch (Exception)
{
die("File " + fileName + " could Not be loaded");
return;
}
if (".kgl" == extention)
{
loaderUtility = new KGLLoaderUtility(fileName, this);
}
else
{
die("File " + fileName + " could Not be loaded");
}
foreach (Assembly loaded in preloads)
{
string name = Path.GetFileName(loaded.Location);
if (!LoadedFiles.ContainsKey(name))
{
LoadedFiles.Add(name, loaded);
ClassFactory.LoadServicesAndManagers(loaded);
}
}
}
示例6: SendByMail
/// <summary>
/// Sends an error message by opening the user's mail client.
/// </summary>
/// <param name="recipient"></param>
/// <param name="subject"></param>
/// <param name="ex"></param>
/// <param name="assembly">The assembly where the error originated. This will
/// be used to extract version information.</param>
public static void SendByMail(string recipient, string subject, Exception ex,
Assembly assembly, StringDictionary additionalInfo)
{
string attributes = GetAttributes(additionalInfo);
StringBuilder msg = new StringBuilder();
msg.AppendLine("[ Please send this as plain text to allow automatic pre-processing ]");
msg.AppendLine();
msg.AppendLine(GetMessage(ex));
msg.AppendLine();
msg.AppendLine(GetAttributes(additionalInfo));
msg.AppendLine();
msg.AppendLine("[ Please send this as plain text to allow automatic pre-processing ]");
msg.AppendLine();
string command = string.Format("mailto:{0}?subject={1}&body={2}",
recipient,
Uri.EscapeDataString(subject),
Uri.EscapeDataString(msg.ToString()));
Debug.WriteLine(command);
Process p = new Process();
p.StartInfo.FileName = command;
p.StartInfo.UseShellExecute = true;
p.Start();
}
示例7: AssemblyScannerMockRegistry
public AssemblyScannerMockRegistry(Assembly pluginAssembly)
{
_pluginAssembly = pluginAssembly;
Forward<ISagaPersister, TpInMemorySagaPersister>();
Forward<IActivityLogger, LogMock>();
}
示例8: LoadString
public static string LoadString(string baseName, string resourceName, Assembly asm)
{
if (string.IsNullOrEmpty(baseName))
{
throw new ArgumentNullException("baseName");
}
if (string.IsNullOrEmpty(resourceName))
{
throw new ArgumentNullException("resourceName");
}
string str = null;
if (asm != null)
{
str = LoadAssemblyString(asm, baseName, resourceName);
}
if (str == null)
{
str = LoadAssemblyString(Assembly.GetExecutingAssembly(), baseName, resourceName);
}
if (str == null)
{
return string.Empty;
}
return str;
}
示例9: GetLoadableTypes
public IEnumerable<Type> GetLoadableTypes(Assembly assembly, Type ofBaseType)
{
var types = GetLoadableTypes(assembly);
return types != null
? types.Where(ofBaseType.IsAssignableFrom)
: null;
}
示例10: Theme
/// <summary>
/// Initializes a new instance of the Theme class.
/// </summary>
/// <param name="themeAssembly">
/// Assembly with the embedded resource containing the theme to apply.
/// </param>
/// <param name="themeResourceName">
/// Name of the embedded resource containing the theme to apply.
/// </param>
protected Theme(Assembly themeAssembly, string themeResourceName)
: this()
{
if (themeAssembly == null)
{
throw new ArgumentNullException("themeAssembly");
}
// Get the resource stream for the theme.
using (Stream stream = themeAssembly.GetManifestResourceStream(themeResourceName))
{
if (stream == null)
{
throw new ResourceNotFoundException(
string.Format(
CultureInfo.CurrentCulture,
Properties.Resources.Theme_ResourceNotFound,
themeResourceName),
new Uri(themeResourceName, UriKind.Relative));
}
// Load the theme
ThemeResources = LoadThemeResources(stream, Resources);
}
}
示例11: compile_
public static CompilerContext compile_(CompileUnit unit, Assembly[] references)
{
BooCompiler compiler = NewCompiler();
foreach (Assembly reference in references)
compiler.Parameters.References.Add(reference);
return compiler.Run(unit);
}
示例12: FromResource
public static UIImage FromResource (Assembly assembly, string name)
{
if (name == null)
throw new ArgumentNullException ("name");
assembly = Assembly.GetCallingAssembly ();
var stream = assembly.GetManifestResourceStream (name);
if (stream == null)
return null;
IntPtr buffer = Marshal.AllocHGlobal ((int) stream.Length);
if (buffer == IntPtr.Zero)
return null;
var copyBuffer = new byte [Math.Min (1024, (int) stream.Length)];
int n;
IntPtr target = buffer;
while ((n = stream.Read (copyBuffer, 0, copyBuffer.Length)) != 0){
Marshal.Copy (copyBuffer, 0, target, n);
target = (IntPtr) ((int) target + n);
}
try {
var data = NSData.FromBytes (buffer, (uint) stream.Length);
return UIImage.LoadFromData (data);
} finally {
Marshal.FreeHGlobal (buffer);
stream.Dispose ();
}
}
示例13: GetExamples
private void GetExamples(Assembly asm)
{
var types = asm.GetExportedTypes().OrderBy(t => t.Name);
foreach (Type type in types)
{
if (type.GetInterface(typeof(IExample).Name) != null && !type.IsAbstract)
{
var example = (ExampleDescriptionAttribute)type.GetCustomAttributes(typeof(ExampleDescriptionAttribute), false)[0];
var paths = example.NodePath.Split(';');
foreach (var path in paths)
{
var pathNodes = path.Split('/');
var nodes = this.treeView1.Nodes;
for (int index = 0; index < pathNodes.Length; index++)
{
var s = pathNodes[index];
if (!nodes.ContainsKey(s))
{
var node = nodes.Add(s, s);
if (index == pathNodes.Length - 1)
{
node.Tag = type.GetConstructor(Type.EmptyTypes);
}
}
nodes = nodes[s].Nodes;
}
}
}
}
}
示例14: GetResourceManager
private static ResourceManager GetResourceManager(string resourceBaseName, Assembly assembly)
{
// check the cache
if (_resManager == null)
_resManager = new ResourceManager(resourceBaseName, assembly);
return _resManager;
}
示例15: ResolveAssembly
private static Assembly ResolveAssembly(object sender, ResolveEventArgs args)
{
var name = args.Name.Split(',')[0];
if (name.Equals("Microsoft.UpdateServices.Administration"))
{
// Microsoft changed version numbers when putting WSUS Admin API into RSAT.
// Need to try and maintain backward compatability.
if (!alreadyTriedRedirect)
{
alreadyTriedRedirect = true;
var programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
if (!programFiles.EndsWith(@"\"))
{
programFiles = programFiles + @"\";
}
redirect = Assembly.LoadFrom(string.Format("{0}Update Services\\Api\\Microsoft.UpdateServices.Administration.dll", programFiles));
}
return redirect;
}
return null;
}