本文整理汇总了C#中System.Reflection.AssemblyName类的典型用法代码示例。如果您正苦于以下问题:C# AssemblyName类的具体用法?C# AssemblyName怎么用?C# AssemblyName使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AssemblyName类属于System.Reflection命名空间,在下文中一共展示了AssemblyName类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnAssemblyResolve
private static Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
{
lock (syncRoot)
{
if (checkedAssemblies.Add(args.Name))
{
var assemblyName = new AssemblyName(args.Name);
if (!assemblyName.Name.EndsWith(".resources"))
{
var stream = typeof(AssemblyResolver).Assembly.GetManifestResourceStream(typeof(AssemblyResolver), assemblyName.Name + ".pkg");
if (stream != null)
{
using (var package = Package.Open(stream))
{
var partUri = PackUriHelper.CreatePartUri(new Uri(assemblyName.Name + ".dll", UriKind.Relative));
if (package.PartExists(partUri))
{
var part = package.GetPart(partUri);
var ms = new MemoryStream();
part.GetStream().CopyTo(ms);
return Assembly.Load(ms.ToArray());
}
}
}
}
}
return null;
}
}
示例2: AssemblyResolve
Assembly AssemblyResolve(object sender, ResolveEventArgs args)
{
// this should only be called to resolve OnlineVideos.dll -> return it regardless of the version, only the name "OnlineVideos"
AssemblyName an = new AssemblyName(args.Name);
var asm = (sender as AppDomain).GetAssemblies().FirstOrDefault(a => a.GetName().Name == an.Name);
return asm;
}
示例3: makeRecord
internal static Type makeRecord(String name,Type basetype)
{
if(assembly == null)
{
AssemblyName assemblyName = new AssemblyName();
assemblyName.Name = "RecordAssembly";
assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName,AssemblyBuilderAccess.Run);
module = assembly.DefineDynamicModule("RecordModule");
}
TypeBuilder tb = module.DefineType(name,TypeAttributes.Class|TypeAttributes.Public,basetype);
Type[] paramTypes = Type.EmptyTypes;
ConstructorBuilder cb = tb.DefineConstructor(MethodAttributes.Public,
CallingConventions.Standard,
paramTypes);
ILGenerator constructorIL = cb.GetILGenerator();
constructorIL.Emit(OpCodes.Ldarg_0);
ConstructorInfo superConstructor = basetype.GetConstructor(Type.EmptyTypes);
constructorIL.Emit(OpCodes.Call, superConstructor);
constructorIL.Emit(OpCodes.Ret);
Type t = tb.CreateType();
//Import.AddType(t); //must do in lisp
return t;
}
示例4: MethodInvoker
static MethodInvoker(){
MethodInvoker.invokerFor = new SimpleHashtable(64);
AssemblyName name = new AssemblyName();
name.Name = "JScript MethodInvoker Assembly";
MethodInvoker.assembly = Thread.GetDomain().DefineDynamicAssembly(name, AssemblyBuilderAccess.Run);
MethodInvoker.module = MethodInvoker.assembly.DefineDynamicModule("JScript MethodInvoker Module");
}
示例5: TestDefinePropertyWithGetAccessor
public void TestDefinePropertyWithGetAccessor()
{
AssemblyName an = new AssemblyName();
an.Name = "Assembly1";
AssemblyBuilder ab = AssemblyBuilder.DefineDynamicAssembly(an, AssemblyBuilderAccess.Run);
ModuleBuilder mb = TestLibrary.Utilities.GetModuleBuilder(ab, "Module1");
TypeBuilder tb = mb.DefineType("DerivedClass", TypeAttributes.Public | TypeAttributes.AutoClass | TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit, typeof(TBBaseClass1));
PropertyBuilder pb = tb.DefineProperty("Property", PropertyAttributes.None, CallingConventions.HasThis | CallingConventions.Standard, typeof(int), s_emptyTypes);
MethodAttributes methodAttr = MethodAttributes.SpecialName | MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.ReuseSlot;
CallingConventions conventions = CallingConventions.Standard | CallingConventions.HasThis;
MethodBuilder getP = tb.DefineMethod("get_Property", methodAttr, conventions, typeof(int), s_emptyTypes);
ILGenerator il = getP.GetILGenerator();
il.Emit(OpCodes.Ldc_I4, 5);
il.Emit(OpCodes.Ret);
pb.SetGetMethod(getP);
Type type = tb.CreateTypeInfo().AsType();
PropertyInfo pi = type.GetProperty("Property"); //it shouldn't throw AmbiguousMatchException
object obj = Activator.CreateInstance(type);
int retValue = (int)type.GetProperty("Property").GetGetMethod().Invoke(obj, null);
Assert.Equal(5, retValue);
}
示例6: AssemblyResolve
Assembly AssemblyResolve(object sender, ResolveEventArgs args) {
var assembly = Get(args.Name);
if (assembly != null)
return assembly;
var asmName = new AssemblyName(args.Name);
foreach (var path in assemblySearchPaths) {
foreach (var ext in assemblyExtensions) {
try {
var filename = Path.Combine(path, asmName.Name + ext);
if (!new FileInfo(filename).Exists)
continue;
AddConfigFile(filename + ".config");
return AddAssembly(Assembly.LoadFile(filename));
}
catch (IOException) {
}
catch (BadImageFormatException) {
}
catch (ArgumentException) {
}
catch (NotSupportedException) {
}
catch (UnauthorizedAccessException) {
}
catch (System.Security.SecurityException) {
}
}
}
return null;
}
示例7: PosTest1
public void PosTest1()
{
AssemblyName myAsmName =
new AssemblyName("TypeBuilderGetFieldTest");
AssemblyBuilder myAssembly = AssemblyBuilder.DefineDynamicAssembly(
myAsmName, AssemblyBuilderAccess.Run);
ModuleBuilder myModule = TestLibrary.Utilities.GetModuleBuilder(myAssembly, "Module1");
TypeBuilder myType = myModule.DefineType("Sample",
TypeAttributes.Class | TypeAttributes.Public);
string[] typeParamNames = { "T" };
GenericTypeParameterBuilder[] typeParams =
myType.DefineGenericParameters(typeParamNames);
EventBuilder eb = myType.DefineEvent("TestEvent", EventAttributes.None, typeof(int));
MethodBuilder addOnMethod = myType.DefineMethod("addOnMethod", MethodAttributes.Public);
ILGenerator ilGen = addOnMethod.GetILGenerator();
ilGen.Emit(OpCodes.Ret);
MethodBuilder removeOnMethod = myType.DefineMethod("removeOnMethod", MethodAttributes.Public);
ilGen = removeOnMethod.GetILGenerator();
ilGen.Emit(OpCodes.Ret);
eb.SetAddOnMethod(addOnMethod);
eb.SetRemoveOnMethod(removeOnMethod);
Type t = myType.CreateTypeInfo().AsType();
EventInfo ei = t.GetEvent("TestEvent", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
Assert.NotNull(ei);
}
示例8: AddAssemblyNameInfo
private void AddAssemblyNameInfo(TreeNode _parent, AssemblyName _name)
{
AddInfo(_parent, "FullName", _name.FullName);
AddInfo(_parent, "ProcessorArchitecture", _name.ProcessorArchitecture);
AddInfo(_parent, "Version", _name.Version);
AddInfo(_parent, "VersionCompatibility", _name.VersionCompatibility);
}
示例9: DataTypeBuilder
public DataTypeBuilder(string name)
{
var assemblyName = new AssemblyName {Name = name};
_moduleBuilder =
AppDomain.CurrentDomain.DefineDynamicAssembly(
assemblyName, AssemblyBuilderAccess.Run).DefineDynamicModule(name);
}
示例10: Main
public static void Main()
{
var an = new AssemblyName()
{
Version = new Version(1, 0, 0, 0),
Name = "QuoteOfTheDay"
};
var ab = AppDomain.CurrentDomain.DefineDynamicAssembly(an, AssemblyBuilderAccess.Save);
var modBuilder = ab.DefineDynamicModule("QuoteOfTheDay", "QuoteOftheDay.dll");
var tb = modBuilder.DefineType("QuoteOfTheDay.QuoteOfTheDay", TypeAttributes.Class | TypeAttributes.Public);
var fields = new FieldSet(tb);
fields.DefinePrivateField<ArrayList>("_quotes");
fields.DefinePrivateField<Random>("_random");
var ilgen = Generate_Constructor(tb, fields);
//////////////////////////////////////////////////
Generate_GetRandomQuote(ilgen, tb, fields);
tb.CreateType();
ab.Save("QuoteOfTheDay.dll");
}
示例11: LoadWhenNeeded
public void LoadWhenNeeded(string directory)
{
var cache = new Dictionary<string, Assembly>();
AppDomain.CurrentDomain.AssemblyResolve +=
(a, b) =>
{
Assembly assembly;
if (cache.TryGetValue(b.Name, out assembly))
{
return assembly;
}
string shortName = new AssemblyName(b.Name).Name;
string path = Path.Combine(directory, shortName + ".dll");
if (File.Exists(path))
{
assembly = Assembly.LoadFile(path);
}
cache[b.Name] = assembly;
if (assembly != null)
{
cache[assembly.FullName] = assembly;
}
return assembly;
};
}
示例12: GetTypeBuilder
private TypeBuilder GetTypeBuilder(string typename)
{
AssemblyName assemblyname = new AssemblyName("assemblyname");
AssemblyBuilder assemblybuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyname, AssemblyBuilderAccess.Run);
ModuleBuilder modulebuilder = TestLibrary.Utilities.GetModuleBuilder(assemblybuilder, ModuleName);
return modulebuilder.DefineType(typename);
}
示例13: TestGetField
public void TestGetField()
{
AssemblyName myAsmName =
new AssemblyName("TypeBuilderGetFieldTest");
AssemblyBuilder myAssembly = AssemblyBuilder.DefineDynamicAssembly(
myAsmName, AssemblyBuilderAccess.Run);
ModuleBuilder myModule = TestLibrary.Utilities.GetModuleBuilder(myAssembly, "Module1");
TypeBuilder myType = myModule.DefineType("Sample",
TypeAttributes.Class | TypeAttributes.Public);
string[] typeParamNames = { "T" };
GenericTypeParameterBuilder[] typeParams =
myType.DefineGenericParameters(typeParamNames);
FieldBuilder myField = myType.DefineField("Field",
typeParams[0].AsType(),
FieldAttributes.Public);
Type SampleOfInt =
myType.MakeGenericType(typeof(int));
FieldInfo fi = TypeBuilder.GetField(SampleOfInt,
myField);
Assert.Equal("Field", fi.Name);
}
示例14: ResolveAssembly
public static Assembly ResolveAssembly(object sender, ResolveEventArgs args)
{
var name = new AssemblyName(args.Name).Name.ToLowerInvariant();
var existingAssembly = ReadExistingAssembly(name);
if (existingAssembly != null)
{
return existingAssembly;
}
var prefix = string.Concat("costura.", name);
var executingAssembly = Assembly.GetExecutingAssembly();
byte[] assemblyData;
using (var assemblyStream = GetAssemblyStream(executingAssembly, prefix))
{
if (assemblyStream == null)
{
return null;
}
assemblyData = ReadStream(assemblyStream);
}
using (var pdbStream = GetDebugStream(executingAssembly, prefix))
{
if (pdbStream != null)
{
var pdbData = ReadStream(pdbStream);
return Assembly.Load(assemblyData, pdbData);
}
}
return Assembly.Load(assemblyData);
}
示例15: MainWindow
public MainWindow()
{
InitializeComponent();
AppDomain d = AppDomain.CreateDomain("Domain");
AssemblyName an = new AssemblyName("Assembly");
d.ExecuteAssembly(an, null, null);
ProcessesDataGrid.ItemsSource = Process.GetProcessesByName("devenv").Select(res => new { res.ProcessName, res.Id });
//Возвращает нити одного процесса
ThreadsDataGrid.ItemsSource = Process.GetProcessesByName("devenv")[0].Threads;
//Возращае dll необходимые для работы процесса
dllDataGrid.ItemsSource = Process.GetProcessesByName("devenv")[0].Modules;
//Запуск приложения (пример)
//Process.Start(new ProcessStartInfo() { FileName = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", Arguments = @"https://en.wikipedia.org/wiki/CPU_time" });
//Возвращает все сборки одного домена
DomainInfoGrid.ItemsSource = AppDomain.CurrentDomain.GetAssemblies();
//Creating of new domain
//****************************************************************
AppDomain NewDomain = AppDomain.CreateDomain("CalculationOfFactorial");
NewDomain.AssemblyLoad += DomainAssemblyLoad;
NewDomain.DomainUnload += DomainAssemblyUnLoad;
int Number = 5;
string[] args = new string[] { Number.ToString() };
//Path to another exe file from current exe
string PathToAssembly = NewDomain.BaseDirectory +
"../../../../CalculationOfFactorial/CalculationOfFactorial/bin/Debug/CalculationOfFactorial.exe";
//THis is the only way to dinamically add and remove libraries
//Because we couldnt do that in THIS domain only in "NewDomain"
NewDomain.Load(new AssemblyName("System.Data"));
//We run here our another application
NewDomain.ExecuteAssembly(PathToAssembly, args);
DomainInfoGrid.ItemsSource = NewDomain.GetAssemblies();
AppDomain.Unload(NewDomain);
//******************************************************************
}