Esempio n. 1
0
        public void TagCloud_functional_test()
        {
            var textContent = "Content text";
            var dividedText = new[] {"Content", "text"};
            var filteredDevidedText = new[] { "Content" };

            var text = "Content";
            var font = new Font("Arial", 10);
            var rect = new RectangleF(0, 0, 10, 10);
            var brush = new SolidBrush(Color.Aqua);
            var cloudWords = new[] { new TagCloudWord(text, font, rect, brush) }.ToImmutableList();

            var reader = A.Fake<IReader>();
            A.CallTo(() => reader.GetContent()).Returns(textContent);

            var parser = A.Fake<IParser>();
            A.CallTo(() => parser.SplitIntoWords(textContent)).Returns(dividedText);

            var filterSequence = A.Fake<IWordFiltersSequence>();
            A.CallTo(() => filterSequence.ApplyTo(dividedText)).Returns(filteredDevidedText);

            var algorithm = A.Fake<IAlgorithm>();
            A.CallTo(algorithm).WithReturnType<ImmutableList<TagCloudWord>>().Returns(cloudWords);

            var cloud = new TagCloud(reader, parser, filterSequence, algorithm);

            CollectionAssert.AreEqual(cloudWords, cloud.Words);
        }
		public void Basic()
		{
			var first = new object();
			var second = new object();

			var one = new[] { first, second }.ToImmutableHashSet();
			var two = new[] { second, first }.ToImmutableHashSet();
			
			Assert.Equal( one, two );
		}
        private static bool IsTestMethod(MethodDeclarationSyntax method)
        {
            var methodAttributes = new[] { "Test", "TestMethod", "Fact" };
            var attributes = method.AttributeLists.FirstOrDefault()?.Attributes;

            if (attributes == null)
            {
                return false;
            }

            return attributes.Value.Any(x => methodAttributes.Contains(x.Name.ToString()));
        }
        private void AnalyzeDateTimeUsage(SyntaxNodeAnalysisContext context)
        {
            if (context.IsGeneratedOrNonUserCode()) { return; }
            var node = context.Node as IdentifierNameSyntax;

            var membersToSearch = new[] {
                new SearchMemberInfo("System", "DateTime", "Now"),
                new SearchMemberInfo("System", "DateTime", "Today")
            };
            var symbol = node.CheckNodeIsMemberOfType(context.SemanticModel, membersToSearch);
            if (symbol == null) { return; }
            Diagnostic diagnostic = Diagnostic.Create(Rule, node.GetLocation(), $"{symbol.ContainingType.Name}.{symbol.Name}");
            context.ReportDiagnostic(diagnostic);
        }
        private void AnalyzeSymbol(SyntaxNodeAnalysisContext context)
        {
            var argumentList = (GenericNameSyntax) context.Node;
            var identifier = "Unnamed variable";
            var ancestorNodes = new[] { SyntaxKind.LocalDeclarationStatement, SyntaxKind.FieldDeclaration, SyntaxKind.Parameter, SyntaxKind.PropertyDeclaration };
            var parentNode = context.Node.AncestorsAndSelf().FirstOrDefault(x => ancestorNodes.Contains(x.Kind()));

            // We're having a return type
            if (context.Node.Parent is MethodDeclarationSyntax)
            {
                identifier = "Return statement";
            }

            if (parentNode != null)
            {
                switch (parentNode.Kind())
                {
                    case SyntaxKind.LocalDeclarationStatement:
                    {
                        identifier = ((LocalDeclarationStatementSyntax) parentNode).Declaration?.Variables.FirstOrDefault()?.Identifier.Text;
                        break;
                    }
                    case SyntaxKind.FieldDeclaration:
                    {
                        identifier = ((FieldDeclarationSyntax) parentNode).Declaration?.Variables.FirstOrDefault()?.Identifier.Text;
                        break;
                    }
                    case SyntaxKind.Parameter:
                    {
                        identifier = ((ParameterSyntax) parentNode).Identifier.Text;
                        break;
                    }
                    case SyntaxKind.TypeParameter:
                    {
                        identifier = ((TypeParameterSyntax) parentNode).Identifier.Text;
                        break;
                    }
                    case SyntaxKind.PropertyDeclaration:
                    {
                        identifier = ((PropertyDeclarationSyntax) parentNode).Identifier.Text;
                        break;
                    }
                }
            }

            Handle(identifier, context.Node.GetLocation(), argumentList, context);
        }
