本文整理汇总了C#中Mono.Cecil.AssemblyNameReference类的典型用法代码示例。如果您正苦于以下问题:C# AssemblyNameReference类的具体用法?C# AssemblyNameReference怎么用?C# AssemblyNameReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AssemblyNameReference类属于Mono.Cecil命名空间,在下文中一共展示了AssemblyNameReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryResolve
public static AssemblyDefinition TryResolve(this ModuleDefinition moduleDef, AssemblyNameReference assemblyNameRef)
{
try {
return moduleDef.AssemblyResolver.Resolve(assemblyNameRef);
} catch (AssemblyResolutionException) { }
return null;
}
示例2: GetRenameMap
private Dictionary<IMemberDefinition, string> GetRenameMap(AssemblyNameReference assembly)
{
foreach (var map in Context.DefinitionsRenameMap)
if (map.Key.FullName == assembly.FullName)
return map.Value;
return null;
}
示例3: VisitAssemblyReference
public override void VisitAssemblyReference(AssemblyNameReference assemblyRef, AssemblyDefinition current)
{
if (string.Compare(assemblyRef.Name, this.myAssembly, true) == 0)
{
this.Aggregator.AddMatch(current);
}
}
示例4: ResolveFailure
AssemblyDefinition ResolveFailure(object sender, AssemblyNameReference reference)
{
string fpath = string.Empty;
if (App.LocalDependencies.Keys.Contains(reference.FullName))
{
fpath = App.LocalDependencies[reference.FullName];
}
else
{
Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();
ofd.Filter = "Assembly|" + reference.Name + ".dll";
if ((bool)ofd.ShowDialog()) fpath = ofd.FileName;
}
if (File.Exists(fpath))
{
AssemblyDefinition ad;
try
{
ad = AssemblyDefinition.ReadAssembly(fpath);
ResolvedReferences.Add(fpath);
App.LocalDependencies.Add(reference.FullName, fpath);
return ad;
}
catch (Exception)
{
MessageBox.Show("Unable to read assembly!");
return ResolveFailure(sender, reference);
}
}
return null;
}
示例5: Parse
public static FrameworkProfileInfo Parse(XDocument frameworkList)
{
var profileInfo = new FrameworkProfileInfo();
var nameAttr = frameworkList.Root.Attribute("Name");
profileInfo.Description = (nameAttr != null ? nameAttr.Value : null);
profileInfo.Assemblies = new HashSet<AssemblyNameReference>(CecilEqualityComparer.Default);
//frameworkList.Descendants("File").Select(file => AssemblyNameReference.Parse(string.Format("{0}, Version={1}, ",file.Attribute("AssemblyName").Value,) ))
foreach (var fileElement in frameworkList.Descendants("File")) {
var assemblyName = fileElement.Attribute("AssemblyName").Value;
var versionString = fileElement.Attribute("Version").Value;
Version version = null;
if (!Version.TryParse(versionString, out version)) {
Trace.WriteLine(string.Format("Warning: Couldn't parse version of the {0} assembly description.", fileElement.ToString()));
}
string culture = null;
var attrib = fileElement.Attribute ("Culture");
if (attrib != null && attrib.Value != "neutral") {
culture = attrib.Value;
}
var publicKeyTokenString = fileElement.Attribute("PublicKeyToken").Value;
var publicKeyToken = new byte[publicKeyTokenString.Length / 2];
for (int j = 0; j < publicKeyToken.Length; j++) {
publicKeyToken[j] = Byte.Parse(publicKeyTokenString.Substring(j * 2, 2), NumberStyles.HexNumber);
}
var assemblyNameRef = new AssemblyNameReference(assemblyName, version) { Culture = culture, PublicKeyToken = publicKeyToken };
profileInfo.Assemblies.Add(assemblyNameRef);
}
return profileInfo;
}
示例6: SearchDirForMatchingName
IEnumerable<string> SearchDirForMatchingName(AssemblyNameReference assemblyNameReference)
{
var fileName = assemblyNameReference.Name + ".dll";
return ReferenceDictionary.Values
.Select(x => Path.Combine(Path.GetDirectoryName(x), fileName))
.Where(File.Exists);
}
示例7: Delete
/// <summary>
/// Remove an assembly name reference
/// </summary>
/// <param name="anref">Assembly name reference</param>
public static void Delete(AssemblyNameReference anref)
{
IPlugin plugin = PluginFactory.GetInstance();
ModuleDefinition moddef = null;
foreach (IAssemblyWrapper wrapper in plugin.GetAssemblies(true))
{
if (wrapper.IsValid)
{
if (plugin.IsAssemblyContextLoaded(wrapper.Location))
{
IAssemblyContext context = plugin.GetAssemblyContext(wrapper.Location);
foreach (ModuleDefinition imoddef in context.AssemblyDefinition.Modules)
{
foreach (AssemblyNameReference ianref in imoddef.AssemblyReferences)
{
if (anref == ianref)
{
moddef = imoddef;
break;
}
}
}
}
}
}
if (moddef != null)
{
moddef.AssemblyReferences.Remove(anref);
}
}
示例8: Resolve
public override AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters)
{
if (name == null)
throw new ArgumentNullException("name");
return Cache.GetOrCreate(name.FullName, () => base.Resolve(name, parameters));
}
示例9: GetAssembliesByReference
public AssemblyDefinition[] GetAssembliesByReference(AssemblyNameReference referencedAssemblyName)
{
ArgumentUtility.CheckNotNull ("referencedAssemblyName", referencedAssemblyName);
var trackedAssembly = GetTrackedAssembliesByReference (referencedAssemblyName);
return trackedAssembly != null ? trackedAssembly.Select(asm => asm.AssemblyDefinition).ToArray() : null;
}
示例10:
public Tuple<TypeDefinition, AssemblyDefinition> this[TypeReference typ, AssemblyNameReference assembly]
{
get
{
return typ == null ? null : this[assembly.BuildAssemblyQualifiedName (typ)];
}
}
示例11: ShouldRemoveStrongName
private bool ShouldRemoveStrongName(AssemblyNameReference reference)
{
// Strong name is not present already
if (reference.PublicKeyToken == null || reference.PublicKeyToken.Length == 0)
{
return false;
}
// Strong name must be kept
if (Context.StrongNameReferences.Any(r => r == reference.Name))
{
return false;
}
AssemblyDefinition assembly;
try
{
// Can't find target assembly
assembly = Context.AssemblyResolver.Resolve(reference);
}
catch (AssemblyResolutionException)
{
return false;
}
// Don't remove strong name to framework references
var assemblyDir = NormalizePath(Path.GetDirectoryName(assembly.MainModule.FullyQualifiedName));
if (Context.FrameworkPaths.Any(path => NormalizePath(path) == assemblyDir))
{
return false;
}
return true;
}
开发者ID:Unity-Technologies,项目名称:ReferenceRewriter,代码行数:35,代码来源:RemoveStrongNamesFromAssemblyReferences.cs
示例12: WindowsRuntimeProjectionsComponent
public WindowsRuntimeProjectionsComponent()
{
AssemblyNameReference reference = new AssemblyNameReference("Windows", new Version(0xff, 0xff, 0xff, 0xff)) {
IsWindowsRuntime = true
};
this._windowsAssemblyReference = reference;
}
示例13: Resolve
/// <summary>
/// Attempts to resolve the assembly by searching for it in the specified directories.
/// </summary>
/// <param name="name">The reference name of the assembly.</param>
/// <returns>The definition of the assembly.</returns>
/// <exception cref="AssemblyResolutionException">The assembly wasn't found in any of the listed directories.</exception>
public override AssemblyDefinition Resolve(AssemblyNameReference name)
{
try
{
return base.Resolve(name);
}
catch (AssemblyResolutionException)
{
Trace.WriteLine("Second-chance attempt to resolve assembly " + name.FullName + "...");
var definitions = from dirPath in this.paths
let filePath = Path.Combine(dirPath, name.Name + ".dll")
where File.Exists(filePath)
let definition = AssemblyDefinition.ReadAssembly(filePath)
where definition.FullName == name.FullName
select definition;
var match = definitions.SingleOrDefault();
if (match != null)
{
Trace.WriteLine("Assembly " + name.FullName + " was resolved.");
return match;
}
Trace.WriteLine("Failed to resolve assembly " + name.FullName + ".");
throw;
}
}
示例14: RewriteAssemblyReference
private void RewriteAssemblyReference(AssemblyNameReference reference)
{
try
{
if (ShouldRewriteToWinmdReference(reference))
{
Context.RewriteTarget = true;
reference.Version = new Version(255, 255, 255, 255);
reference.IsWindowsRuntime = true;
}
var assembly = Context.AssemblyResolver.Resolve(reference);
if ((reference.IsWindowsRuntime != assembly.Name.IsWindowsRuntime) || (IsFrameworkAssembly(assembly) && ShouldRewriteFrameworkReference(reference, assembly)))
{
Context.RewriteTarget = true;
reference.Version = assembly.Name.Version;
reference.PublicKeyToken = Copy(assembly.Name.PublicKeyToken);
reference.IsWindowsRuntime = assembly.Name.IsWindowsRuntime;
}
}
catch (AssemblyResolutionException)
{
}
}
示例15: GetAssembly
public void GetAssembly(string repository, AssemblyDefinition callingAssembly, AssemblyNameReference reference, Action<Stream> callback)
{
if (string.IsNullOrWhiteSpace(repository)) throw new ArgumentNullException("repository");
if (callingAssembly == null) throw new ArgumentNullException("callingAssembly");
if (reference == null) throw new ArgumentNullException("reference");
if (callback == null) throw new ArgumentNullException("callback");
repository = repository.TrimEnd('/');
var uriString = GetRepositoryAddress(callingAssembly, reference);
var uri = new Uri(repository + uriString, UriKind.RelativeOrAbsolute);
var request = (HttpWebRequest)WebRequestCreator.ClientHttp.Create(uri);
request.Method = "GET";
request.BeginGetResponse(r =>
{
try
{
var rs = (HttpWebResponse)request.EndGetResponse(r);
var stream = rs.GetResponseStream();
Dispatcher.BeginInvoke(() => callback(stream));
}
catch (WebException ex)
{
Debug.WriteLine(ex.Message);
Dispatcher.BeginInvoke(() => callback(null));
}
}, request);
}