提交 0f4eeb5d 编写于 作者: C ChuckStoner

Added .winmd helper methods (changeset 1332312)

上级 def35ce5
......@@ -371,20 +371,8 @@ private bool CreateAndSetSourceAssemblyFullBind(CSharpCompilation compilation)
if ((object)bindingResult[i].AssemblySymbol == null)
{
// symbols hasn't been found in the cache, create a new one
var compilationData = allAssemblies[i] as AssemblyDataForCompilation;
if (compilationData != null)
{
bindingResult[i].AssemblySymbol = new Symbols.Retargeting.RetargetingAssemblySymbol(
compilationData.Compilation.SourceAssembly, compilationData.IsLinked);
}
else
{
var fileData = (AssemblyDataForFile)allAssemblies[i];
bindingResult[i].AssemblySymbol = new PEAssemblySymbol(fileData.Assembly, fileData.DocumentationProvider, fileData.IsLinked, fileData.EffectiveImportOptions);
}
var compilationData = (AssemblyDataForMetadataOrCompilation)allAssemblies[i];
bindingResult[i].AssemblySymbol = compilationData.CreateAssemblySymbol();
newSymbols.Add(i);
}
......@@ -822,6 +810,8 @@ protected AssemblyDataForMetadataOrCompilation(bool embedInteropTypes)
this.EmbedInteropTypes = embedInteropTypes;
}
internal abstract AssemblySymbol CreateAssemblySymbol();
public override AssemblyIdentity Identity
{
get
......@@ -943,6 +933,11 @@ public DocumentationProvider DocumentationProvider
private bool internalsVisibleComputed = false;
private bool internalsPotentiallyVisibleToCompilation = false;
internal override AssemblySymbol CreateAssemblySymbol()
{
return new PEAssemblySymbol(this.assembly, this.documentationProvider, this.IsLinked, this.EffectiveImportOptions);
}
internal bool InternalsMayBeVisibleToCompilation
{
get
......@@ -1089,6 +1084,11 @@ public AssemblyDataForCompilation(CSharpCompilation compilation, bool embedInter
referencedAssemblies = refs.ToImmutableAndFree();
}
internal override AssemblySymbol CreateAssemblySymbol()
{
return new Symbols.Retargeting.RetargetingAssemblySymbol(this.compilation.SourceAssembly, this.IsLinked);
}
protected override void AddAvailableSymbols(List<AssemblySymbol> assemblies)
{
assemblies.Add(compilation.Assembly);
......
......@@ -862,5 +862,22 @@ internal static bool SplitNameEqualsFullyQualifiedName(string namespaceName, str
fullyQualified.StartsWith(namespaceName, StringComparison.Ordinal) &&
fullyQualified.EndsWith(typeName, StringComparison.Ordinal);
}
/// <summary>
/// Returns true if the metadata name is a compile-time .winmd assembly name.
/// </summary>
internal static bool IsCompileTimeWinMd(string metadataName)
{
return string.Equals(metadataName, "windows.winmd", StringComparison.OrdinalIgnoreCase);
}
/// <summary>
/// Returns true if the metadata name is a runtime .winmd assembly name.
/// </summary>
internal static bool IsRuntimeWinMd(string metadataName)
{
return !IsCompileTimeWinMd(metadataName) &&
metadataName.EndsWith(".winmd", StringComparison.OrdinalIgnoreCase);
}
}
}
......@@ -219,7 +219,8 @@ internal bool IsValidAssembly()
for (int i = 1; i < Modules.Length; i++)
{
if (!Modules[i].Module.IsLinkedModule)
var module = Modules[i].Module;
if (!module.IsLinkedModule && !MetadataHelpers.IsRuntimeWinMd(module.Name))
{
return false;
}
......
......@@ -85,12 +85,9 @@ internal ImmutableArray<ModuleMetadata> GetAllModuleMetadata()
public void Emit(string expectedOutput, IEnumerable<ResourceDescription> manifestResources, bool peVerify, SignatureDescription[] expectedSignatures)
{
bool doExecute = expectedOutput != null;
using (var testEnvironment = new HostedRuntimeEnvironment(dependencies))
{
string mainModuleName = Emit(testEnvironment, manifestResources);
allModuleData = testEnvironment.GetAllModuleData();
if (peVerify)
......@@ -103,7 +100,7 @@ public void Emit(string expectedOutput, IEnumerable<ResourceDescription> manifes
MetadataSignatureUnitTestHelper.VerifyMemberSignatures(testEnvironment, expectedSignatures);
}
if (doExecute)
if (expectedOutput != null)
{
testEnvironment.Execute(mainModuleName, expectedOutput);
}
......
......@@ -8,24 +8,16 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Text;
using System.Threading;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeGen;
using Microsoft.CodeAnalysis.Emit;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Test.Utilities
{
public enum OutputMatchKind
{
MatchAll,
DoesNotMatch
}
public class HostedRuntimeEnvironment : IDisposable
{
private static readonly Dictionary<string, Guid> allModuleNames = new Dictionary<string, Guid>();
......@@ -269,35 +261,16 @@ public int Execute(string moduleName, int expectedOutputLength, out string proce
}
}
public int Execute(string moduleName, string expectedOutput, OutputMatchKind outputMatchKind = OutputMatchKind.MatchAll)
public int Execute(string moduleName, string expectedOutput)
{
string actualOutput;
int exitCode = Execute(moduleName, expectedOutput.Length, out actualOutput);
if (expectedOutput != null)
{
switch (outputMatchKind)
{
case OutputMatchKind.MatchAll:
if (expectedOutput.Trim() != actualOutput.Trim())
{
string dumpDir;
assemblyManager.DumpAssemblyData(out dumpDir);
throw new ExecutionException(expectedOutput, actualOutput, dumpDir);
}
break;
case OutputMatchKind.DoesNotMatch:
if (actualOutput.Contains(expectedOutput))
{
string dumpDir;
assemblyManager.DumpAssemblyData(out dumpDir);
throw new ExecutionException(null, actualOutput, dumpDir);
}
break;
default:
throw new NotSupportedException("Unsupported OutputMatchKind: " + outputMatchKind.ToString());
}
if (expectedOutput.Trim() != actualOutput.Trim())
{
string dumpDir;
assemblyManager.DumpAssemblyData(out dumpDir);
throw new ExecutionException(expectedOutput, actualOutput, dumpDir);
}
return exitCode;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册