本文整理汇总了C#中System.Reflection.AssemblyName类的典型用法代码示例。如果您正苦于以下问题:C# AssemblyName类的具体用法?C# AssemblyName怎么用?C# AssemblyName使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AssemblyName类属于System.Reflection命名空间,在下文中一共展示了AssemblyName类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
}
开发者ID:wimr,项目名称:Vidyano,代码行数:30,代码来源:AssemblyResolver.cs
示例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;
}
开发者ID:pilehave,项目名称:headweb-mp,代码行数:7,代码来源:PluginLoader.cs
示例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;
}
开发者ID:randylien,项目名称:Rich-Hickey-fanclub,代码行数:25,代码来源:Record.cs
示例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");
}
开发者ID:ArildF,项目名称:masters,代码行数:7,代码来源:methodinvoker.cs
示例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);
}
开发者ID:noahfalk,项目名称:corefx,代码行数:27,代码来源:TypeBuilderDefineProperty1.cs
示例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;
}
开发者ID:RafaelRMachado,项目名称:de4dot,代码行数:32,代码来源:AssemblyResolver.cs
示例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);
}
开发者ID:timbarrass,项目名称:corefx,代码行数:30,代码来源:TypeBuilderDefineEvent.cs
示例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);
}
开发者ID:rasmus-toftdahl-olesen,项目名称:sdepends,代码行数:7,代码来源:MainForm.cs
示例9: DataTypeBuilder
public DataTypeBuilder(string name)
{
var assemblyName = new AssemblyName {Name = name};
_moduleBuilder =
AppDomain.CurrentDomain.DefineDynamicAssembly(
assemblyName, AssemblyBuilderAccess.Run).DefineDynamicModule(name);
}
开发者ID:nickchal,项目名称:pash,代码行数:7,代码来源:DataTypeBuilder.cs
示例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");
}
开发者ID:treytomes,项目名称:ILExperiments,代码行数:25,代码来源:Program.cs
示例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;
};
}
开发者ID:tkggand,项目名称:katana,代码行数:26,代码来源:StartParametersTests.cs
示例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);
}
开发者ID:timbarrass,项目名称:corefx,代码行数:7,代码来源:TypeBuilderGenericParameterPosition.cs
示例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);
}
开发者ID:noahfalk,项目名称:corefx,代码行数:26,代码来源:TypeBuilderGetField.cs
示例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);
}
开发者ID:MartinDemberger,项目名称:Costura,代码行数:33,代码来源:AssemblyLoader.cs
示例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);
//******************************************************************
}
开发者ID:Saroko-dnd,项目名称:My_DZ,代码行数:34,代码来源:MainWindow.xaml.cs
示例16: Processor
/// <summary>
/// Create a Processor, indicating whether it is to be schema-aware.
/// </summary>
/// <param name="schemaAware">Set to true if the Processor is to be schema-aware.
/// This requires the Saxon-SA product to be installed, with a valid license key.</param>
/// <param name="loadLocally">Set to true if Saxon-SA is to be loaded from the application
/// directory rather than from the Global Assembly Cache. This option should normally
/// be set only when troubleshooting, for example when using a locally-patched version
/// of the software.</param>
public Processor(bool schemaAware, bool loadLocally) {
if (schemaAware) {
if (loadLocally) {
Assembly asm = Assembly.Load("saxon8sa");
} else {
try {
int[] v = JVersion.getStructuredVersionNumber();
AssemblyName asn = new AssemblyName();
asn.Name = "saxon8sa";
asn.Version = new Version(v[0], v[1], v[2], v[3]);
//asn.Version = new Version(JVersion.getMajorVersion(), JVersion.getMinorVersion());
asn.SetPublicKeyToken(new byte[] { 0xe1, 0xfd, 0xd0, 0x02, 0xd5, 0x08, 0x3f, 0xe6 });
asn.CultureInfo = new CultureInfo("");
Assembly asm = Assembly.Load(asn);
// try to load the saxon8sa.dll assembly
//Assembly asm = Assembly.Load("saxon8sa, Ver=" + JVersion.getProductVersion() + ".0.1, " +
// @"SN=e1fdd002d5083fe6, Loc=neutral");
} catch (Exception e) {
Console.WriteLine("Cannot load Saxon-SA software (assembly saxon8sa.dll version " +
JVersion.getProductVersion() + ".0.1)");
throw e;
}
}
config = JConfiguration.makeSchemaAwareConfiguration(null);
schemaManager = new SchemaManager(config);
} else {
config = new JConfiguration();
}
config.setURIResolver(new DotNetURIResolver(new XmlUrlResolver()));
config.setCollectionURIResolver(new DotNetCollectionURIResolver());
}
开发者ID:pombredanne,项目名称:https-dev.saxonica.com-repos-archive-opensource-,代码行数:41,代码来源:Configuration.cs
示例17: PropertyAccessor
static PropertyAccessor()
{
AssemblyName asmName = new AssemblyName();
asmName.Name = "$Assembly.Hprose.IO.PropertyAccessor";
asmBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Run);
modBuilder = asmBuilder.DefineDynamicModule("$Module.PropertyAccessor");
}
开发者ID:JesonRen,项目名称:hprose,代码行数:7,代码来源:PropertyAccessor.cs
示例18: RedirectAssembly
/// <summary>
/// Adds an AssemblyResolve handler to redirect all failed assembly load attempts
/// </summary>
/// <remarks>
/// http://blog.slaks.net/2013-12-25/redirecting-assembly-loads-at-runtime/
/// </remarks>
/// <param name="shortName">The short name.</param>
/// <param name="targetVersion">The target version.</param>
/// <param name="publicKeyToken">The public key token.</param>
public static void RedirectAssembly(string shortName, Version targetVersion, string publicKeyToken)
{
ResolveEventHandler handler = null;
handler = (sender, args) =>
{
// Use latest strong name & version when trying to load SDK assemblies
var requestedAssembly = new AssemblyName(args.Name);
if (requestedAssembly.Name != shortName)
{
return null;
}
requestedAssembly.Version = targetVersion;
requestedAssembly.SetPublicKeyToken(new AssemblyName("x, PublicKeyToken=" + publicKeyToken).GetPublicKeyToken());
requestedAssembly.CultureInfo = CultureInfo.InvariantCulture;
AppDomain.CurrentDomain.AssemblyResolve -= handler;
var assembly = Assembly.Load(requestedAssembly);
return assembly;
};
AppDomain.CurrentDomain.AssemblyResolve += handler;
}
开发者ID:jamesholcomb,项目名称:Postman.WebApi.MsBuildTask,代码行数:35,代码来源:GenerateTask.cs
示例19: OnResolveAssembly
private static Assembly OnResolveAssembly(object sender, ResolveEventArgs args)
{
Assembly cachedAsm;
if (loadedAsmsCache.TryGetValue(args.Name, out cachedAsm))
return cachedAsm;
Assembly executingAssembly = Assembly.GetExecutingAssembly();
AssemblyName assemblyName = new AssemblyName(args.Name);
string path = assemblyName.Name + ".dll";
if (assemblyName.CultureInfo != null && assemblyName.CultureInfo.Equals(CultureInfo.InvariantCulture) == false)
{
path = String.Format(@"{0}\{1}", assemblyName.CultureInfo, path);
}
using (Stream stream = executingAssembly.GetManifestResourceStream(path))
{
if (stream == null)
return null;
byte[] assemblyRawBytes = new byte[stream.Length];
stream.Read(assemblyRawBytes, 0, assemblyRawBytes.Length);
var loadedAsm = Assembly.Load(assemblyRawBytes);
loadedAsmsCache.Add(args.Name, loadedAsm);
return loadedAsm;
}
}
开发者ID:kazyx,项目名称:SvgToXaml,代码行数:27,代码来源:Program.cs
示例20: TestOnOverridenInterfaceMethod
public void TestOnOverridenInterfaceMethod()
{
string name = "Assembly1";
AssemblyName asmname = new AssemblyName();
asmname.Name = name;
AssemblyBuilder asmbuild = AssemblyBuilder.DefineDynamicAssembly(asmname, AssemblyBuilderAccess.Run);
ModuleBuilder modbuild = TestLibrary.Utilities.GetModuleBuilder(asmbuild, "Module1");
TypeBuilder tpbuild = modbuild.DefineType("C1", TypeAttributes.Public);
MethodBuilder methbuild = tpbuild.DefineMethod("M", MethodAttributes.Public | MethodAttributes.Virtual, typeof(int), null);
ILGenerator ilgen = methbuild.GetILGenerator();
ilgen.Emit(OpCodes.Ldc_I4, 2);
ilgen.Emit(OpCodes.Ret);
// C1 implements interface TBI1
tpbuild.AddInterfaceImplementation(typeof(TBI1));
MethodInfo md2 = typeof(TBI1).GetMethod("M");
tpbuild.DefineMethodOverride(methbuild, md2);
Type tp = tpbuild.CreateTypeInfo().AsType();
MethodInfo mdInvoke = typeof(TBI1).GetMethod("M");
int ret = (int)mdInvoke.Invoke(Activator.CreateInstance(tp), null);
Assert.Equal(2, ret);
}
开发者ID:noahfalk,项目名称:corefx,代码行数:28,代码来源:TypeBuilderDefineMethodOverride.cs
注:本文中的System.Reflection.AssemblyName类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论