public void ForwardedTypesAreEmittedInADeterministicOrder() { var forwardedToCode = @" namespace Namespace2 { public class GenericType1<T> {} public class GenericType3<T> {} public class GenericType2<T> {} } namespace Namespace1 { public class Type3 {} public class Type2 {} public class Type1 {} } namespace Namespace4 { namespace Embedded { public class Type2 {} public class Type1 {} } } namespace Namespace3 { public class GenericType {} public class GenericType<T> {} public class GenericType<T, U> {} } "; var forwardedToCompilation1 = CreateCompilation(forwardedToCode, assemblyName: "ForwardedTo"); var forwardedToReference1 = new CSharpCompilationReference(forwardedToCompilation1); var forwardingCode = @" using System.Runtime.CompilerServices; [assembly: TypeForwardedTo(typeof(Namespace2.GenericType1<int>))] [assembly: TypeForwardedTo(typeof(Namespace2.GenericType3<int>))] [assembly: TypeForwardedTo(typeof(Namespace2.GenericType2<int>))] [assembly: TypeForwardedTo(typeof(Namespace1.Type3))] [assembly: TypeForwardedTo(typeof(Namespace1.Type2))] [assembly: TypeForwardedTo(typeof(Namespace1.Type1))] [assembly: TypeForwardedTo(typeof(Namespace4.Embedded.Type2))] [assembly: TypeForwardedTo(typeof(Namespace4.Embedded.Type1))] [assembly: TypeForwardedTo(typeof(Namespace3.GenericType))] [assembly: TypeForwardedTo(typeof(Namespace3.GenericType<int>))] [assembly: TypeForwardedTo(typeof(Namespace3.GenericType<int, int>))] "; var forwardingCompilation = CreateCompilation(forwardingCode, new MetadataReference[] { forwardedToReference1 }); var forwardingReference = new CSharpCompilationReference(forwardingCompilation); var sortedFullNames = new string[] { "Namespace1.Type1", "Namespace1.Type2", "Namespace1.Type3", "Namespace2.GenericType1`1", "Namespace2.GenericType2`1", "Namespace2.GenericType3`1", "Namespace3.GenericType", "Namespace3.GenericType`1", "Namespace3.GenericType`2", "Namespace4.Embedded.Type1", "Namespace4.Embedded.Type2" }; Action <ModuleSymbol> metadataValidator = module => { var assembly = module.ContainingAssembly; Assert.Equal(sortedFullNames, getNamesOfForwardedTypes(assembly)); }; CompileAndVerify(forwardingCompilation, symbolValidator: metadataValidator, sourceSymbolValidator: metadataValidator, verify: Verification.Skipped); using (var stream = forwardingCompilation.EmitToStream()) { using (var block = ModuleMetadata.CreateFromStream(stream)) { var metadataFullNames = MetadataValidation.GetExportedTypesFullNames(block.MetadataReader); Assert.Equal(sortedFullNames, metadataFullNames); } } var forwardedToCompilation2 = CreateCompilation(forwardedToCode, assemblyName: "ForwardedTo"); var forwardedToReference2 = new CSharpCompilationReference(forwardedToCompilation2); var withRetargeting = CreateCompilation("", new MetadataReference[] { forwardedToReference2, forwardingReference }); var retargeting = (RetargetingAssemblySymbol)withRetargeting.GetReferencedAssemblySymbol(forwardingReference); Assert.Equal(sortedFullNames, getNamesOfForwardedTypes(retargeting)); foreach (var type in getForwardedTypes(retargeting)) { Assert.Same(forwardedToCompilation2.Assembly.GetPublicSymbol(), type.ContainingAssembly); }
public void ForwardedTypesAreEmittedInADeterministicOrder() { var forwardedToCode = @" namespace Namespace2 { public class GenericType1<T> {} public class GenericType3<T> {} public class GenericType2<T> {} } namespace Namespace1 { public class Type3 {} public class Type2 {} public class Type1 {} } namespace Namespace4 { namespace Embedded { public class Type2 {} public class Type1 {} } } namespace Namespace3 { public class GenericType {} public class GenericType<T> {} public class GenericType<T, U> {} } "; var forwardedToCompilation = CreateEmptyCompilation(forwardedToCode); var forwardedToReference = new CSharpCompilationReference(forwardedToCompilation); var forwardingCode = @" using System.Runtime.CompilerServices; [assembly: TypeForwardedTo(typeof(Namespace2.GenericType1<int>))] [assembly: TypeForwardedTo(typeof(Namespace2.GenericType3<int>))] [assembly: TypeForwardedTo(typeof(Namespace2.GenericType2<int>))] [assembly: TypeForwardedTo(typeof(Namespace1.Type3))] [assembly: TypeForwardedTo(typeof(Namespace1.Type2))] [assembly: TypeForwardedTo(typeof(Namespace1.Type1))] [assembly: TypeForwardedTo(typeof(Namespace4.Embedded.Type2))] [assembly: TypeForwardedTo(typeof(Namespace4.Embedded.Type1))] [assembly: TypeForwardedTo(typeof(Namespace3.GenericType))] [assembly: TypeForwardedTo(typeof(Namespace3.GenericType<int>))] [assembly: TypeForwardedTo(typeof(Namespace3.GenericType<int, int>))] "; var forwardingCompilation = CreateCompilation(forwardingCode, new MetadataReference[] { forwardedToReference }); var sortedFullNames = new string[] { "Namespace1.Type1", "Namespace1.Type2", "Namespace1.Type3", "Namespace2.GenericType1`1", "Namespace2.GenericType2`1", "Namespace2.GenericType3`1", "Namespace3.GenericType", "Namespace3.GenericType`1", "Namespace3.GenericType`2", "Namespace4.Embedded.Type1", "Namespace4.Embedded.Type2" }; using (var stream = forwardingCompilation.EmitToStream()) { using (var block = ModuleMetadata.CreateFromStream(stream)) { var metadataFullNames = MetadataValidation.GetExportedTypesFullNames(block.MetadataReader); Assert.Equal(sortedFullNames, metadataFullNames); } } }
internal CompilationVerifier CompileAndVerifyFieldMarshalCommon(Compilation compilation, Func <string, PEAssembly, byte[]> getExpectedBlob, bool isField = true) { return(CompileAndVerifyCommon(compilation, assemblyValidator: (assembly) => MetadataValidation.MarshalAsMetadataValidator(assembly, getExpectedBlob, isField))); }