当前位置: 首页>>代码示例>>C#>>正文


C# Collections.Immutable类代码示例

本文整理汇总了C#中System.Collections.Immutable的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Immutable类的具体用法?C# System.Collections.Immutable怎么用?C# System.Collections.Immutable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


System.Collections.Immutable类属于命名空间,在下文中一共展示了System.Collections.Immutable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TagCloud_functional_test

        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);
        }
开发者ID:xackill,项目名称:03-design-hw,代码行数:28,代码来源:TagCloud_Test.cs

示例2: Basic

		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 );
		}
开发者ID:DevelopersWin,项目名称:VoteReporter,代码行数:10,代码来源:ImmutableArrayTests.cs

示例3: PartialMethod

        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));
                }
            }
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:50,代码来源:EditAndContinueTests.cs

示例4: AddThenModifyMethod

        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));
                    }
                }
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:101,代码来源:EditAndContinueTests.cs

示例5: AssemblyAndModuleAttributeReferences

        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));
                }
            }
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:51,代码来源:EditAndContinueTests.cs

示例6: NoPIAReferences

        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
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:101,代码来源:EditAndContinueTests.cs

示例7: AddEvent

        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),
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:101,代码来源:EditAndContinueTests.cs

示例8: AddProperty

        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),
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:101,代码来源:EditAndContinueTests.cs

示例9: PrivateImplementationDetails_ComputeStringHash

        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");
                }
            }
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:58,代码来源:EditAndContinueTests.cs

示例10: AddField

        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));
                }
            }
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:59,代码来源:EditAndContinueTests.cs

示例11: PrivateImplementationDetails

        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
}");
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:54,代码来源:EditAndContinueTests.cs

示例12: IsIndexOfCall

        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);
        }
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:19,代码来源:IndexOfCheckAgainstZero.cs

示例13: GetSimpleBuiltInOperators

        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),
//.........这里部分代码省略.........
开发者ID:riversky,项目名称:roslyn,代码行数:101,代码来源:BuiltInOperators.cs

示例14: IsTestMethod

        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()));
        }
开发者ID:nemec,项目名称:VSDiagnostics,代码行数:12,代码来源:TestMethodWithoutPublicModifierAnalyzer.cs

示例15: AnalyzeDateTimeUsage

        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);
        }
开发者ID:vuder,项目名称:CodingStandardCodeAnalyzers,代码行数:14,代码来源:DateTimeClassUsageCodeAnalyzer.cs


注:本文中的System.Collections.Immutable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。