本文整理汇总了C#中AssemblyResolver.ProbeForAssembly方法的典型用法代码示例。如果您正苦于以下问题:C# AssemblyResolver.ProbeForAssembly方法的具体用法?C# AssemblyResolver.ProbeForAssembly怎么用?C# AssemblyResolver.ProbeForAssembly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AssemblyResolver
的用法示例。
在下文中一共展示了AssemblyResolver.ProbeForAssembly方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MikesArchitecture
private static void MikesArchitecture(AssemblyResolver resolver, AssemblyNode assemblyNode,
ContractNodes contractNodes, ContractNodes backupContracts)
{
#if false
var originalsourceDir = Path.GetDirectoryName(assemblyNode.Location);
int oldPeVerifyCode = options.verify ? PEVerify(assemblyNode.Location, originalsourceDir) : -1;
#endif
// Check to see if the assembly has already been rewritten
if (!options.passthrough)
{
if (ContractNodes.IsAlreadyRewritten(assemblyNode))
{
if (!options.allowRewritten)
{
Console.WriteLine("Assembly '" + assemblyNode.Name +
"' has already been rewritten. I, your poor humble servant, cannot rewrite it. Instead I must give up without rewriting it. Help!");
}
return;
}
}
// Extract the contracts from the code (includes checking the contracts)
string contractFileName = Path.GetFileNameWithoutExtension(assemblyNode.Location) + ".Contracts";
if (options.contracts == null || options.contracts.Count <= 0) contractFileName = null;
if (options.contracts != null &&
!options.contracts.Exists(name => name.Equals(assemblyNode.Name + ".Contracts.dll", StringComparison.OrdinalIgnoreCase)))
{
contractFileName = null;
}
AssemblyNode contractAssembly = null;
if (contractFileName != null)
{
contractAssembly = resolver.ProbeForAssembly(contractFileName, assemblyNode.Directory,
resolver.DllExt);
}
if (!options.passthrough)
{
ContractNodes usedContractNodes;
Extractor.ExtractContracts(assemblyNode, contractAssembly, contractNodes, backupContracts, contractNodes,
out usedContractNodes, options.EmitError, false);
// important to extract source before we perform any more traversals due to contract instantiation. Otherwise,
// we might get copies of contracts due to instantiation that have no source text yet.
// Extract the text from the sources (optional)
if (usedContractNodes != null && options.extractSourceText)
{
GenerateDocumentationFromPDB gd = new GenerateDocumentationFromPDB(contractNodes);
gd.VisitForDoc(assemblyNode);
}
// After all contracts have been extracted in assembly, do some post-extractor checks
// we run these even if no contracts were extracted due to checks having to do with overrides
var contractNodesForChecks = usedContractNodes != null ? usedContractNodes : contractNodes;
if (contractNodesForChecks != null)
{
PostExtractorChecker pec = new PostExtractorChecker(contractNodesForChecks, options.EmitError, false,
options.fSharp, options.IsLegacyModeAssembly, options.addInterfaceWrappersWhenNeeded,
options.level);
if (contractAssembly != null)
{
pec.VisitForPostCheck(contractAssembly);
}
else
{
pec.VisitForPostCheck(assemblyNode);
}
}
// don't really need to test, since if they are the same, the assignment doesn't change that
// but this is to emphasize that the nodes used in the AST by the extractor are different
// than what we thought we were using.
if (options.GetErrorCount() > 0)
{
// we are done.
// But first, report any metadata errors so they are not masked by the errors
CheckForMetaDataErrors(assemblyNode);
return;
}
}
// If we have metadata errors, cop out
{
#if false
for (int i = 0; i < assemblyNode.ModuleReferences.Count; i++)
{
//.........这里部分代码省略.........
示例2: InternalMain
//.........这里部分代码省略.........
if (assemblyNode.MetadataImportErrors != null && assemblyNode.MetadataImportErrors.Count > 0)
{
string msg = "\tThere were errors reported in " + assemblyNode.Name + "'s metadata.\n";
foreach (Exception e in assemblyNode.MetadataImportErrors)
{
msg += "\t" + e.Message;
}
Console.WriteLine(msg);
throw new InvalidOperationException("Foxtrot: " + msg);
}
else
{
//Console.WriteLine("\tThere were no errors reported in {0}'s metadata.", assemblyNode.Name);
}
// Load the rewriter assembly if any
AssemblyNode rewriterMethodAssembly = null;
if (options.rewriterMethods != null && 0 < options.rewriterMethods.Length)
{
string[] pieces = options.rewriterMethods.Split(',');
if (!(pieces.Length == 2 || pieces.Length == 3))
{
Console.WriteLine("Error: Need to provide two or three comma separated arguments to /rewriterMethods");
options.PrintOptions("", Console.Out);
return errorReturnValue;
}
string assemName = pieces[0];
rewriterMethodAssembly = resolver.ProbeForAssembly(assemName, null, resolver.AllExt);
if (rewriterMethodAssembly == null)
{
Console.WriteLine("Error: Could not open assembly '" + assemName + "'");
return errorReturnValue;
}
string nameSpaceName = null;
string bareClassName = null;
if (pieces.Length == 2)
{
// interpret A.B.C as namespace A.B and class C
// no nested classes allowed.
string namespaceAndClassName = pieces[1];
int lastDot = namespaceAndClassName.LastIndexOf('.');
nameSpaceName = lastDot == -1 ? "" : namespaceAndClassName.Substring(0, lastDot);
bareClassName = namespaceAndClassName.Substring(lastDot + 1);
userSpecifiedContractType = rewriterMethodAssembly.GetType(Identifier.For(nameSpaceName),
Identifier.For(bareClassName));
}
else
{
// pieces.Length == 3
// namespace can be A.B and class can be C.D
nameSpaceName = pieces[1];
bareClassName = pieces[2];
userSpecifiedContractType = GetPossiblyNestedType(rewriterMethodAssembly, nameSpaceName, bareClassName);
}
示例3: PostLoadExtractionHook
private static void PostLoadExtractionHook(AssemblyResolver resolver, AssemblyNode assemblyNode)
{
Contract.Requires(assemblyNode != null);
LogFileLoads(assemblyNode);
// If ends in ".Contracts", no need to do anything. Just return
if (assemblyNode.Name.EndsWith(".Contracts")) return;
// Possibly load OOB contract assembly for assemblyNode. If found, run extractor on the pair.
if (options.automaticallyLookForOOBs)
{
string contractFileName = Path.GetFileNameWithoutExtension(assemblyNode.Location) + ".Contracts";
// if (contractFileName != null)
{
AssemblyNode contractAssembly = resolver.ProbeForAssembly(contractFileName, assemblyNode.Directory, resolver.DllExt);
if (contractAssembly != null)
{
ContractNodes usedContractNodes;
Extractor.ExtractContracts(assemblyNode, contractAssembly, DefaultContractLibrary,
BackupContractLibrary, DefaultContractLibrary, out usedContractNodes, null, false);
}
}
}
else
{
// use only if specified
if (options.contracts != null)
{
foreach (var contractAssemblyName in options.contracts)
{
string contractFileName = Path.GetFileNameWithoutExtension(contractAssemblyName);
var assemblyName = assemblyNode.Name + ".Contracts";
if (contractFileName == assemblyName)
{
AssemblyNode contractAssembly = resolver.ProbeForAssembly(assemblyName, assemblyNode.Directory, resolver.DllExt);
if (contractAssembly != null)
{
ContractNodes usedContractNodes;
Extractor.ExtractContracts(assemblyNode, contractAssembly, DefaultContractLibrary,
BackupContractLibrary, DefaultContractLibrary, out usedContractNodes, null, false);
}
break; // only do the one
}
}
}
}
}