Esempio n. 6
0
        public void AllowsNonKeywordsAnywhereANameIsAllowed()
        {
            var nonKeywords = new[] {
              "on",
              "fragment",
              "query",
              "mutation",
              "true",
              "false",
            };
            foreach (var keyword in nonKeywords)
            {
                // You can't define or reference a fragment named `on`.
                var fragmentName = keyword == "on" ? "a" : keyword;
                ParseNoErr($@"query {keyword} {{
  ... {fragmentName}
  ... on {keyword} {{ field }}
}}
fragment {fragmentName} on Type {{
  {keyword}({keyword}: ${keyword}) @{keyword}({keyword}: {keyword})
}}");
            }
        }
        public void PartialMethod()
        {
            var source =
@"partial class C
{
    static partial void M1();
    static partial void M2();
    static partial void M3();
    static partial void M1() { }
    static partial void M2() { }
}";
            var compilation0 = CreateCompilationWithMscorlib(source, options: TestOptions.DebugDll);
            var compilation1 = CreateCompilationWithMscorlib(source, options: TestOptions.DebugDll);

            var bytes0 = compilation0.EmitToArray();
            using (var md0 = ModuleMetadata.CreateFromImage(bytes0))
            {
                var reader0 = md0.MetadataReader;
                CheckNames(reader0, reader0.GetMethodDefNames(), "M1", "M2", ".ctor");

                var method0 = compilation0.GetMember<MethodSymbol>("C.M2").PartialImplementationPart;
                var method1 = compilation1.GetMember<MethodSymbol>("C.M2").PartialImplementationPart;
                var generation0 = EmitBaseline.CreateInitialBaseline(
                    md0,
                    EmptyLocalsProvider);
                var diff1 = compilation1.EmitDifference(
                    generation0,
                    ImmutableArray.Create(new SemanticEdit(SemanticEditKind.Update, method0, method1)));

                var methods = diff1.TestData.Methods;
                Assert.Equal(methods.Count, 1);
                Assert.True(methods.ContainsKey("C.M2()"));

               using (var md1 = diff1.GetMetadata())
                {
                    var reader1 = md1.Reader;
                    var readers = new[] { reader0, reader1 };
                    EncValidation.VerifyModuleMvid(1, reader0, reader1);
                    CheckNames(readers, reader1.GetMethodDefNames(), "M2");
                    CheckEncLog(reader1,
                        Row(2, TableIndex.AssemblyRef, EditAndContinueOperation.Default),
                        Row(6, TableIndex.TypeRef, EditAndContinueOperation.Default),
                        Row(2, TableIndex.MethodDef, EditAndContinueOperation.Default));
                    CheckEncMap(reader1,
                        Handle(6, TableIndex.TypeRef),
                        Handle(2, TableIndex.MethodDef),
                        Handle(2, TableIndex.AssemblyRef));
                }
            }
        }
        public void OverriddenPropertyAccessibility7()
        {
            var source1 = @"
[assembly:System.Runtime.CompilerServices.InternalsVisibleTo(""B"")]
public class A
{
	protected internal virtual int P { get; set; }
}
";
            var source2 = @"
public class B : A
{
	protected internal override int P { set { } }
}
";
            // If this was C#, we would have to change the accessibility from
            // "protected internal" to "protected", so we'll do this in IL.
            var source3 = @"
.assembly extern mscorlib { }
.assembly extern B { }
.assembly C { }

.class public auto ansi beforefieldinit C
       extends [B]B
{
  .method famorassem hidebysig specialname virtual 
          instance int32  get_P() cil managed
  {
    ldc.i4.0
    ret
  }

  .method public hidebysig specialname rtspecialname 
          instance void  .ctor() cil managed
  {
    ldarg.0
    call       instance void [B]B::.ctor()
    ret
  } // end of method C::.ctor

  .property instance int32 P()
  {
    .get instance int32 C::get_P()
  } // end of property C::P
} // end of class C
";

            var comp1 = CreateCompilationWithMscorlib(source1, assemblyName: "A");
            var ref1 = comp1.EmitToImageReference();

            var comp2 = CreateCompilationWithMscorlib(source2, new[] { ref1 }, assemblyName: "B");
            var ref2 = comp2.EmitToImageReference();

            var ilRef = CompileIL(source3, appendDefaultHeader: false);

            var comp3 = CreateCompilationWithMscorlib("", new[] { ref1, ref2, ilRef }, assemblyName: "Test");
            comp3.VerifyDiagnostics();

            var properties = new[]
            {
                comp1.GlobalNamespace.GetMember<NamedTypeSymbol>("A").GetMember<PropertySymbol>("P"),

                comp2.GlobalNamespace.GetMember<NamedTypeSymbol>("A").GetMember<PropertySymbol>("P"),
                comp2.GlobalNamespace.GetMember<NamedTypeSymbol>("B").GetMember<PropertySymbol>("P"),

                comp3.GlobalNamespace.GetMember<NamedTypeSymbol>("A").GetMember<PropertySymbol>("P"),
                comp3.GlobalNamespace.GetMember<NamedTypeSymbol>("B").GetMember<PropertySymbol>("P"),
                comp3.GlobalNamespace.GetMember<NamedTypeSymbol>("C").GetMember<PropertySymbol>("P"),
            };

            AssertEx.All(properties, p => p.DeclaredAccessibility == Accessibility.ProtectedOrInternal);
        }
        public void TestMixedEventAccessorModifiers_EmptyAbstract()
        {
            var text1 = @"
abstract class Derived : AccessorModifierMismatch
{
    // Not overriding anything.
}
";
            var refs = new[] { TestReferences.SymbolsTests.Events };
            CreateCompilationWithMscorlib(text1, references: refs, compOptions: TestOptions.Dll).VerifyDiagnostics();
        }
        public void AddThenModifyMethod()
        {
            var source0 =
@"class A : System.Attribute { }
class C
{
    static void Main() { F1(null); }
    static object F1(string s1) { return s1; }
}";
            var source1 =
@"class A : System.Attribute { }
class C
{
    static void Main() { F2(); }
    [return:A]static object F2(string s2 = ""2"") { return s2; }
}";
            var source2 =
@"class A : System.Attribute { }
class C
{
    static void Main() { F2(); }
    [return:A]static object F2(string s2 = ""2"") { return null; }
}";
            var compilation0 = CreateCompilationWithMscorlib(source0, options: TestOptions.DebugExe);
            var compilation1 = CreateCompilationWithMscorlib(source1, options: TestOptions.DebugExe);
            var compilation2 = CreateCompilationWithMscorlib(source2, options: TestOptions.DebugExe);

            // Verify full metadata contains expected rows.
            var bytes0 = compilation0.EmitToArray();
            using (var md0 = ModuleMetadata.CreateFromImage(bytes0))
            {
                var reader0 = md0.MetadataReader;
                CheckNames(reader0, reader0.GetTypeDefNames(), "<Module>", "A", "C");
                CheckNames(reader0, reader0.GetMethodDefNames(), ".ctor", "Main", "F1", ".ctor");
                CheckNames(reader0, reader0.GetParameterDefNames(), "s1");

                var generation0 = EmitBaseline.CreateInitialBaseline(md0, EmptyLocalsProvider);

                var method1 = compilation1.GetMember<MethodSymbol>("C.F2");
                var diff1 = compilation1.EmitDifference(
                    generation0,
                    ImmutableArray.Create(new SemanticEdit(SemanticEditKind.Insert, null, method1)));

                // Verify delta metadata contains expected rows.
                using (var md1 = diff1.GetMetadata())
                {
                    var reader1 = md1.Reader;
                    var readers = new[] { reader0, reader1 };
                    EncValidation.VerifyModuleMvid(1, reader0, reader1);
                    CheckNames(readers, reader1.GetTypeDefNames());
                    CheckNames(readers, reader1.GetMethodDefNames(), "F2");
                    CheckNames(readers, reader1.GetParameterDefNames(), "", "s2");
                    CheckEncLog(reader1,
                        Row(2, TableIndex.AssemblyRef, EditAndContinueOperation.Default),
                        Row(7, TableIndex.TypeRef, EditAndContinueOperation.Default),
                        Row(2, TableIndex.StandAloneSig, EditAndContinueOperation.Default),
                        Row(3, TableIndex.TypeDef, EditAndContinueOperation.AddMethod),
                        Row(5, TableIndex.MethodDef, EditAndContinueOperation.Default),
                        Row(5, TableIndex.MethodDef, EditAndContinueOperation.AddParameter),
                        Row(2, TableIndex.Param, EditAndContinueOperation.Default),
                        Row(5, TableIndex.MethodDef, EditAndContinueOperation.AddParameter),
                        Row(3, TableIndex.Param, EditAndContinueOperation.Default),
                        Row(1, TableIndex.Constant, EditAndContinueOperation.Default),
                        Row(4, TableIndex.CustomAttribute, EditAndContinueOperation.Default));
                    CheckEncMap(reader1,
                        Handle(7, TableIndex.TypeRef),
                        Handle(5, TableIndex.MethodDef),
                        Handle(2, TableIndex.Param),
                        Handle(3, TableIndex.Param),
                        Handle(1, TableIndex.Constant),
                        Handle(4, TableIndex.CustomAttribute),
                        Handle(2, TableIndex.StandAloneSig),
                        Handle(2, TableIndex.AssemblyRef));

                    var method2 = compilation2.GetMember<MethodSymbol>("C.F2");
                    var diff2 = compilation2.EmitDifference(
                        diff1.NextGeneration,
                        ImmutableArray.Create(new SemanticEdit(SemanticEditKind.Update, method1, method2)));

                    // Verify delta metadata contains expected rows.
                    using (var md2 = diff2.GetMetadata())
                    {
                        var reader2 = md2.Reader;
                        readers = new[] { reader0, reader1, reader2 };
                        EncValidation.VerifyModuleMvid(2, reader1, reader2);
                        CheckNames(readers, reader2.GetTypeDefNames());
                        CheckNames(readers, reader2.GetMethodDefNames(), "F2");
                        CheckNames(readers, reader2.GetParameterDefNames());
                        CheckEncLog(reader2,
                            Row(3, TableIndex.AssemblyRef, EditAndContinueOperation.Default),
                            Row(8, TableIndex.TypeRef, EditAndContinueOperation.Default),
                            Row(3, TableIndex.StandAloneSig, EditAndContinueOperation.Default),
                            Row(5, TableIndex.MethodDef, EditAndContinueOperation.Default)); // C.F2
                        CheckEncMap(reader2,
                            Handle(8, TableIndex.TypeRef),
                            Handle(5, TableIndex.MethodDef),
                            Handle(3, TableIndex.StandAloneSig),
                            Handle(3, TableIndex.AssemblyRef));
                    }
                }
            }
        }
        public void AssemblyAndModuleAttributeReferences()
        {
            var source0 =
@"[assembly: System.CLSCompliantAttribute(true)]
[module: System.CLSCompliantAttribute(true)]
class C
{
}";
            var source1 =
@"[assembly: System.CLSCompliantAttribute(true)]
[module: System.CLSCompliantAttribute(true)]
class C
{
    static void M()
    {
    }
}";
            var compilation0 = CreateCompilationWithMscorlib(source0, options: TestOptions.DebugDll);
            var compilation1 = CreateCompilationWithMscorlib(source1, options: TestOptions.DebugDll);

            // Verify full metadata contains expected rows.
            var bytes0 = compilation0.EmitToArray();
            using (var md0 = ModuleMetadata.CreateFromImage(bytes0))
            {
                var reader0 = md0.MetadataReader;
                CheckNames(reader0, reader0.GetTypeDefNames(), "<Module>", "C");

                var generation0 = EmitBaseline.CreateInitialBaseline(md0, EmptyLocalsProvider);

                var diff1 = compilation1.EmitDifference(
                    generation0,
                    ImmutableArray.Create(new SemanticEdit(SemanticEditKind.Insert, null, compilation1.GetMember<MethodSymbol>("C.M"))));

                // Verify delta metadata contains expected rows.
                using (var md1 = diff1.GetMetadata())
                {
                    var readers = new[] { reader0, md1.Reader };
                    CheckNames(readers, md1.Reader.GetTypeDefNames());
                    CheckNames(readers, md1.Reader.GetMethodDefNames(), "M");
                    CheckEncLog(md1.Reader,
                        Row(2, TableIndex.AssemblyRef, EditAndContinueOperation.Default),
                        Row(7, TableIndex.TypeRef, EditAndContinueOperation.Default),
                        Row(2, TableIndex.TypeDef, EditAndContinueOperation.AddMethod),
                        Row(2, TableIndex.MethodDef, EditAndContinueOperation.Default)); // C.M
                    CheckEncMap(md1.Reader,
                        Handle(7, TableIndex.TypeRef),
                        Handle(2, TableIndex.MethodDef),
                        Handle(2, TableIndex.AssemblyRef));
                }
            }
        }
        public void NoPIAReferences()
        {
            var sourcePIA =
@"using System;
using System.Runtime.InteropServices;
[assembly: ImportedFromTypeLib(""_.dll"")]
[assembly: Guid(""35DB1A6B-D635-4320-A062-28D42921E2B3"")]
[ComImport()]
[Guid(""35DB1A6B-D635-4320-A062-28D42921E2B4"")]
public interface IA
{
    void M();
    int P { get; }
    event Action E;
}
[ComImport()]
[Guid(""35DB1A6B-D635-4320-A062-28D42921E2B5"")]
public interface IB
{
}
[ComImport()]
[Guid(""35DB1A6B-D635-4320-A062-28D42921E2B6"")]
public interface IC
{
}
public struct S
{
    public object F;
}";
            var source0 =
@"class C<T>
{
    static object F = typeof(IC);
    static void M1()
    {
        var o = default(IA);
        o.M();
        M2(o.P);
        o.E += M1;
        M2(C<IA>.F);
        M2(new S());
    }
    static void M2(object o)
    {
    }
}";
            var source1A = source0;
            var source1B =
@"class C<T>
{
    static object F = typeof(IC);
    static void M1()
    {
        M2(null);
    }
    static void M2(object o)
    {
    }
}";
            var compilationPIA = CreateCompilationWithMscorlib(sourcePIA, options: TestOptions.DebugDll);
            var referencePIA = new MetadataImageReference(compilationPIA.EmitToArray(), embedInteropTypes: true);
            var compilation0 = CreateCompilationWithMscorlib(source0, options: TestOptions.DebugDll, references: new MetadataReference[] { referencePIA, SystemCoreRef, CSharpRef });
            var compilation1A = CreateCompilationWithMscorlib(source1A, options: TestOptions.DebugDll, references: new MetadataReference[] { referencePIA, SystemCoreRef, CSharpRef });
            var compilation1B = CreateCompilationWithMscorlib(source1B, options: TestOptions.DebugDll, references: new MetadataReference[] { referencePIA, SystemCoreRef, CSharpRef });

            var testData0 = new CompilationTestData();
            var bytes0 = compilation0.EmitToArray(testData: testData0);
            var methodData0 = testData0.GetMethodData("C<T>.M1");
            using (var md0 = ModuleMetadata.CreateFromImage(bytes0))
            {
                var reader0 = md0.MetadataReader;
                CheckNames(reader0, reader0.GetTypeDefNames(), "<Module>", "C`1", "IA", "IC", "S");
                var generation0 = EmitBaseline.CreateInitialBaseline(md0, m => GetLocalNames(methodData0));
                var method0 = compilation0.GetMember<MethodSymbol>("C.M1");

                // Disallow edits that require NoPIA references.
                var method1A = compilation1A.GetMember<MethodSymbol>("C.M1");
                var diff1A = compilation1A.EmitDifference(
                    generation0,
                    ImmutableArray.Create(new SemanticEdit(SemanticEditKind.Update, method0, method1A, GetEquivalentNodesMap(method1A, method0), preserveLocalVariables: true)));
                diff1A.Result.Diagnostics.Verify(
                    // error CS7094: Cannot continue since the edit includes a reference to an embedded type: 'S'.
                    Diagnostic(ErrorCode.ERR_EnCNoPIAReference).WithArguments("S"),
                    // error CS7094: Cannot continue since the edit includes a reference to an embedded type: 'IA'.
                    Diagnostic(ErrorCode.ERR_EnCNoPIAReference).WithArguments("IA"));

                // Allow edits that do not require NoPIA references,
                // even if the previous code included references.
                var method1B = compilation1B.GetMember<MethodSymbol>("C.M1");
                var diff1B = compilation1B.EmitDifference(
                    generation0,
                    ImmutableArray.Create(new SemanticEdit(SemanticEditKind.Update, method0, method1B, GetEquivalentNodesMap(method1B, method0), preserveLocalVariables: true)));
                diff1B.VerifyIL("C<T>.M1",
@"{
  // Code size        9 (0x9)
  .maxstack  1
  .locals init ([unchanged] V_0,
  [unchanged] V_1)
  IL_0000:  nop
  IL_0001:  ldnull
  IL_0002:  call       ""void C<T>.M2(object)""
  IL_0007:  nop
  IL_0008:  ret
}");
                using (var md1 = diff1B.GetMetadata())
                {
                    var reader1 = md1.Reader;
                    var readers = new[] { reader0, reader1 };
                    CheckNames(readers, reader1.GetTypeDefNames());
                }
            }
        }
        public void AddEvent()
        {
            var source0 =
@"delegate void D();
class A
{
    event D E;
}
class B
{
}";
            var source1 =
@"delegate void D();
class A
{
    event D E;
}
class B
{
    event D F;
}";
            var source2 =
@"delegate void D();
class A
{
    event D E;
    event D G;
}
class B
{
    event D F;
    event D H;
}";
            var compilation0 = CreateCompilationWithMscorlib(source0, options: TestOptions.DebugDll);
            var compilation1 = CreateCompilationWithMscorlib(source1, options: TestOptions.DebugDll);
            var compilation2 = CreateCompilationWithMscorlib(source2, options: TestOptions.DebugDll);

            // Verify full metadata contains expected rows.
            var bytes0 = compilation0.EmitToArray();
            using (var md0 = ModuleMetadata.CreateFromImage(bytes0))
            {
                var reader0 = md0.MetadataReader;
                CheckNames(reader0, reader0.GetTypeDefNames(), "<Module>", "D", "A", "B");
                CheckNames(reader0, reader0.GetFieldDefNames(), "E");
                CheckNames(reader0, reader0.GetEventDefNames(), "E");
                CheckNames(reader0, reader0.GetMethodDefNames(), ".ctor", "BeginInvoke", "EndInvoke", "Invoke", "add_E", "remove_E", ".ctor", ".ctor");

                var generation0 = EmitBaseline.CreateInitialBaseline(md0, EmptyLocalsProvider);

                var diff1 = compilation1.EmitDifference(
                    generation0,
                    ImmutableArray.Create(new SemanticEdit(SemanticEditKind.Insert, null, compilation1.GetMember<EventSymbol>("B.F"))));

                // Verify delta metadata contains expected rows.
                using (var md1 = diff1.GetMetadata())
                {
                    var reader1 = md1.Reader;
                    var readers = new[] { reader0, reader1 };
                    CheckNames(readers, reader1.GetTypeDefNames());
                    CheckNames(readers, reader1.GetFieldDefNames(), "F");
                    CheckNames(readers, reader1.GetMethodDefNames(), "add_F", "remove_F");
                    CheckEncLog(reader1,
                        Row(2, TableIndex.AssemblyRef, EditAndContinueOperation.Default),
                        Row(10, TableIndex.MemberRef, EditAndContinueOperation.Default),
                        Row(11, TableIndex.MemberRef, EditAndContinueOperation.Default),
                        Row(12, TableIndex.MemberRef, EditAndContinueOperation.Default),
                        Row(13, TableIndex.MemberRef, EditAndContinueOperation.Default),
                        Row(14, TableIndex.MemberRef, EditAndContinueOperation.Default),
                        Row(2, TableIndex.MethodSpec, EditAndContinueOperation.Default),
                        Row(14, TableIndex.TypeRef, EditAndContinueOperation.Default),
                        Row(15, TableIndex.TypeRef, EditAndContinueOperation.Default),
                        Row(16, TableIndex.TypeRef, EditAndContinueOperation.Default),
                        Row(17, TableIndex.TypeRef, EditAndContinueOperation.Default),
                        Row(18, TableIndex.TypeRef, EditAndContinueOperation.Default),
                        Row(19, TableIndex.TypeRef, EditAndContinueOperation.Default),
                        Row(2, TableIndex.StandAloneSig, EditAndContinueOperation.Default),
                        Row(2, TableIndex.EventMap, EditAndContinueOperation.Default),
                        Row(2, TableIndex.EventMap, EditAndContinueOperation.AddEvent),
                        Row(2, TableIndex.Event, EditAndContinueOperation.Default),
                        Row(4, TableIndex.TypeDef, EditAndContinueOperation.AddField),
                        Row(2, TableIndex.Field, EditAndContinueOperation.Default),
                        Row(4, TableIndex.TypeDef, EditAndContinueOperation.AddMethod),
                        Row(9, TableIndex.MethodDef, EditAndContinueOperation.Default),
                        Row(4, TableIndex.TypeDef, EditAndContinueOperation.AddMethod),
                        Row(10, TableIndex.MethodDef, EditAndContinueOperation.Default),
                        Row(9, TableIndex.MethodDef, EditAndContinueOperation.AddParameter),
                        Row(8, TableIndex.Param, EditAndContinueOperation.Default),
                        Row(10, TableIndex.MethodDef, EditAndContinueOperation.AddParameter),
                        Row(9, TableIndex.Param, EditAndContinueOperation.Default),
                        Row(8, TableIndex.CustomAttribute, EditAndContinueOperation.Default),
                        Row(9, TableIndex.CustomAttribute, EditAndContinueOperation.Default),
                        Row(10, TableIndex.CustomAttribute, EditAndContinueOperation.Default),
                        Row(11, TableIndex.CustomAttribute, EditAndContinueOperation.Default),
                        Row(3, TableIndex.MethodSemantics, EditAndContinueOperation.Default),
                        Row(4, TableIndex.MethodSemantics, EditAndContinueOperation.Default));
                    CheckEncMap(reader1,
                        Handle(14, TableIndex.TypeRef),
                        Handle(15, TableIndex.TypeRef),
                        Handle(16, TableIndex.TypeRef),
                        Handle(17, TableIndex.TypeRef),
                        Handle(18, TableIndex.TypeRef),
                        Handle(19, TableIndex.TypeRef),
                        Handle(2, TableIndex.Field),
                        Handle(9, TableIndex.MethodDef),
                        Handle(10, TableIndex.MethodDef),
                        Handle(8, TableIndex.Param),
                        Handle(9, TableIndex.Param),
                        Handle(10, TableIndex.MemberRef),
                        Handle(11, TableIndex.MemberRef),
                        Handle(12, TableIndex.MemberRef),
                        Handle(13, TableIndex.MemberRef),
                        Handle(14, TableIndex.MemberRef),
                        Handle(8, TableIndex.CustomAttribute),
                        Handle(9, TableIndex.CustomAttribute),
                        Handle(10, TableIndex.CustomAttribute),
                        Handle(11, TableIndex.CustomAttribute),
                        Handle(2, TableIndex.StandAloneSig),
                        Handle(2, TableIndex.EventMap),
                        Handle(2, TableIndex.Event),
                        Handle(3, TableIndex.MethodSemantics),
                        Handle(4, TableIndex.MethodSemantics),
                        Handle(2, TableIndex.AssemblyRef),
                        Handle(2, TableIndex.MethodSpec));

                    var diff2 = compilation2.EmitDifference(
                        diff1.NextGeneration,
                        ImmutableArray.Create(
                            new SemanticEdit(SemanticEditKind.Insert, null, compilation2.GetMember<EventSymbol>("A.G")),
                            new SemanticEdit(SemanticEditKind.Insert, null, compilation2.GetMember<EventSymbol>("B.H"))));

                    // Verify delta metadata contains expected rows.
                    using (var md2 = diff2.GetMetadata())
                    {
                        var reader2 = md2.Reader;
                        readers = new[] { reader0, reader1, reader2 };
                        CheckNames(readers, reader2.GetTypeDefNames());
                        CheckNames(readers, reader2.GetFieldDefNames(), "G", "H");
                        CheckNames(readers, reader2.GetMethodDefNames(), "add_G", "remove_G", "add_H", "remove_H");
                        CheckEncLog(reader2,
                            Row(3, TableIndex.AssemblyRef, EditAndContinueOperation.Default),
                            Row(15, TableIndex.MemberRef, EditAndContinueOperation.Default),
                            Row(16, TableIndex.MemberRef, EditAndContinueOperation.Default),
                            Row(17, TableIndex.MemberRef, EditAndContinueOperation.Default),
                            Row(18, TableIndex.MemberRef, EditAndContinueOperation.Default),
                            Row(19, TableIndex.MemberRef, EditAndContinueOperation.Default),
                            Row(3, TableIndex.MethodSpec, EditAndContinueOperation.Default),
                            Row(20, TableIndex.TypeRef, EditAndContinueOperation.Default),
                            Row(21, TableIndex.TypeRef, EditAndContinueOperation.Default),
                            Row(22, TableIndex.TypeRef, EditAndContinueOperation.Default),
                            Row(23, TableIndex.TypeRef, EditAndContinueOperation.Default),
                            Row(24, TableIndex.TypeRef, EditAndContinueOperation.Default),
                            Row(25, TableIndex.TypeRef, EditAndContinueOperation.Default),
                            Row(3, TableIndex.StandAloneSig, EditAndContinueOperation.Default),
                            Row(1, TableIndex.EventMap, EditAndContinueOperation.AddEvent),
                            Row(3, TableIndex.Event, EditAndContinueOperation.Default),
                            Row(2, TableIndex.EventMap, EditAndContinueOperation.AddEvent),
                            Row(4, TableIndex.Event, EditAndContinueOperation.Default),
                            Row(3, TableIndex.TypeDef, EditAndContinueOperation.AddField),
                            Row(3, TableIndex.Field, EditAndContinueOperation.Default),
                            Row(4, TableIndex.TypeDef, EditAndContinueOperation.AddField),
                            Row(4, TableIndex.Field, EditAndContinueOperation.Default),
                            Row(3, TableIndex.TypeDef, EditAndContinueOperation.AddMethod),
                            Row(11, TableIndex.MethodDef, EditAndContinueOperation.Default),
                            Row(3, TableIndex.TypeDef, EditAndContinueOperation.AddMethod),
                            Row(12, TableIndex.MethodDef, EditAndContinueOperation.Default),
                            Row(4, TableIndex.TypeDef, EditAndContinueOperation.AddMethod),
                            Row(13, TableIndex.MethodDef, EditAndContinueOperation.Default),
                            Row(4, TableIndex.TypeDef, EditAndContinueOperation.AddMethod),
                            Row(14, TableIndex.MethodDef, EditAndContinueOperation.Default),
                            Row(11, TableIndex.MethodDef, EditAndContinueOperation.AddParameter),
                            Row(10, TableIndex.Param, EditAndContinueOperation.Default),
                            Row(12, TableIndex.MethodDef, EditAndContinueOperation.AddParameter),
                            Row(11, TableIndex.Param, EditAndContinueOperation.Default),
                            Row(13, TableIndex.MethodDef, EditAndContinueOperation.AddParameter),
                            Row(12, TableIndex.Param, EditAndContinueOperation.Default),
                            Row(14, TableIndex.MethodDef, EditAndContinueOperation.AddParameter),
                            Row(13, TableIndex.Param, EditAndContinueOperation.Default),
                            Row(12, TableIndex.CustomAttribute, EditAndContinueOperation.Default),
                            Row(13, TableIndex.CustomAttribute, EditAndContinueOperation.Default),
                            Row(14, TableIndex.CustomAttribute, EditAndContinueOperation.Default),
                            Row(15, TableIndex.CustomAttribute, EditAndContinueOperation.Default),
                            Row(16, TableIndex.CustomAttribute, EditAndContinueOperation.Default),
                            Row(17, TableIndex.CustomAttribute, EditAndContinueOperation.Default),
                            Row(18, TableIndex.CustomAttribute, EditAndContinueOperation.Default),
                            Row(19, TableIndex.CustomAttribute, EditAndContinueOperation.Default),
                            Row(5, TableIndex.MethodSemantics, EditAndContinueOperation.Default),
                            Row(6, TableIndex.MethodSemantics, EditAndContinueOperation.Default),
                            Row(7, TableIndex.MethodSemantics, EditAndContinueOperation.Default),
                            Row(8, TableIndex.MethodSemantics, EditAndContinueOperation.Default));
                        CheckEncMap(reader2,
                            Handle(20, TableIndex.TypeRef),
                            Handle(21, TableIndex.TypeRef),
                            Handle(22, TableIndex.TypeRef),
                            Handle(23, TableIndex.TypeRef),
                            Handle(24, TableIndex.TypeRef),
                            Handle(25, TableIndex.TypeRef),
                            Handle(3, TableIndex.Field),
                            Handle(4, TableIndex.Field),
                            Handle(11, TableIndex.MethodDef),
                            Handle(12, TableIndex.MethodDef),
                            Handle(13, TableIndex.MethodDef),
                            Handle(14, TableIndex.MethodDef),
                            Handle(10, TableIndex.Param),
                            Handle(11, TableIndex.Param),
                            Handle(12, TableIndex.Param),
                            Handle(13, TableIndex.Param),
                            Handle(15, TableIndex.MemberRef),
                            Handle(16, TableIndex.MemberRef),
                            Handle(17, TableIndex.MemberRef),
                            Handle(18, TableIndex.MemberRef),
                            Handle(19, TableIndex.MemberRef),
                            Handle(12, TableIndex.CustomAttribute),
                            Handle(13, TableIndex.CustomAttribute),
                            Handle(14, TableIndex.CustomAttribute),
                            Handle(15, TableIndex.CustomAttribute),
                            Handle(16, TableIndex.CustomAttribute),
                            Handle(17, TableIndex.CustomAttribute),
                            Handle(18, TableIndex.CustomAttribute),
                            Handle(19, TableIndex.CustomAttribute),
                            Handle(3, TableIndex.StandAloneSig),
                            Handle(3, TableIndex.Event),
                            Handle(4, TableIndex.Event),
                            Handle(5, TableIndex.MethodSemantics),
                            Handle(6, TableIndex.MethodSemantics),
                            Handle(7, TableIndex.MethodSemantics),
                            Handle(8, TableIndex.MethodSemantics),
                            Handle(3, TableIndex.AssemblyRef),
                            Handle(3, TableIndex.MethodSpec));
                    }
                }
            }
        }
        public void AddProperty()
        {
            var source0 =
@"class A
{
    object P { get; set; }
}
class B
{
}";
            var source1 =
@"class A
{
    object P { get; set; }
}
class B
{
    object R { get { return null; } }
}";
            var source2 =
@"class A
{
    object P { get; set; }
    object Q { get; set; }
}
class B
{
    object R { get { return null; } }
    object S { set { } }
}";
            var compilation0 = CreateCompilationWithMscorlib(source0, options: TestOptions.DebugDll);
            var compilation1 = CreateCompilationWithMscorlib(source1, options: TestOptions.DebugDll);
            var compilation2 = CreateCompilationWithMscorlib(source2, options: TestOptions.DebugDll);

            // Verify full metadata contains expected rows.
            var bytes0 = compilation0.EmitToArray();
            using (var md0 = ModuleMetadata.CreateFromImage(bytes0))
            {
                var reader0 = md0.MetadataReader;
                CheckNames(reader0, reader0.GetTypeDefNames(), "<Module>", "A", "B");
                CheckNames(reader0, reader0.GetFieldDefNames(), "<P>k__BackingField");
                CheckNames(reader0, reader0.GetPropertyDefNames(), "P");
                CheckNames(reader0, reader0.GetMethodDefNames(), "get_P", "set_P", ".ctor", ".ctor");

                var generation0 = EmitBaseline.CreateInitialBaseline(md0, EmptyLocalsProvider);

                var diff1 = compilation1.EmitDifference(
                    generation0,
                    ImmutableArray.Create(new SemanticEdit(SemanticEditKind.Insert, null, compilation1.GetMember<PropertySymbol>("B.R"))));

                // Verify delta metadata contains expected rows.
                using (var md1 = diff1.GetMetadata())
                {
                    var reader1 = md1.Reader;
                    var readers = new[] { reader0, reader1 };
                    CheckNames(readers, reader1.GetTypeDefNames());
                    CheckNames(readers, reader1.GetFieldDefNames());
                    CheckNames(readers, reader1.GetPropertyDefNames(), "R");
                    CheckNames(readers, reader1.GetMethodDefNames(), "get_R");
                    CheckEncLog(reader1,
                        Row(2, TableIndex.AssemblyRef, EditAndContinueOperation.Default),
                        Row(9, TableIndex.TypeRef, EditAndContinueOperation.Default),
                        Row(2, TableIndex.StandAloneSig, EditAndContinueOperation.Default),
                        Row(2, TableIndex.PropertyMap, EditAndContinueOperation.Default),
                        Row(3, TableIndex.TypeDef, EditAndContinueOperation.AddMethod),
                        Row(5, TableIndex.MethodDef, EditAndContinueOperation.Default),
                        Row(2, TableIndex.PropertyMap, EditAndContinueOperation.AddProperty),
                        Row(2, TableIndex.Property, EditAndContinueOperation.Default),
                        Row(3, TableIndex.MethodSemantics, EditAndContinueOperation.Default));
                    CheckEncMap(reader1,
                        Handle(9, TableIndex.TypeRef),
                        Handle(5, TableIndex.MethodDef),
                        Handle(2, TableIndex.StandAloneSig),
                        Handle(2, TableIndex.PropertyMap),
                        Handle(2, TableIndex.Property),
                        Handle(3, TableIndex.MethodSemantics),
                        Handle(2, TableIndex.AssemblyRef));

                    var diff2 = compilation2.EmitDifference(
                        diff1.NextGeneration,
                        ImmutableArray.Create(
                            new SemanticEdit(SemanticEditKind.Insert, null, compilation2.GetMember<PropertySymbol>("A.Q")),
                            new SemanticEdit(SemanticEditKind.Insert, null, compilation2.GetMember<PropertySymbol>("B.S"))));

                    // Verify delta metadata contains expected rows.
                    using (var md2 = diff2.GetMetadata())
                    {
                        var reader2 = md2.Reader;
                        readers = new[] { reader0, reader1, reader2 };
                        CheckNames(readers, reader2.GetTypeDefNames());
                        CheckNames(readers, reader2.GetFieldDefNames(), "<Q>k__BackingField");
                        CheckNames(readers, reader2.GetPropertyDefNames(), "Q", "S");
                        CheckNames(readers, reader2.GetMethodDefNames(), "get_Q", "set_Q", "set_S");
                        CheckEncLog(reader2,
                            Row(3, TableIndex.AssemblyRef, EditAndContinueOperation.Default),
                            Row(7, TableIndex.MemberRef, EditAndContinueOperation.Default),
                            Row(8, TableIndex.MemberRef, EditAndContinueOperation.Default),
                            Row(10, TableIndex.TypeRef, EditAndContinueOperation.Default),
                            Row(11, TableIndex.TypeRef, EditAndContinueOperation.Default),
                            Row(12, TableIndex.TypeRef, EditAndContinueOperation.Default),
                            Row(13, TableIndex.TypeRef, EditAndContinueOperation.Default),
                            Row(3, TableIndex.StandAloneSig, EditAndContinueOperation.Default),
                            Row(2, TableIndex.TypeDef, EditAndContinueOperation.AddField),
                            Row(2, TableIndex.Field, EditAndContinueOperation.Default),
                            Row(2, TableIndex.TypeDef, EditAndContinueOperation.AddMethod),
                            Row(6, TableIndex.MethodDef, EditAndContinueOperation.Default),
                            Row(2, TableIndex.TypeDef, EditAndContinueOperation.AddMethod),
                            Row(7, TableIndex.MethodDef, EditAndContinueOperation.Default),
                            Row(3, TableIndex.TypeDef, EditAndContinueOperation.AddMethod),
                            Row(8, TableIndex.MethodDef, EditAndContinueOperation.Default),
                            Row(1, TableIndex.PropertyMap, EditAndContinueOperation.AddProperty),
                            Row(3, TableIndex.Property, EditAndContinueOperation.Default),
                            Row(2, TableIndex.PropertyMap, EditAndContinueOperation.AddProperty),
                            Row(4, TableIndex.Property, EditAndContinueOperation.Default),
                            Row(7, TableIndex.MethodDef, EditAndContinueOperation.AddParameter),
                            Row(2, TableIndex.Param, EditAndContinueOperation.Default),
                            Row(8, TableIndex.MethodDef, EditAndContinueOperation.AddParameter),
                            Row(3, TableIndex.Param, EditAndContinueOperation.Default),
                            Row(8, TableIndex.CustomAttribute, EditAndContinueOperation.Default),
                            Row(9, TableIndex.CustomAttribute, EditAndContinueOperation.Default),
                            Row(10, TableIndex.CustomAttribute, EditAndContinueOperation.Default),
                            Row(11, TableIndex.CustomAttribute, EditAndContinueOperation.Default),
                            Row(4, TableIndex.MethodSemantics, EditAndContinueOperation.Default),
                            Row(5, TableIndex.MethodSemantics, EditAndContinueOperation.Default),
                            Row(6, TableIndex.MethodSemantics, EditAndContinueOperation.Default));
                        CheckEncMap(reader2,
                            Handle(10, TableIndex.TypeRef),
                            Handle(11, TableIndex.TypeRef),
                            Handle(12, TableIndex.TypeRef),
                            Handle(13, TableIndex.TypeRef),
                            Handle(2, TableIndex.Field),
                            Handle(6, TableIndex.MethodDef),
                            Handle(7, TableIndex.MethodDef),
                            Handle(8, TableIndex.MethodDef),
                            Handle(2, TableIndex.Param),
                            Handle(3, TableIndex.Param),
                            Handle(7, TableIndex.MemberRef),
                            Handle(8, TableIndex.MemberRef),
                            Handle(8, TableIndex.CustomAttribute),
                            Handle(9, TableIndex.CustomAttribute),
                            Handle(10, TableIndex.CustomAttribute),
                            Handle(11, TableIndex.CustomAttribute),
                            Handle(3, TableIndex.StandAloneSig),
                            Handle(3, TableIndex.Property),
                            Handle(4, TableIndex.Property),
                            Handle(4, TableIndex.MethodSemantics),
                            Handle(5, TableIndex.MethodSemantics),
                            Handle(6, TableIndex.MethodSemantics),
                            Handle(3, TableIndex.AssemblyRef));
                    }
                }
            }
        }
        public void PrivateImplementationDetails_ComputeStringHash()
        {
            var source =
@"class C
{
    static int F(string s)
    {
        switch (s)
        {
            case ""1"": return 1;
            case ""2"": return 2;
            case ""3"": return 3;
            case ""4"": return 4;
            case ""5"": return 5;
            case ""6"": return 6;
            case ""7"": return 7;
            default: return 0;
        }
    }
}";
            const string ComputeStringHashName = "$$method0x6000001-ComputeStringHash";
            var compilation0 = CreateCompilationWithMscorlib(source, options: TestOptions.DebugDll);
            var compilation1 = CreateCompilationWithMscorlib(source, options: TestOptions.DebugDll);

            var testData0 = new CompilationTestData();
            var bytes0 = compilation0.EmitToArray(testData: testData0);
            var methodData0 = testData0.GetMethodData("C.F");
            var method0 = compilation0.GetMember<MethodSymbol>("C.F");
            var generation0 = EmitBaseline.CreateInitialBaseline(ModuleMetadata.CreateFromImage(bytes0), m => GetLocalNames(methodData0));

            // Should have generated call to ComputeStringHash and
            // added the method to <PrivateImplementationDetails>.
            var actualIL0 = methodData0.GetMethodIL();
            Assert.True(actualIL0.Contains(ComputeStringHashName));

            using (var md0 = ModuleMetadata.CreateFromImage(bytes0))
            {
                var reader0 = md0.MetadataReader;
                CheckNames(reader0, reader0.GetMethodDefNames(), "F", ".ctor", ComputeStringHashName);

                var method1 = compilation1.GetMember<MethodSymbol>("C.F");
                var diff1 = compilation1.EmitDifference(
                    generation0,
                    ImmutableArray.Create(new SemanticEdit(SemanticEditKind.Update, method0, method1, GetEquivalentNodesMap(method1, method0), preserveLocalVariables: true)));

                // Should not have generated call to ComputeStringHash nor
                // added the method to <PrivateImplementationDetails>.
                var actualIL1 = diff1.GetMethodIL("C.F");
                Assert.False(actualIL1.Contains(ComputeStringHashName));

                using (var md1 = diff1.GetMetadata())
                {
                    var reader1 = md1.Reader;
                    var readers = new[] { reader0, reader1 };
                    CheckNames(readers, reader1.GetMethodDefNames(), "F");
                }
            }
        }
        public void AddField()
        {
            var source0 =
@"class C
{
    string F = ""F"";
}";
            var source1 =
@"class C
{
    string F = ""F"";
    string G = ""G"";
}";
            var compilation0 = CreateCompilationWithMscorlib(source0, options: TestOptions.DebugDll);
            var compilation1 = CreateCompilationWithMscorlib(source1, options: TestOptions.DebugDll);

            // Verify full metadata contains expected rows.
            var bytes0 = compilation0.EmitToArray();
            using (var md0 = ModuleMetadata.CreateFromImage(bytes0))
            {
                var reader0 = md0.MetadataReader;
                CheckNames(reader0, reader0.GetTypeDefNames(), "<Module>", "C");
                CheckNames(reader0, reader0.GetFieldDefNames(), "F");
                CheckNames(reader0, reader0.GetMethodDefNames(), ".ctor");

                var generation0 = EmitBaseline.CreateInitialBaseline(md0, EmptyLocalsProvider);
                var method0 = compilation0.GetMember<MethodSymbol>("C..ctor");
                var method1 = compilation1.GetMember<MethodSymbol>("C..ctor");

                var diff1 = compilation1.EmitDifference(
                    generation0,
                    ImmutableArray.Create(
                        new SemanticEdit(SemanticEditKind.Insert, null, compilation1.GetMember<FieldSymbol>("C.G")),
                        new SemanticEdit(SemanticEditKind.Update, method0, method1)));

                // Verify delta metadata contains expected rows.
                using (var md1 = diff1.GetMetadata())
                {
                    var reader1 = md1.Reader;
                    var readers = new[] { reader0, reader1 };
                    CheckNames(readers, reader1.GetTypeDefNames());
                    CheckNames(readers, reader1.GetFieldDefNames(), "G");
                    CheckNames(readers, reader1.GetMethodDefNames(), ".ctor");
                    CheckEncLog(reader1,
                        Row(2, TableIndex.AssemblyRef, EditAndContinueOperation.Default),
                        Row(5, TableIndex.MemberRef, EditAndContinueOperation.Default),
                        Row(6, TableIndex.TypeRef, EditAndContinueOperation.Default),
                        Row(2, TableIndex.TypeDef, EditAndContinueOperation.AddField),
                        Row(2, TableIndex.Field, EditAndContinueOperation.Default),
                        Row(1, TableIndex.MethodDef, EditAndContinueOperation.Default));
                    CheckEncMap(reader1,
                        Handle(6, TableIndex.TypeRef),
                        Handle(2, TableIndex.Field),
                        Handle(1, TableIndex.MethodDef),
                        Handle(5, TableIndex.MemberRef),
                        Handle(2, TableIndex.AssemblyRef));
                }
            }
        }
        public void PrivateImplementationDetails()
        {
            var source =
@"class C
{
    static int[] F = new int[] { 1, 2, 3 };
    int[] G = new int[] { 4, 5, 6 };
    int M(int index)
    {
        return F[index] + G[index];
    }
}";
            var compilation0 = CreateCompilationWithMscorlib(source, options: TestOptions.DebugDll);
            var compilation1 = CreateCompilationWithMscorlib(source, options: TestOptions.DebugDll);

            var testData0 = new CompilationTestData();
            var bytes0 = compilation0.EmitToArray(testData: testData0);
            using (var md0 = ModuleMetadata.CreateFromImage(bytes0))
            {
                var reader0 = md0.MetadataReader;
                var typeNames = new[] { reader0 }.GetStrings(reader0.GetTypeDefNames());
                Assert.NotNull(typeNames.FirstOrDefault(n => n.StartsWith("<PrivateImplementationDetails>")));
            }

            var methodData0 = testData0.GetMethodData("C.M");
            var method0 = compilation0.GetMember<MethodSymbol>("C.M");
            var generation0 = EmitBaseline.CreateInitialBaseline(ModuleMetadata.CreateFromImage(bytes0), m => GetLocalNames(methodData0));

            var method1 = compilation1.GetMember<MethodSymbol>("C.M");
            var diff1 = compilation1.EmitDifference(
                generation0,
                ImmutableArray.Create(new SemanticEdit(SemanticEditKind.Update, method0, method1, GetEquivalentNodesMap(method1, method0), preserveLocalVariables: true)));

            diff1.VerifyIL("C.M", @"
{
  // Code size       22 (0x16)
  .maxstack  3
  .locals init ([int] V_0,
                int V_1)
  IL_0000:  nop
  IL_0001:  ldsfld     ""int[] C.F""
  IL_0006:  ldarg.1
  IL_0007:  ldelem.i4
  IL_0008:  ldarg.0
  IL_0009:  ldfld      ""int[] C.G""
  IL_000e:  ldarg.1
  IL_000f:  ldelem.i4
  IL_0010:  add
  IL_0011:  stloc.1
  IL_0012:  br.s       IL_0014
  IL_0014:  ldloc.1
  IL_0015:  ret
}");
        }
        private static bool IsIndexOfCall(ExpressionSyntax call, SemanticModel semanticModel)
        {
            var indexOfSymbol = semanticModel.GetSymbolInfo(call).Symbol as IMethodSymbol;
            if (indexOfSymbol == null ||
                indexOfSymbol.Name != "IndexOf")
            {
                return false;
            }

            var possibleTypes = new[]
            {
                KnownType.System_Array,
                KnownType.System_Collections_Generic_IList_T,
                KnownType.System_String,
                KnownType.System_Collections_IList
            }.ToImmutableHashSet();

            return indexOfSymbol.ContainingType.DerivesOrImplementsAny(possibleTypes);
        }
        public override void Initialize(AnalysisContext analysisContext)
        {
            analysisContext.RegisterCompilationStartAction(
                compilationStartAnalysisContext =>
                {
                    Compilation compilation = compilationStartAnalysisContext.Compilation;

                    INamedTypeSymbol[] nativeResourceTypes = new[]
                    {
                        WellKnownTypes.IntPtr(compilation),
                        WellKnownTypes.UIntPtr(compilation),
                        WellKnownTypes.HandleRef(compilation)
                    };

                    compilationStartAnalysisContext.RegisterOperationAction(
                        operationAnalysisContext =>
                        {
                            var assignment = (IAssignmentExpression)operationAnalysisContext.Operation;

                            IReferenceExpression target = assignment.Target;
                            if (target == null)
                            {
                                // This can happen if the left-hand side is an undefined symbol.
                                return;
                            }

                            if (target.Kind != OperationKind.FieldReferenceExpression)
                            {
                                return;
                            }

                            var fieldReference = (IFieldReferenceExpression)target;
                            var field = fieldReference.Member as IFieldSymbol;
                            if (field == null || field.Kind != SymbolKind.Field || field.IsStatic)
                            {
                                return;
                            }

                            if (!nativeResourceTypes.Contains(field.Type))
                            {
                                return;
                            }

                            INamedTypeSymbol containingType = field.ContainingType;
                            if (containingType == null || containingType.IsValueType)
                            {
                                return;
                            }

                            if (!containingType.AllInterfaces.Contains(WellKnownTypes.IDisposable(compilation)))
                            {
                                return;
                            }

                            if (containingType.HasFinalizer())
                            {
                                return;
                            }

                            if (assignment.Value == null || assignment.Value.Kind != OperationKind.InvocationExpression)
                            {
                                return;
                            }

                            var invocation = (IInvocationExpression)assignment.Value;
                            if (invocation == null)
                            {
                                return;
                            }

                            IMethodSymbol method = invocation.TargetMethod;

                            // TODO: What about COM?
                            if (method.GetDllImportData() == null)
                            {
                                return;
                            }

                            operationAnalysisContext.ReportDiagnostic(containingType.CreateDiagnostic(Rule));
                        },
                        OperationKind.AssignmentExpression);
                });
        }
Esempio n. 20
0
        internal void GetSimpleBuiltInOperators(BinaryOperatorKind kind, ArrayBuilder<BinaryOperatorSignature> operators)
        {
            if (builtInOperators == null)
            {
                var logicalOperators = new ImmutableArray<BinaryOperatorSignature>[]
                {
                    ImmutableArray<BinaryOperatorSignature>.Empty, //multiplication
                    ImmutableArray<BinaryOperatorSignature>.Empty, //addition
                    ImmutableArray<BinaryOperatorSignature>.Empty, //subtraction
                    ImmutableArray<BinaryOperatorSignature>.Empty, //division
                    ImmutableArray<BinaryOperatorSignature>.Empty, //remainder
                    ImmutableArray<BinaryOperatorSignature>.Empty, //left shift
                    ImmutableArray<BinaryOperatorSignature>.Empty, //right shift
                    ImmutableArray<BinaryOperatorSignature>.Empty, //equal
                    ImmutableArray<BinaryOperatorSignature>.Empty, //not equal
                    ImmutableArray<BinaryOperatorSignature>.Empty, //greater than
                    ImmutableArray<BinaryOperatorSignature>.Empty, //less than
                    ImmutableArray<BinaryOperatorSignature>.Empty, //greater than or equal
                    ImmutableArray<BinaryOperatorSignature>.Empty, //less than or equal
                    ImmutableArray.Create<BinaryOperatorSignature>(GetSignature(BinaryOperatorKind.LogicalBoolAnd)), //and
                    ImmutableArray<BinaryOperatorSignature>.Empty, //xor
                    ImmutableArray.Create<BinaryOperatorSignature>(GetSignature(BinaryOperatorKind.LogicalBoolOr)), //or
                };

                var nonLogicalOperators = new ImmutableArray<BinaryOperatorSignature>[]
                {
                    (new []
                    {
                        GetSignature(BinaryOperatorKind.IntMultiplication),
                        GetSignature(BinaryOperatorKind.UIntMultiplication),
                        GetSignature(BinaryOperatorKind.LongMultiplication),
                        GetSignature(BinaryOperatorKind.ULongMultiplication),
                        GetSignature(BinaryOperatorKind.FloatMultiplication),
                        GetSignature(BinaryOperatorKind.DoubleMultiplication),
                        GetSignature(BinaryOperatorKind.DecimalMultiplication),
                        GetSignature(BinaryOperatorKind.LiftedIntMultiplication),
                        GetSignature(BinaryOperatorKind.LiftedUIntMultiplication),
                        GetSignature(BinaryOperatorKind.LiftedLongMultiplication),
                        GetSignature(BinaryOperatorKind.LiftedULongMultiplication),
                        GetSignature(BinaryOperatorKind.LiftedFloatMultiplication),
                        GetSignature(BinaryOperatorKind.LiftedDoubleMultiplication),
                        GetSignature(BinaryOperatorKind.LiftedDecimalMultiplication),
                    }).AsImmutableOrNull(),
                    (new []
                    {
                        GetSignature(BinaryOperatorKind.IntAddition),
                        GetSignature(BinaryOperatorKind.UIntAddition),
                        GetSignature(BinaryOperatorKind.LongAddition),
                        GetSignature(BinaryOperatorKind.ULongAddition),
                        GetSignature(BinaryOperatorKind.FloatAddition),
                        GetSignature(BinaryOperatorKind.DoubleAddition),
                        GetSignature(BinaryOperatorKind.DecimalAddition),
                        GetSignature(BinaryOperatorKind.LiftedIntAddition),
                        GetSignature(BinaryOperatorKind.LiftedUIntAddition),
                        GetSignature(BinaryOperatorKind.LiftedLongAddition),
                        GetSignature(BinaryOperatorKind.LiftedULongAddition),
                        GetSignature(BinaryOperatorKind.LiftedFloatAddition),
                        GetSignature(BinaryOperatorKind.LiftedDoubleAddition),
                        GetSignature(BinaryOperatorKind.LiftedDecimalAddition),
                        GetSignature(BinaryOperatorKind.StringConcatenation),
                        GetSignature(BinaryOperatorKind.StringAndObjectConcatenation),
                        GetSignature(BinaryOperatorKind.ObjectAndStringConcatenation),
                    }).AsImmutableOrNull(),
                    (new []
                    {
                        GetSignature(BinaryOperatorKind.IntSubtraction),
                        GetSignature(BinaryOperatorKind.UIntSubtraction),
                        GetSignature(BinaryOperatorKind.LongSubtraction),
                        GetSignature(BinaryOperatorKind.ULongSubtraction),
                        GetSignature(BinaryOperatorKind.FloatSubtraction),
                        GetSignature(BinaryOperatorKind.DoubleSubtraction),
                        GetSignature(BinaryOperatorKind.DecimalSubtraction),
                        GetSignature(BinaryOperatorKind.LiftedIntSubtraction),
                        GetSignature(BinaryOperatorKind.LiftedUIntSubtraction),
                        GetSignature(BinaryOperatorKind.LiftedLongSubtraction),
                        GetSignature(BinaryOperatorKind.LiftedULongSubtraction),
                        GetSignature(BinaryOperatorKind.LiftedFloatSubtraction),
                        GetSignature(BinaryOperatorKind.LiftedDoubleSubtraction),
                        GetSignature(BinaryOperatorKind.LiftedDecimalSubtraction),
                    }).AsImmutableOrNull(),
                    (new []
                    {
                        GetSignature(BinaryOperatorKind.IntDivision),
                        GetSignature(BinaryOperatorKind.UIntDivision),
                        GetSignature(BinaryOperatorKind.LongDivision),
                        GetSignature(BinaryOperatorKind.ULongDivision),
                        GetSignature(BinaryOperatorKind.FloatDivision),
                        GetSignature(BinaryOperatorKind.DoubleDivision),
                        GetSignature(BinaryOperatorKind.DecimalDivision),
                        GetSignature(BinaryOperatorKind.LiftedIntDivision),
                        GetSignature(BinaryOperatorKind.LiftedUIntDivision),
                        GetSignature(BinaryOperatorKind.LiftedLongDivision),
                        GetSignature(BinaryOperatorKind.LiftedULongDivision),
                        GetSignature(BinaryOperatorKind.LiftedFloatDivision),
                        GetSignature(BinaryOperatorKind.LiftedDoubleDivision),
                        GetSignature(BinaryOperatorKind.LiftedDecimalDivision),
                    }).AsImmutableOrNull(),
                    (new []
                    {
                        GetSignature(BinaryOperatorKind.IntRemainder),
                        GetSignature(BinaryOperatorKind.UIntRemainder),
                        GetSignature(BinaryOperatorKind.LongRemainder),
                        GetSignature(BinaryOperatorKind.ULongRemainder),
                        GetSignature(BinaryOperatorKind.FloatRemainder),
                        GetSignature(BinaryOperatorKind.DoubleRemainder),
                        GetSignature(BinaryOperatorKind.DecimalRemainder),
                        GetSignature(BinaryOperatorKind.LiftedIntRemainder),
                        GetSignature(BinaryOperatorKind.LiftedUIntRemainder),
                        GetSignature(BinaryOperatorKind.LiftedLongRemainder),
                        GetSignature(BinaryOperatorKind.LiftedULongRemainder),
                        GetSignature(BinaryOperatorKind.LiftedFloatRemainder),
                        GetSignature(BinaryOperatorKind.LiftedDoubleRemainder),
                        GetSignature(BinaryOperatorKind.LiftedDecimalRemainder),
                    }).AsImmutableOrNull(),
                    (new []
                    {
                        GetSignature(BinaryOperatorKind.IntLeftShift),
                        GetSignature(BinaryOperatorKind.UIntLeftShift),
                        GetSignature(BinaryOperatorKind.LongLeftShift),
                        GetSignature(BinaryOperatorKind.ULongLeftShift),
                        GetSignature(BinaryOperatorKind.LiftedIntLeftShift),
                        GetSignature(BinaryOperatorKind.LiftedUIntLeftShift),
                        GetSignature(BinaryOperatorKind.LiftedLongLeftShift),
                        GetSignature(BinaryOperatorKind.LiftedULongLeftShift),
                    }).AsImmutableOrNull(),
                    (new []
                    {
                        GetSignature(BinaryOperatorKind.IntRightShift),
                        GetSignature(BinaryOperatorKind.UIntRightShift),
                        GetSignature(BinaryOperatorKind.LongRightShift),
                        GetSignature(BinaryOperatorKind.ULongRightShift),
                        GetSignature(BinaryOperatorKind.LiftedIntRightShift),
                        GetSignature(BinaryOperatorKind.LiftedUIntRightShift),
                        GetSignature(BinaryOperatorKind.LiftedLongRightShift),
                        GetSignature(BinaryOperatorKind.LiftedULongRightShift),
                    }).AsImmutableOrNull(),
                    (new []
                    {
                        GetSignature(BinaryOperatorKind.IntEqual),
                        GetSignature(BinaryOperatorKind.UIntEqual),
                        GetSignature(BinaryOperatorKind.LongEqual),
                        GetSignature(BinaryOperatorKind.ULongEqual),
                        GetSignature(BinaryOperatorKind.FloatEqual),
                        GetSignature(BinaryOperatorKind.DoubleEqual),
                        GetSignature(BinaryOperatorKind.DecimalEqual),
                        GetSignature(BinaryOperatorKind.BoolEqual),
                        GetSignature(BinaryOperatorKind.LiftedIntEqual),
                        GetSignature(BinaryOperatorKind.LiftedUIntEqual),
                        GetSignature(BinaryOperatorKind.LiftedLongEqual),
                        GetSignature(BinaryOperatorKind.LiftedULongEqual),
                        GetSignature(BinaryOperatorKind.LiftedFloatEqual),
                        GetSignature(BinaryOperatorKind.LiftedDoubleEqual),
                        GetSignature(BinaryOperatorKind.LiftedDecimalEqual),
                        GetSignature(BinaryOperatorKind.LiftedBoolEqual),
                        GetSignature(BinaryOperatorKind.ObjectEqual),
                        GetSignature(BinaryOperatorKind.StringEqual),
                    }).AsImmutableOrNull(),
                    (new []
                    {
                        GetSignature(BinaryOperatorKind.IntNotEqual),
                        GetSignature(BinaryOperatorKind.UIntNotEqual),
                        GetSignature(BinaryOperatorKind.LongNotEqual),
                        GetSignature(BinaryOperatorKind.ULongNotEqual),
                        GetSignature(BinaryOperatorKind.FloatNotEqual),
                        GetSignature(BinaryOperatorKind.DoubleNotEqual),
                        GetSignature(BinaryOperatorKind.DecimalNotEqual),
                        GetSignature(BinaryOperatorKind.BoolNotEqual),
                        GetSignature(BinaryOperatorKind.LiftedIntNotEqual),
                        GetSignature(BinaryOperatorKind.LiftedUIntNotEqual),
                        GetSignature(BinaryOperatorKind.LiftedLongNotEqual),
                        GetSignature(BinaryOperatorKind.LiftedULongNotEqual),
                        GetSignature(BinaryOperatorKind.LiftedFloatNotEqual),
                        GetSignature(BinaryOperatorKind.LiftedDoubleNotEqual),
                        GetSignature(BinaryOperatorKind.LiftedDecimalNotEqual),
                        GetSignature(BinaryOperatorKind.LiftedBoolNotEqual),
                        GetSignature(BinaryOperatorKind.ObjectNotEqual),
                        GetSignature(BinaryOperatorKind.StringNotEqual),
                    }).AsImmutableOrNull(),
                    (new []
                    {
                        GetSignature(BinaryOperatorKind.IntGreaterThan),
                        GetSignature(BinaryOperatorKind.UIntGreaterThan),
                        GetSignature(BinaryOperatorKind.LongGreaterThan),
                        GetSignature(BinaryOperatorKind.ULongGreaterThan),
                        GetSignature(BinaryOperatorKind.FloatGreaterThan),
                        GetSignature(BinaryOperatorKind.DoubleGreaterThan),
                        GetSignature(BinaryOperatorKind.DecimalGreaterThan),
                        GetSignature(BinaryOperatorKind.LiftedIntGreaterThan),
                        GetSignature(BinaryOperatorKind.LiftedUIntGreaterThan),
                        GetSignature(BinaryOperatorKind.LiftedLongGreaterThan),
                        GetSignature(BinaryOperatorKind.LiftedULongGreaterThan),
                        GetSignature(BinaryOperatorKind.LiftedFloatGreaterThan),
                        GetSignature(BinaryOperatorKind.LiftedDoubleGreaterThan),
                        GetSignature(BinaryOperatorKind.LiftedDecimalGreaterThan),
                    }).AsImmutableOrNull(),
                    (new []
                    {
                        GetSignature(BinaryOperatorKind.IntLessThan),
                        GetSignature(BinaryOperatorKind.UIntLessThan),
                        GetSignature(BinaryOperatorKind.LongLessThan),
                        GetSignature(BinaryOperatorKind.ULongLessThan),
                        GetSignature(BinaryOperatorKind.FloatLessThan),
                        GetSignature(BinaryOperatorKind.DoubleLessThan),
                        GetSignature(BinaryOperatorKind.DecimalLessThan),
                        GetSignature(BinaryOperatorKind.LiftedIntLessThan),
                        GetSignature(BinaryOperatorKind.LiftedUIntLessThan),
                        GetSignature(BinaryOperatorKind.LiftedLongLessThan),
                        GetSignature(BinaryOperatorKind.LiftedULongLessThan),
                        GetSignature(BinaryOperatorKind.LiftedFloatLessThan),
                        GetSignature(BinaryOperatorKind.LiftedDoubleLessThan),
                        GetSignature(BinaryOperatorKind.LiftedDecimalLessThan),
                    }).AsImmutableOrNull(),
                    (new []
                    {
                        GetSignature(BinaryOperatorKind.IntGreaterThanOrEqual),
                        GetSignature(BinaryOperatorKind.UIntGreaterThanOrEqual),
                        GetSignature(BinaryOperatorKind.LongGreaterThanOrEqual),
                        GetSignature(BinaryOperatorKind.ULongGreaterThanOrEqual),
                        GetSignature(BinaryOperatorKind.FloatGreaterThanOrEqual),
                        GetSignature(BinaryOperatorKind.DoubleGreaterThanOrEqual),
                        GetSignature(BinaryOperatorKind.DecimalGreaterThanOrEqual),
                        GetSignature(BinaryOperatorKind.LiftedIntGreaterThanOrEqual),
                        GetSignature(BinaryOperatorKind.LiftedUIntGreaterThanOrEqual),
                        GetSignature(BinaryOperatorKind.LiftedLongGreaterThanOrEqual),
                        GetSignature(BinaryOperatorKind.LiftedULongGreaterThanOrEqual),
                        GetSignature(BinaryOperatorKind.LiftedFloatGreaterThanOrEqual),
                        GetSignature(BinaryOperatorKind.LiftedDoubleGreaterThanOrEqual),
                        GetSignature(BinaryOperatorKind.LiftedDecimalGreaterThanOrEqual),
                    }).AsImmutableOrNull(),
                    (new []
                    {
                        GetSignature(BinaryOperatorKind.IntLessThanOrEqual),
                        GetSignature(BinaryOperatorKind.UIntLessThanOrEqual),
                        GetSignature(BinaryOperatorKind.LongLessThanOrEqual),
                        GetSignature(BinaryOperatorKind.ULongLessThanOrEqual),
                        GetSignature(BinaryOperatorKind.FloatLessThanOrEqual),
                        GetSignature(BinaryOperatorKind.DoubleLessThanOrEqual),
                        GetSignature(BinaryOperatorKind.DecimalLessThanOrEqual),
                        GetSignature(BinaryOperatorKind.LiftedIntLessThanOrEqual),
                        GetSignature(BinaryOperatorKind.LiftedUIntLessThanOrEqual),
                        GetSignature(BinaryOperatorKind.LiftedLongLessThanOrEqual),
                        GetSignature(BinaryOperatorKind.LiftedULongLessThanOrEqual),
                        GetSignature(BinaryOperatorKind.LiftedFloatLessThanOrEqual),
                        GetSignature(BinaryOperatorKind.LiftedDoubleLessThanOrEqual),
                        GetSignature(BinaryOperatorKind.LiftedDecimalLessThanOrEqual),
                    }).AsImmutableOrNull(),
                    (new []
                    {
                        GetSignature(BinaryOperatorKind.IntAnd),
                        GetSignature(BinaryOperatorKind.UIntAnd),
                        GetSignature(BinaryOperatorKind.LongAnd),
                        GetSignature(BinaryOperatorKind.ULongAnd),
                        GetSignature(BinaryOperatorKind.BoolAnd),
                        GetSignature(BinaryOperatorKind.LiftedIntAnd),
                        GetSignature(BinaryOperatorKind.LiftedUIntAnd),
                        GetSignature(BinaryOperatorKind.LiftedLongAnd),
                        GetSignature(BinaryOperatorKind.LiftedULongAnd),
                        GetSignature(BinaryOperatorKind.LiftedBoolAnd),
                    }).AsImmutableOrNull(),
                    (new []
                    {
                        GetSignature(BinaryOperatorKind.IntXor),
                        GetSignature(BinaryOperatorKind.UIntXor),
                        GetSignature(BinaryOperatorKind.LongXor),
                        GetSignature(BinaryOperatorKind.ULongXor),
                        GetSignature(BinaryOperatorKind.BoolXor),
                        GetSignature(BinaryOperatorKind.LiftedIntXor),
                        GetSignature(BinaryOperatorKind.LiftedUIntXor),
                        GetSignature(BinaryOperatorKind.LiftedLongXor),
                        GetSignature(BinaryOperatorKind.LiftedULongXor),
                        GetSignature(BinaryOperatorKind.LiftedBoolXor),
                    }).AsImmutableOrNull(),
                    (new []
                    {
                        GetSignature(BinaryOperatorKind.IntOr),
                        GetSignature(BinaryOperatorKind.UIntOr),
                        GetSignature(BinaryOperatorKind.LongOr),
                        GetSignature(BinaryOperatorKind.ULongOr),
                        GetSignature(BinaryOperatorKind.BoolOr),
                        GetSignature(BinaryOperatorKind.LiftedIntOr),
                        GetSignature(BinaryOperatorKind.LiftedUIntOr),
                        GetSignature(BinaryOperatorKind.LiftedLongOr),
                        GetSignature(BinaryOperatorKind.LiftedULongOr),
                        GetSignature(BinaryOperatorKind.LiftedBoolOr),
                    }).AsImmutableOrNull(),
                };

                var allOperators = new[] { nonLogicalOperators, logicalOperators };

                Interlocked.CompareExchange(ref builtInOperators, allOperators, null);
            }

            operators.AddRange(builtInOperators[kind.IsLogical() ? 1 : 0][kind.OperatorIndex()]);
        }
        public void UnrecognizedLocalOfTypeFromAssembly()
        {
            var source =
@"class E : System.Exception
{
}
class C
{
    static void M()
    {
        try
        {
        }
        catch (E e)
        {
        }
    }
}";
            var compilation0 = CreateCompilationWithMscorlib(source, options: TestOptions.DebugDll);
            var compilation1 = CreateCompilationWithMscorlib(source, options: TestOptions.DebugDll);
            var bytes0 = compilation0.EmitToArray();
            using (var md0 = ModuleMetadata.CreateFromImage(bytes0))
            {
                var reader0 = md0.MetadataReader;
                CheckNames(reader0, reader0.GetAssemblyRefNames(), "mscorlib");
                var method0 = compilation0.GetMember<MethodSymbol>("C.M");
                // Use empty LocalVariableNameProvider for original locals and
                // use preserveLocalVariables: true for the edit so that existing
                // locals are retained even though all are unrecognized.
                var generation0 = EmitBaseline.CreateInitialBaseline(
                    md0,
                    EmptyLocalsProvider);
                var method1 = compilation1.GetMember<MethodSymbol>("C.M");
                var diff1 = compilation1.EmitDifference(
                    generation0,
                    ImmutableArray.Create(new SemanticEdit(SemanticEditKind.Update, method0, method1, syntaxMap: s => null, preserveLocalVariables: true)));
                using (var md1 = diff1.GetMetadata())
                {
                    var reader1 = md1.Reader;
                    var readers = new[] { reader0, reader1 };
                    CheckNames(readers, reader1.GetAssemblyRefNames(), "mscorlib");
                    CheckNames(readers, reader1.GetTypeRefNames(), "Object");
                    CheckEncLog(reader1,
                        Row(2, TableIndex.AssemblyRef, EditAndContinueOperation.Default),
                        Row(7, TableIndex.TypeRef, EditAndContinueOperation.Default),
                        Row(2, TableIndex.StandAloneSig, EditAndContinueOperation.Default),
                        Row(2, TableIndex.MethodDef, EditAndContinueOperation.Default));
                    CheckEncMap(reader1,
                        Handle(7, TableIndex.TypeRef),
                        Handle(2, TableIndex.MethodDef),
                        Handle(2, TableIndex.StandAloneSig),
                        Handle(2, TableIndex.AssemblyRef));
                }
            }
        }
        public void OtherReferences()
        {
            var source0 =
@"delegate void D();
class C
{
    object F;
    object P { get { return null; } }
    event D E;
    void M()
    {
    }
}";
            var source1 =
@"delegate void D();
class C
{
    object F;
    object P { get { return null; } }
    event D E;
    void M()
    {
        object o;
        o = typeof(D);
        o = F;
        o = P;
        E += null;
    }
}";
            var compilation0 = CreateCompilationWithMscorlib(source0, options: TestOptions.DebugDll);
            var compilation1 = CreateCompilationWithMscorlib(source1, options: TestOptions.DebugDll);

            // Verify full metadata contains expected rows.
            var bytes0 = compilation0.EmitToArray();
            using (var md0 = ModuleMetadata.CreateFromImage(bytes0))
            {
                var reader0 = md0.MetadataReader;
                CheckNames(reader0, reader0.GetTypeDefNames(), "<Module>", "D", "C");
                CheckNames(reader0, reader0.GetEventDefNames(), "E");
                CheckNames(reader0, reader0.GetFieldDefNames(), "F", "E");
                CheckNames(reader0, reader0.GetMethodDefNames(), ".ctor", "BeginInvoke", "EndInvoke", "Invoke", "get_P", "add_E", "remove_E", "M", ".ctor");
                CheckNames(reader0, reader0.GetPropertyDefNames(), "P");

                var method0 = compilation0.GetMember<MethodSymbol>("C.M");

                // Emit delta metadata.
                var generation0 = EmitBaseline.CreateInitialBaseline(md0, EmptyLocalsProvider);
                var method1 = compilation1.GetMember<MethodSymbol>("C.M");

                var diff1 = compilation1.EmitDifference(
                    generation0,
                    ImmutableArray.Create(new SemanticEdit(SemanticEditKind.Update, method0, method1, GetEquivalentNodesMap(method1, method0), preserveLocalVariables: true)));

                // Verify delta metadata contains expected rows.
                using (var md1 = diff1.GetMetadata())
                {
                    var reader1 = md1.Reader;
                    var readers = new[] { reader0, reader1 };
                    CheckNames(readers, reader1.GetTypeDefNames());
                    CheckNames(readers, reader1.GetEventDefNames());
                    CheckNames(readers, reader1.GetFieldDefNames());
                    CheckNames(readers, reader1.GetMethodDefNames(), "M");
                    CheckNames(readers, reader1.GetPropertyDefNames());
                }
            }
        }
Esempio n. 23
0
        public void ImportScopeEquality()
        {
            var sources = new[] { @"
extern alias A;
using System;
using C = System;

namespace N.M 
{
   using System.Collections;

   class C1 { void F() {} }
}

namespace N.M 
{
   using System.Collections;

   class C2 { void F() {} }
}
", @"
extern alias A;
using System;
using C = System;

namespace N.M 
{
   using System.Collections;

   class C3 { void F() {} }
}

namespace N.M 
{
   using System.Collections.Generic;

   class C4 { void F() {} }
}
", @"
extern alias A;
using System;
using D = System;

namespace N.M 
{
   using System.Collections;

   class C5 { void F() {} }
}
", @"
extern alias A;
using System;

class C6 { void F() {} }
" };

            var c = CreateCompilationWithMscorlib(sources, new[] { SystemCoreRef.WithAliases(ImmutableArray.Create("A")) });
            var pdbStream = new MemoryStream();
            c.EmitToArray(EmitOptions.Default.WithDebugInformationFormat(DebugInformationFormat.PortablePdb), pdbStream: pdbStream);
            var pdbImage = pdbStream.ToImmutable();
            using (var metadata = new PinnedMetadata(pdbImage))
            {
                var mdReader = metadata.Reader;
                var writer = new StringWriter();
                var mdVisualizer = new MetadataVisualizer(mdReader, writer);
                mdVisualizer.WriteImportScope();

                AssertEx.AssertEqualToleratingWhitespaceDifferences(@"
ImportScope (index: 0x35, size: 36): 
=============================================================================================
   Parent                    Imports                                                          
=============================================================================================
1: nil (ImportScope)         'A' (#1) = 0x23000002 (AssemblyRef)                              
2: 0x35000001 (ImportScope)  Extern Alias 'A' (#1), 'System' (#7)                             
3: 0x35000001 (ImportScope)  Extern Alias 'A' (#1), 'System' (#7), 'C' (#1d) = 'System' (#7)  
4: 0x35000003 (ImportScope)  nil                                                              
5: 0x35000004 (ImportScope)  'System.Collections' (#27)                                       
6: 0x35000004 (ImportScope)  'System.Collections.Generic' (#4b)                               
7: 0x35000001 (ImportScope)  Extern Alias 'A' (#1), 'System' (#7), 'D' (#69) = 'System' (#7)  
8: 0x35000007 (ImportScope)  nil                                                              
9: 0x35000008 (ImportScope)  'System.Collections' (#27)    
", writer.ToString());
            }
        }
        public void UnrecognizedLocalOfAnonymousTypeFromAssembly()
        {
            var source0 =
@"class C
{
    static string F()
    {
        return null;
    }
    static string G()
    {
        var o = new { Y = 1 };
        return o.ToString();
    }
}";
            var source1 =
@"class C
{
    static string F()
    {
        var o = new { X = 1 };
        return o.ToString();
    }
    static string G()
    {
        var o = new { Y = 1 };
        return o.ToString();
    }
}";
            var source2 =
@"class C
{
    static string F()
    {
        return null;
    }
    static string G()
    {
        return null;
    }
}";
            var compilation0 = CreateCompilationWithMscorlib(source0, options: TestOptions.DebugDll);
            var compilation1 = CreateCompilationWithMscorlib(source1, options: TestOptions.DebugDll);
            var compilation2 = CreateCompilationWithMscorlib(source2, options: TestOptions.DebugDll);
            var bytes0 = compilation0.EmitToArray();
            using (var md0 = ModuleMetadata.CreateFromImage(bytes0))
            {
                var reader0 = md0.MetadataReader;
                CheckNames(reader0, reader0.GetAssemblyRefNames(), "mscorlib");
                var method0F = compilation0.GetMember<MethodSymbol>("C.F");
                // Use empty LocalVariableNameProvider for original locals and
                // use preserveLocalVariables: true for the edit so that existing
                // locals are retained even though all are unrecognized.
                var generation0 = EmitBaseline.CreateInitialBaseline(
                    md0,
                    EmptyLocalsProvider);
                var method1F = compilation1.GetMember<MethodSymbol>("C.F");
                var method1G = compilation1.GetMember<MethodSymbol>("C.G");
                var diff1 = compilation1.EmitDifference(
                    generation0,
                    ImmutableArray.Create(new SemanticEdit(SemanticEditKind.Update, method0F, method1F, syntaxMap: s => null, preserveLocalVariables: true)));
                using (var md1 = diff1.GetMetadata())
                {
                    var reader1 = md1.Reader;
                    var readers = new[] { reader0, reader1 };
                    CheckNames(readers, reader1.GetAssemblyRefNames(), "mscorlib");
                    CheckNames(readers, reader1.GetTypeDefNames(), "<>f__AnonymousType1`1");
                    CheckNames(readers, reader1.GetTypeRefNames(), "CompilerGeneratedAttribute", "DebuggerDisplayAttribute", "Object", "DebuggerBrowsableState", "DebuggerBrowsableAttribute", "DebuggerHiddenAttribute", "EqualityComparer`1", "String");
                    // Change method updated in generation 1.
                    var method2F = compilation2.GetMember<MethodSymbol>("C.F");
                    var diff2F = compilation2.EmitDifference(
                        diff1.NextGeneration,
                        ImmutableArray.Create(new SemanticEdit(SemanticEditKind.Update, method1F, method2F, syntaxMap: s => null, preserveLocalVariables: true)));
                    using (var md2 = diff2F.GetMetadata())
                    {
                        var reader2 = md2.Reader;
                        readers = new[] { reader0, reader1, reader2 };
                        CheckNames(readers, reader2.GetAssemblyRefNames(), "mscorlib");
                        CheckNames(readers, reader2.GetTypeDefNames());
                        CheckNames(readers, reader2.GetTypeRefNames(), "Object");
                    }
                    // Change method unchanged since generation 0.
                    var method2G = compilation2.GetMember<MethodSymbol>("C.G");
                    var diff2G = compilation2.EmitDifference(
                        diff1.NextGeneration,
                        ImmutableArray.Create(new SemanticEdit(SemanticEditKind.Update, method1G, method2G, syntaxMap: s => null, preserveLocalVariables: true)));
                    using (var md2 = diff2G.GetMetadata())
                    {
                        var reader2 = md2.Reader;
                        readers = new[] { reader0, reader1, reader2 };
                        CheckNames(readers, reader2.GetAssemblyRefNames(), "mscorlib");
                        CheckNames(readers, reader2.GetTypeDefNames());
                        CheckNames(readers, reader2.GetTypeRefNames(), "Object");
                    }
                }
            }
        }
        public void ModifyMethod()
        {
            var source0 =
@"class C
{
    static void Main() { }
    static string F() { return null; }
}";
            var source1 =
@"class C
{
    static void Main() { }
    static string F() { return string.Empty; }
}";
            var compilation0 = CreateCompilationWithMscorlib(source0, options: TestOptions.DebugExe);
            var compilation1 = CreateCompilationWithMscorlib(source1, options: TestOptions.DebugExe);

            // Verify full metadata contains expected rows.
            var bytes0 = compilation0.EmitToArray();
            using (var md0 = ModuleMetadata.CreateFromImage(bytes0))
            {
                var reader0 = md0.MetadataReader;
                CheckNames(reader0, reader0.GetTypeDefNames(), "<Module>", "C");
                CheckNames(reader0, reader0.GetMethodDefNames(), "Main", "F", ".ctor");
                CheckNames(reader0, reader0.GetMemberRefNames(), /*CompilationRelaxationsAttribute.*/".ctor", /*RuntimeCompatibilityAttribute.*/".ctor", /*Object.*/".ctor", /*DebuggableAttribute*/".ctor");

                var method0 = compilation0.GetMember<MethodSymbol>("C.F");
                var generation0 = EmitBaseline.CreateInitialBaseline(
                    md0,
                    EmptyLocalsProvider);
                var method1 = compilation1.GetMember<MethodSymbol>("C.F");

                var diff1 = compilation1.EmitDifference(
                    generation0,
                    ImmutableArray.Create(new SemanticEdit(SemanticEditKind.Update, method0, method1)));

                // Verify delta metadata contains expected rows.
                using (var md1 = diff1.GetMetadata())
                {
                    var reader1 = md1.Reader;
                    var readers = new[] { reader0, reader1 };
                    EncValidation.VerifyModuleMvid(1, reader0, reader1);
                    CheckNames(readers, reader1.GetTypeDefNames());
                    CheckNames(readers, reader1.GetMethodDefNames(), "F");
                    CheckNames(readers, reader1.GetMemberRefNames(), /*String.*/"Empty");
                    CheckEncLog(reader1,
                        Row(2, TableIndex.AssemblyRef, EditAndContinueOperation.Default),
                        Row(5, TableIndex.MemberRef, EditAndContinueOperation.Default),
                        Row(6, TableIndex.TypeRef, EditAndContinueOperation.Default),
                        Row(7, TableIndex.TypeRef, EditAndContinueOperation.Default),
                        Row(2, TableIndex.StandAloneSig, EditAndContinueOperation.Default),
                        Row(2, TableIndex.MethodDef, EditAndContinueOperation.Default)); // C.F
                    CheckEncMap(reader1,
                        Handle(6, TableIndex.TypeRef),
                        Handle(7, TableIndex.TypeRef),
                        Handle(2, TableIndex.MethodDef),
                        Handle(5, TableIndex.MemberRef),
                        Handle(2, TableIndex.StandAloneSig),
                        Handle(2, TableIndex.AssemblyRef));
                }
            }
        }
        public void AddNestedTypesOrder()
        {
            var source0 =
@"class A
{
    class B1
    {
        class C1 { }
    }
    class B2
    {
        class C2 { }
    }
}";
            var source1 =
@"class A
{
    class B1
    {
        class C1 { }
    }
    class B2
    {
        class C2 { }
    }
    class B3
    {
        class C3 { }
    }
    class B4
    {
        class C4 { }
    }
}";
            var compilation0 = CreateCompilationWithMscorlib(source0, options: TestOptions.DebugDll);
            var compilation1 = CreateCompilationWithMscorlib(source1, options: TestOptions.DebugDll);

            var bytes0 = compilation0.EmitToArray();
            using (var md0 = ModuleMetadata.CreateFromImage(bytes0))
            {
                var reader0 = md0.MetadataReader;
                CheckNames(reader0, reader0.GetTypeDefNames(), "<Module>", "A", "B1", "B2", "C1", "C2");
                Assert.Equal(4, reader0.GetTableRowCount(TableIndex.NestedClass));

                var generation0 = EmitBaseline.CreateInitialBaseline(md0, EmptyLocalsProvider);
                var diff1 = compilation1.EmitDifference(
                    generation0,
                    ImmutableArray.Create(
                        new SemanticEdit(SemanticEditKind.Insert, null, compilation1.GetMember<NamedTypeSymbol>("A.B3")),
                        new SemanticEdit(SemanticEditKind.Insert, null, compilation1.GetMember<NamedTypeSymbol>("A.B4"))));

                using (var md1 = diff1.GetMetadata())
                {
                    var reader1 = md1.Reader;
                    var readers = new[] { reader0, reader1 };
                    CheckNames(readers, reader1.GetTypeDefNames(), "B3", "B4", "C3", "C4");
                    Assert.Equal(4, reader1.GetTableRowCount(TableIndex.NestedClass));
                }
            }
        }
        public void OverriddenPropertyAccessibility6()
        {
            var source1 = @"
[assembly:System.Runtime.CompilerServices.InternalsVisibleTo(""B"")]
public class A
{
	public virtual int P { get; protected set; }
}
";
            var source2 = @"
public class B : A
{
	public override int P { protected set { } }
}
";
            var source3 = @"
public class C : B
{
	public override int P { get { return 0; } }
}
";

            var comp1 = CreateCompilationWithMscorlib(source1, assemblyName: "A.dll");
            var ref1 = comp1.EmitToImageReference();

            var comp2 = CreateCompilationWithMscorlib(source2, new[] { ref1 }, assemblyName: "B.dll");
            var ref2 = comp2.EmitToImageReference();

            var comp3 = CreateCompilationWithMscorlib(source3, new[] { ref1, ref2 }, assemblyName: "C.dll");
            comp3.VerifyDiagnostics();

            var properties = new[]
            {
                comp1.GlobalNamespace.GetMember<NamedTypeSymbol>("A").GetMember<PropertySymbol>("P"),

                comp2.GlobalNamespace.GetMember<NamedTypeSymbol>("A").GetMember<PropertySymbol>("P"),
                comp2.GlobalNamespace.GetMember<NamedTypeSymbol>("B").GetMember<PropertySymbol>("P"),

                comp3.GlobalNamespace.GetMember<NamedTypeSymbol>("A").GetMember<PropertySymbol>("P"),
                comp3.GlobalNamespace.GetMember<NamedTypeSymbol>("B").GetMember<PropertySymbol>("P"),
                comp3.GlobalNamespace.GetMember<NamedTypeSymbol>("C").GetMember<PropertySymbol>("P"),
            };

            AssertEx.All(properties, p => p.DeclaredAccessibility == Accessibility.Public);
        }
        public void AddNestedGenericType()
        {
            var source0 =
@"class A
{
    class B<T>
    {
    }
    static object F()
    {
        return null;
    }
}";
            var source1 =
@"class A
{
    class B<T>
    {
        internal class C<U>
        {
            internal object F<V>() where V : T, new()
            {
                return new C<V>();
            }
        }
    }
    static object F()
    {
        return new B<A>.C<B<object>>().F<A>();
    }
}";
            var compilation0 = CreateCompilationWithMscorlib(source0, options: TestOptions.DebugDll);
            var compilation1 = CreateCompilationWithMscorlib(source1, options: TestOptions.DebugDll);

            // Verify full metadata contains expected rows.
            var bytes0 = compilation0.EmitToArray();
            using (var md0 = ModuleMetadata.CreateFromImage(bytes0))
            {
                var reader0 = md0.MetadataReader;
                CheckNames(reader0, reader0.GetTypeDefNames(), "<Module>", "A", "B`1");
                Assert.Equal(1, reader0.GetTableRowCount(TableIndex.NestedClass));

                var generation0 = EmitBaseline.CreateInitialBaseline(md0, EmptyLocalsProvider);

                var diff1 = compilation1.EmitDifference(
                    generation0,
                    ImmutableArray.Create(
                        new SemanticEdit(SemanticEditKind.Insert, null, compilation1.GetMember<NamedTypeSymbol>("A.B.C")),
                        new SemanticEdit(SemanticEditKind.Update, compilation0.GetMember<MethodSymbol>("A.F"), compilation1.GetMember<MethodSymbol>("A.F"))));

                // Verify delta metadata contains expected rows.
                using (var md1 = diff1.GetMetadata())
                {
                    var reader1 = md1.Reader;
                    var readers = new[] { reader0, reader1 };
                    CheckNames(readers, reader1.GetTypeDefNames(), "C`1");
                    Assert.Equal(1, reader1.GetTableRowCount(TableIndex.NestedClass));
                    CheckEncLog(reader1,
                        Row(2, TableIndex.AssemblyRef, EditAndContinueOperation.Default),
                        Row(5, TableIndex.MemberRef, EditAndContinueOperation.Default),
                        Row(6, TableIndex.MemberRef, EditAndContinueOperation.Default),
                        Row(7, TableIndex.MemberRef, EditAndContinueOperation.Default),
                        Row(8, TableIndex.MemberRef, EditAndContinueOperation.Default),
                        Row(1, TableIndex.MethodSpec, EditAndContinueOperation.Default),
                        Row(6, TableIndex.TypeRef, EditAndContinueOperation.Default),
                        Row(1, TableIndex.TypeSpec, EditAndContinueOperation.Default),
                        Row(2, TableIndex.TypeSpec, EditAndContinueOperation.Default),
                        Row(3, TableIndex.TypeSpec, EditAndContinueOperation.Default),
                        Row(2, TableIndex.StandAloneSig, EditAndContinueOperation.Default),
                        Row(4, TableIndex.TypeDef, EditAndContinueOperation.Default),
                        Row(1, TableIndex.MethodDef, EditAndContinueOperation.Default),
                        Row(4, TableIndex.TypeDef, EditAndContinueOperation.AddMethod),
                        Row(4, TableIndex.MethodDef, EditAndContinueOperation.Default),
                        Row(4, TableIndex.TypeDef, EditAndContinueOperation.AddMethod),
                        Row(5, TableIndex.MethodDef, EditAndContinueOperation.Default),
                        Row(2, TableIndex.NestedClass, EditAndContinueOperation.Default),
                        Row(2, TableIndex.GenericParam, EditAndContinueOperation.Default),
                        Row(3, TableIndex.GenericParam, EditAndContinueOperation.Default),
                        Row(4, TableIndex.GenericParam, EditAndContinueOperation.Default),
                        Row(1, TableIndex.GenericParamConstraint, EditAndContinueOperation.Default));
                    CheckEncMap(reader1,
                        Handle(6, TableIndex.TypeRef),
                        Handle(4, TableIndex.TypeDef),
                        Handle(1, TableIndex.MethodDef),
                        Handle(4, TableIndex.MethodDef),
                        Handle(5, TableIndex.MethodDef),
                        Handle(5, TableIndex.MemberRef),
                        Handle(6, TableIndex.MemberRef),
                        Handle(7, TableIndex.MemberRef),
                        Handle(8, TableIndex.MemberRef),
                        Handle(2, TableIndex.StandAloneSig),
                        Handle(1, TableIndex.TypeSpec),
                        Handle(2, TableIndex.TypeSpec),
                        Handle(3, TableIndex.TypeSpec),
                        Handle(2, TableIndex.AssemblyRef),
                        Handle(2, TableIndex.NestedClass),
                        Handle(2, TableIndex.GenericParam),
                        Handle(3, TableIndex.GenericParam),
                        Handle(4, TableIndex.GenericParam),
                        Handle(1, TableIndex.MethodSpec),
                        Handle(1, TableIndex.GenericParamConstraint));
                }
            }
        }
        public void OverriddenEventAccessibility()
        {
            var source1 = @"
public class A
{
	protected internal virtual event System.Action E;

    void UseEvent() { E(); }
}
";
            var source2 = @"
[assembly:System.Runtime.CompilerServices.InternalsVisibleTo(""C"")]
public class B : A
{
	protected override event System.Action E;

    void UseEvent() { E(); }
}
";
            var source3 = @"
public class C : B
{
	protected override event System.Action E;

    void UseEvent() { E(); }
}
";

            var comp1 = CreateCompilationWithMscorlib(source1, assemblyName: "A.dll");
            var ref1 = comp1.EmitToImageReference();

            var comp2 = CreateCompilationWithMscorlib(source2, new[] { ref1 }, assemblyName: "B.dll");
            var ref2 = comp2.EmitToImageReference();

            var comp3 = CreateCompilationWithMscorlib(source3, new[] { ref1, ref2 }, assemblyName: "C.dll");
            comp3.VerifyDiagnostics();

            var events = new[]
            {
                comp1.GlobalNamespace.GetMember<NamedTypeSymbol>("A").GetMember<EventSymbol>("E"),
                                                                                                 
                comp2.GlobalNamespace.GetMember<NamedTypeSymbol>("A").GetMember<EventSymbol>("E"),
                comp2.GlobalNamespace.GetMember<NamedTypeSymbol>("B").GetMember<EventSymbol>("E"),
                                                                                                 
                comp3.GlobalNamespace.GetMember<NamedTypeSymbol>("A").GetMember<EventSymbol>("E"),
                comp3.GlobalNamespace.GetMember<NamedTypeSymbol>("B").GetMember<EventSymbol>("E"),
                comp3.GlobalNamespace.GetMember<NamedTypeSymbol>("C").GetMember<EventSymbol>("E"),
            };

            AssertEx.All(events, e =>
                e.DeclaredAccessibility == (e.ContainingType.Name == "A" ? Accessibility.ProtectedOrInternal : Accessibility.Protected));
        }
        public void AddAttributeReferences()
        {
            var source0 =
@"class A : System.Attribute { }
class B : System.Attribute { }
class C
{
    [A] static void M1<[B]T>() { }
    [B] static object F1;
    [A] static object P1 { get { return null; } }
    [B] static event D E1;
}
delegate void D();
";
            var source1 =
@"class A : System.Attribute { }
class B : System.Attribute { }
class C
{
    [A] static void M1<[B]T>() { }
    [B] static void M2<[A]T>() { }
    [B] static object F1;
    [A] static object F2;
    [A] static object P1 { get { return null; } }
    [B] static object P2 { get { return null; } }
    [B] static event D E1;
    [A] static event D E2;
}
delegate void D();
";
            var compilation0 = CreateCompilationWithMscorlib(source0, options: TestOptions.DebugDll);
            var compilation1 = CreateCompilationWithMscorlib(source1, options: TestOptions.DebugDll);

            // Verify full metadata contains expected rows.
            var bytes0 = compilation0.EmitToArray();
            using (var md0 = ModuleMetadata.CreateFromImage(bytes0))
            {
                var reader0 = md0.MetadataReader;
                CheckNames(reader0, reader0.GetTypeDefNames(), "<Module>", "A", "B", "C", "D");
                CheckNames(reader0, reader0.GetMethodDefNames(), ".ctor", ".ctor", "M1", "get_P1", "add_E1", "remove_E1", ".ctor", ".ctor", "BeginInvoke", "EndInvoke", "Invoke");
                CheckAttributes(reader0,
                    new CustomAttributeRow(Handle(1, TableIndex.Field), Handle(2, TableIndex.MethodDef)),
                    new CustomAttributeRow(Handle(1, TableIndex.Property), Handle(1, TableIndex.MethodDef)),
                    new CustomAttributeRow(Handle(1, TableIndex.Event), Handle(2, TableIndex.MethodDef)),
                    new CustomAttributeRow(Handle(1, TableIndex.Assembly), Handle(1, TableIndex.MemberRef)),
                    new CustomAttributeRow(Handle(1, TableIndex.Assembly), Handle(2, TableIndex.MemberRef)),
                    new CustomAttributeRow(Handle(1, TableIndex.Assembly), Handle(3, TableIndex.MemberRef)),
                    new CustomAttributeRow(Handle(1, TableIndex.GenericParam), Handle(2, TableIndex.MethodDef)),
                    new CustomAttributeRow(Handle(2, TableIndex.Field), Handle(4, TableIndex.MemberRef)),
                    new CustomAttributeRow(Handle(2, TableIndex.Field), Handle(5, TableIndex.MemberRef)),
                    new CustomAttributeRow(Handle(3, TableIndex.MethodDef), Handle(1, TableIndex.MethodDef)),
                    new CustomAttributeRow(Handle(5, TableIndex.MethodDef), Handle(4, TableIndex.MemberRef)),
                    new CustomAttributeRow(Handle(6, TableIndex.MethodDef), Handle(4, TableIndex.MemberRef)));

                var generation0 = EmitBaseline.CreateInitialBaseline(md0, EmptyLocalsProvider);

                var diff1 = compilation1.EmitDifference(
                    generation0,
                    ImmutableArray.Create(
                        new SemanticEdit(SemanticEditKind.Insert, null, compilation1.GetMember<MethodSymbol>("C.M2")),
                        new SemanticEdit(SemanticEditKind.Insert, null, compilation1.GetMember<FieldSymbol>("C.F2")),
                        new SemanticEdit(SemanticEditKind.Insert, null, compilation1.GetMember<PropertySymbol>("C.P2")),
                        new SemanticEdit(SemanticEditKind.Insert, null, compilation1.GetMember<EventSymbol>("C.E2"))));

                // Verify delta metadata contains expected rows.
                using (var md1 = diff1.GetMetadata())
                {
                    var reader1 = md1.Reader;
                    var readers = new[] { reader0, reader1 };
                    CheckNames(readers, reader1.GetTypeDefNames());
                    CheckNames(readers, reader1.GetMethodDefNames(), "M2", "get_P2", "add_E2", "remove_E2");
                    CheckEncLog(reader1,
                        Row(2, TableIndex.AssemblyRef, EditAndContinueOperation.Default),
                        Row(11, TableIndex.MemberRef, EditAndContinueOperation.Default),
                        Row(12, TableIndex.MemberRef, EditAndContinueOperation.Default),
                        Row(13, TableIndex.MemberRef, EditAndContinueOperation.Default),
                        Row(14, TableIndex.MemberRef, EditAndContinueOperation.Default),
                        Row(15, TableIndex.MemberRef, EditAndContinueOperation.Default),
                        Row(2, TableIndex.MethodSpec, EditAndContinueOperation.Default),
                        Row(15, TableIndex.TypeRef, EditAndContinueOperation.Default),
                        Row(16, TableIndex.TypeRef, EditAndContinueOperation.Default),
                        Row(17, TableIndex.TypeRef, EditAndContinueOperation.Default),
                        Row(18, TableIndex.TypeRef, EditAndContinueOperation.Default),
                        Row(19, TableIndex.TypeRef, EditAndContinueOperation.Default),
                        Row(20, TableIndex.TypeRef, EditAndContinueOperation.Default),
                        Row(3, TableIndex.StandAloneSig, EditAndContinueOperation.Default),
                        Row(4, TableIndex.StandAloneSig, EditAndContinueOperation.Default),
                        Row(1, TableIndex.EventMap, EditAndContinueOperation.AddEvent),
                        Row(2, TableIndex.Event, EditAndContinueOperation.Default),
                        Row(4, TableIndex.TypeDef, EditAndContinueOperation.AddField),
                        Row(3, TableIndex.Field, EditAndContinueOperation.Default),
                        Row(4, TableIndex.TypeDef, EditAndContinueOperation.AddField),
                        Row(4, TableIndex.Field, EditAndContinueOperation.Default),
                        Row(4, TableIndex.TypeDef, EditAndContinueOperation.AddMethod),
                        Row(12, TableIndex.MethodDef, EditAndContinueOperation.Default),
                        Row(4, TableIndex.TypeDef, EditAndContinueOperation.AddMethod),
                        Row(13, TableIndex.MethodDef, EditAndContinueOperation.Default),
                        Row(4, TableIndex.TypeDef, EditAndContinueOperation.AddMethod),
                        Row(14, TableIndex.MethodDef, EditAndContinueOperation.Default),
                        Row(4, TableIndex.TypeDef, EditAndContinueOperation.AddMethod),
                        Row(15, TableIndex.MethodDef, EditAndContinueOperation.Default),
                        Row(1, TableIndex.PropertyMap, EditAndContinueOperation.AddProperty),
                        Row(2, TableIndex.Property, EditAndContinueOperation.Default),
                        Row(14, TableIndex.MethodDef, EditAndContinueOperation.AddParameter),
                        Row(8, TableIndex.Param, EditAndContinueOperation.Default),
                        Row(15, TableIndex.MethodDef, EditAndContinueOperation.AddParameter),
                        Row(9, TableIndex.Param, EditAndContinueOperation.Default),
                        Row(13, TableIndex.CustomAttribute, EditAndContinueOperation.Default),
                        Row(14, TableIndex.CustomAttribute, EditAndContinueOperation.Default),
                        Row(15, TableIndex.CustomAttribute, EditAndContinueOperation.Default),
                        Row(16, TableIndex.CustomAttribute, EditAndContinueOperation.Default),
                        Row(17, TableIndex.CustomAttribute, EditAndContinueOperation.Default),
                        Row(18, TableIndex.CustomAttribute, EditAndContinueOperation.Default),
                        Row(19, TableIndex.CustomAttribute, EditAndContinueOperation.Default),
                        Row(20, TableIndex.CustomAttribute, EditAndContinueOperation.Default),
                        Row(21, TableIndex.CustomAttribute, EditAndContinueOperation.Default),
                        Row(4, TableIndex.MethodSemantics, EditAndContinueOperation.Default),
                        Row(5, TableIndex.MethodSemantics, EditAndContinueOperation.Default),
                        Row(6, TableIndex.MethodSemantics, EditAndContinueOperation.Default),
                        Row(2, TableIndex.GenericParam, EditAndContinueOperation.Default));
                    CheckEncMap(reader1,
                        Handle(15, TableIndex.TypeRef),
                        Handle(16, TableIndex.TypeRef),
                        Handle(17, TableIndex.TypeRef),
                        Handle(18, TableIndex.TypeRef),
                        Handle(19, TableIndex.TypeRef),
                        Handle(20, TableIndex.TypeRef),
                        Handle(3, TableIndex.Field),
                        Handle(4, TableIndex.Field),
                        Handle(12, TableIndex.MethodDef),
                        Handle(13, TableIndex.MethodDef),
                        Handle(14, TableIndex.MethodDef),
                        Handle(15, TableIndex.MethodDef),
                        Handle(8, TableIndex.Param),
                        Handle(9, TableIndex.Param),
                        Handle(11, TableIndex.MemberRef),
                        Handle(12, TableIndex.MemberRef),
                        Handle(13, TableIndex.MemberRef),
                        Handle(14, TableIndex.MemberRef),
                        Handle(15, TableIndex.MemberRef),
                        Handle(13, TableIndex.CustomAttribute),
                        Handle(14, TableIndex.CustomAttribute),
                        Handle(15, TableIndex.CustomAttribute),
                        Handle(16, TableIndex.CustomAttribute),
                        Handle(17, TableIndex.CustomAttribute),
                        Handle(18, TableIndex.CustomAttribute),
                        Handle(19, TableIndex.CustomAttribute),
                        Handle(20, TableIndex.CustomAttribute),
                        Handle(21, TableIndex.CustomAttribute),
                        Handle(3, TableIndex.StandAloneSig),
                        Handle(4, TableIndex.StandAloneSig),
                        Handle(2, TableIndex.Event),
                        Handle(2, TableIndex.Property),
                        Handle(4, TableIndex.MethodSemantics),
                        Handle(5, TableIndex.MethodSemantics),
                        Handle(6, TableIndex.MethodSemantics),
                        Handle(2, TableIndex.AssemblyRef),
                        Handle(2, TableIndex.GenericParam),
                        Handle(2, TableIndex.MethodSpec));
                    CheckAttributes(reader1,
                        new CustomAttributeRow(Handle(2, TableIndex.Property), Handle(2, TableIndex.MethodDef)),
                        new CustomAttributeRow(Handle(2, TableIndex.Event), Handle(1, TableIndex.MethodDef)),
                        new CustomAttributeRow(Handle(2, TableIndex.GenericParam), Handle(1, TableIndex.MethodDef)),
                        new CustomAttributeRow(Handle(3, TableIndex.Field), Handle(1, TableIndex.MethodDef)),
                        new CustomAttributeRow(Handle(4, TableIndex.Field), Handle(11, TableIndex.MemberRef)),
                        new CustomAttributeRow(Handle(4, TableIndex.Field), Handle(12, TableIndex.MemberRef)),
                        new CustomAttributeRow(Handle(12, TableIndex.MethodDef), Handle(2, TableIndex.MethodDef)),
                        new CustomAttributeRow(Handle(14, TableIndex.MethodDef), Handle(11, TableIndex.MemberRef)),
                        new CustomAttributeRow(Handle(15, TableIndex.MethodDef), Handle(11, TableIndex.MemberRef)));
                }
            }
        }