• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Symbols.ArrayTypeSymbol类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: TestArrayType

        public void TestArrayType()
        {
            CSharpCompilation compilation = CSharpCompilation.Create("Test");

            NamedTypeSymbol elementType = new MockNamedTypeSymbol("TestClass", Enumerable.Empty<Symbol>());   // this can be any type.

            ArrayTypeSymbol ats1 = new ArrayTypeSymbol(compilation.Assembly, elementType, rank: 1);
            Assert.Equal(1, ats1.Rank);
            Assert.Same(elementType, ats1.ElementType);
            Assert.Equal(SymbolKind.ArrayType, ats1.Kind);
            Assert.True(ats1.IsReferenceType);
            Assert.False(ats1.IsValueType);
            Assert.Equal("TestClass[]", ats1.ToTestDisplayString());

            ArrayTypeSymbol ats2 = new ArrayTypeSymbol(compilation.Assembly, elementType, rank: 2);
            Assert.Equal(2, ats2.Rank);
            Assert.Same(elementType, ats2.ElementType);
            Assert.Equal(SymbolKind.ArrayType, ats2.Kind);
            Assert.True(ats2.IsReferenceType);
            Assert.False(ats2.IsValueType);
            Assert.Equal("TestClass[,]", ats2.ToTestDisplayString());

            ArrayTypeSymbol ats3 = new ArrayTypeSymbol(compilation.Assembly, elementType, rank: 3);
            Assert.Equal(3, ats3.Rank);
            Assert.Equal("TestClass[,,]", ats3.ToTestDisplayString());
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:26,代码来源:MockSymbolTests.cs


示例2: CorLibTypes

        public void CorLibTypes()
        {
            var mdTestLib1 = TestReferences.SymbolsTests.MDTestLib1;

            var c1 = CSharpCompilation.Create("Test", references: new MetadataReference[] { MscorlibRef_v4_0_30316_17626, mdTestLib1 });

            TypeSymbol c107 = c1.GlobalNamespace.GetTypeMembers("C107").Single();

            Assert.Equal(SpecialType.None, c107.SpecialType);

            for (int i = 1; i <= (int)SpecialType.Count; i++)
            {
                NamedTypeSymbol type = c1.GetSpecialType((SpecialType)i);
                Assert.False(type.IsErrorType());
                Assert.Equal((SpecialType)i, type.SpecialType);
            }

            Assert.Equal(SpecialType.None, c107.SpecialType);

            var arrayOfc107 = new ArrayTypeSymbol(c1.Assembly, c107);

            Assert.Equal(SpecialType.None, arrayOfc107.SpecialType);

            var c2 = CSharpCompilation.Create("Test", references: new[] { mdTestLib1 });

            Assert.Equal(SpecialType.None, c2.GlobalNamespace.GetTypeMembers("C107").Single().SpecialType);
        }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:27,代码来源:CompilationCreationTests.cs


示例3: TypedConstantTests

 public TypedConstantTests()
 {
     compilation = CreateCompilationWithMscorlib("class C {}");
     namedType = compilation.GlobalNamespace.GetMember<NamedTypeSymbol>("C");
     systemType = compilation.GetWellKnownType(WellKnownType.System_Type);
     arrayType = compilation.CreateArrayTypeSymbol(compilation.GetSpecialType(SpecialType.System_Object));
     intType = compilation.GetSpecialType(SpecialType.System_Int32);
     stringType = compilation.GetSpecialType(SpecialType.System_String);
     enumString1 = compilation.GetSpecialType(SpecialType.System_Collections_Generic_IEnumerable_T).Construct(compilation.GetSpecialType(SpecialType.System_String));
     enumString2 = compilation.GetSpecialType(SpecialType.System_Collections_Generic_IEnumerable_T).Construct(compilation.GetSpecialType(SpecialType.System_String));
 }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:11,代码来源:TypedConstantTests.cs


示例4: EmitElementInitializers

 private void EmitElementInitializers(ArrayTypeSymbol arrayType,
                                     ImmutableArray<BoundExpression> inits,
                                     bool includeConstants)
 {
     if (!IsMultidimensionalInitializer(inits))
     {
         EmitVectorElementInitializers(arrayType, inits, includeConstants);
     }
     else
     {
         EmitMultidimensionalElementInitializers(arrayType, inits, includeConstants);
     }
 }
开发者ID:GeertVL,项目名称:roslyn,代码行数:13,代码来源:EmitArrayInitializer.cs


示例5: EmitVectorElementInitializers

 private void EmitVectorElementInitializers(ArrayTypeSymbol arrayType,
             ImmutableArray<BoundExpression> inits,
             bool includeConstants)
 {
     for (int i = 0; i < inits.Length; i++)
     {
         var init = inits[i];
         if (ShouldEmitInitExpression(includeConstants, init))
         {
             _builder.EmitOpCode(ILOpCode.Dup);
             _builder.EmitIntConstant(i);
             EmitExpression(init, true);
             EmitVectorElementStore(arrayType, init.Syntax);
         }
     }
 }
开发者ID:GeertVL,项目名称:roslyn,代码行数:16,代码来源:EmitArrayInitializer.cs


示例6: DynamicAnalysisInjector

        private DynamicAnalysisInjector(MethodSymbol method, BoundStatement methodBody, SyntheticBoundNodeFactory methodBodyFactory, MethodSymbol createPayload, DiagnosticBag diagnostics, DebugDocumentProvider debugDocumentProvider, Instrumenter previous)
            : base(previous)
        {
            _createPayload = createPayload;
            _method = method;
            _methodBody = methodBody;
            _spansBuilder = ArrayBuilder<SourceSpan>.GetInstance();
            TypeSymbol payloadElementType = methodBodyFactory.SpecialType(SpecialType.System_Boolean);
            _payloadType = ArrayTypeSymbol.CreateCSharpArray(methodBodyFactory.Compilation.Assembly, payloadElementType);
            _methodPayload = methodBodyFactory.SynthesizedLocal(_payloadType, kind: SynthesizedLocalKind.InstrumentationPayload, syntax: methodBody.Syntax);
            _diagnostics = diagnostics;
            _debugDocumentProvider = debugDocumentProvider;
            _methodHasExplicitBlock = MethodHasExplicitBlock(method);
            _methodBodyFactory = methodBodyFactory;

            // The first point indicates entry into the method and has the span of the method definition.
            _methodEntryInstrumentation = AddAnalysisPoint(MethodDeclarationIfAvailable(methodBody.Syntax), methodBodyFactory);
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:18,代码来源:DynamicAnalysisInjector.cs


示例7: EmitArrayInitializers

        /// <summary>
        /// Entry point to the array initialization.
        /// Assumes that we have newly created array on the stack.
        /// 
        /// inits could be an array of values for a single dimensional array
        /// or an   array (of array)+  of values for a multidimensional case
        /// 
        /// in either case it is expected that number of leaf values will match number 
        /// of elements in the array and nesting level should match the rank of the array.
        /// </summary>
        private void EmitArrayInitializers(ArrayTypeSymbol arrayType, BoundArrayInitialization inits)
        {
            var initExprs = inits.Initializers;
            var initializationStyle = ShouldEmitBlockInitializer(arrayType.ElementType, initExprs);

            if (initializationStyle == ArrayInitializerStyle.Element)
            {
                this.EmitElementInitializers(arrayType, initExprs, true);
            }
            else
            {
                ImmutableArray<byte> data = this.GetRawData(initExprs);
                _builder.EmitArrayBlockInitializer(data, inits.Syntax, _diagnostics);

                if (initializationStyle == ArrayInitializerStyle.Mixed)
                {
                    EmitElementInitializers(arrayType, initExprs, false);
                }
            }
        }
开发者ID:GeertVL,项目名称:roslyn,代码行数:30,代码来源:EmitArrayInitializer.cs


示例8: EmitArrayElementStore

 private void EmitArrayElementStore(ArrayTypeSymbol arrayType, SyntaxNode syntaxNode)
 {
     if (arrayType.IsSZArray)
     {
         EmitVectorElementStore(arrayType, syntaxNode);
     }
     else
     {
         _builder.EmitArrayElementStore(Emit.PEModuleBuilder.Translate(arrayType), syntaxNode, _diagnostics);
     }
 }
开发者ID:tvsonar,项目名称:roslyn,代码行数:11,代码来源:EmitExpression.cs


示例9: TransformArrayType

        private ArrayTypeSymbol TransformArrayType(ArrayTypeSymbol arrayType)
        {
            var flag = ConsumeFlag();
            Debug.Assert(!flag);

            if (!HandleCustomModifiers(arrayType.CustomModifiers.Length))
            {
                return null;
            }

            TypeSymbol transformedElementType = TransformType(arrayType.ElementType);
            if ((object)transformedElementType == null)
            {
                return null;
            }

            return transformedElementType == arrayType.ElementType ?
                arrayType :
                arrayType.IsSZArray ?
                    ArrayTypeSymbol.CreateSZArray(_containingAssembly, transformedElementType, arrayType.CustomModifiers) :
                    ArrayTypeSymbol.CreateMDArray(_containingAssembly, transformedElementType, arrayType.Rank, arrayType.Sizes, arrayType.LowerBounds, arrayType.CustomModifiers);
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:22,代码来源:DynamicTypeDecoder.cs


示例10: EmitMultidimensionalElementInitializers

        private void EmitMultidimensionalElementInitializers(ArrayTypeSymbol arrayType,
                                                            ImmutableArray<BoundExpression> inits,
                                                            bool includeConstants)
        {
            // Using a List for the stack instead of the framework Stack because IEnumerable from Stack is top to bottom.
            // This algorithm requires the IEnumerable to be from bottom to top. See extensions for List in CollectionExtensions.vb.

            var indices = new ArrayBuilder<IndexDesc>();

            // emit initializers for all values of the leftmost index.
            for (int i = 0; i < inits.Length; i++)
            {
                indices.Push(new IndexDesc(i, ((BoundArrayInitialization)inits[i]).Initializers));
                EmitAllElementInitializersRecursive(arrayType, indices, includeConstants);
            }

            Debug.Assert(!indices.Any());
        }
开发者ID:GeertVL,项目名称:roslyn,代码行数:18,代码来源:EmitArrayInitializer.cs


示例11: TestArrayTypeInAttributeArgument

        public void TestArrayTypeInAttributeArgument()
        {
            var source =
@"using System;

public class W {}

public class Y<T>
{
  public class F {}
  public class Z<U> {}
}

public class X : Attribute
{
    public X(Type y) { }
}

[X(typeof(W[]))]
public class C1 {}

[X(typeof(W[,]))]
public class C2 {}

[X(typeof(W[,][]))]
public class C3 {}

[X(typeof(Y<W>[][,]))]
public class C4 {}

[X(typeof(Y<int>.F[,][][,,]))]
public class C5 {}

[X(typeof(Y<int>.Z<W>[,][]))]
public class C6 {}
";

            var compilation = CreateCompilationWithMscorlib(source);

            Action<ModuleSymbol> attributeValidator = (ModuleSymbol m) =>
            {
                NamedTypeSymbol classW = m.GlobalNamespace.GetTypeMember("W");
                NamedTypeSymbol classY = m.GlobalNamespace.GetTypeMember("Y");
                NamedTypeSymbol classF = classY.GetTypeMember("F");
                NamedTypeSymbol classZ = classY.GetTypeMember("Z");
                NamedTypeSymbol classX = m.GlobalNamespace.GetTypeMember("X");

                NamedTypeSymbol classC1 = m.GlobalNamespace.GetTypeMember("C1");
                NamedTypeSymbol classC2 = m.GlobalNamespace.GetTypeMember("C2");
                NamedTypeSymbol classC3 = m.GlobalNamespace.GetTypeMember("C3");
                NamedTypeSymbol classC4 = m.GlobalNamespace.GetTypeMember("C4");
                NamedTypeSymbol classC5 = m.GlobalNamespace.GetTypeMember("C5");
                NamedTypeSymbol classC6 = m.GlobalNamespace.GetTypeMember("C6");

                var attrs = classC1.GetAttributes();
                Assert.Equal(1, attrs.Length);
                var typeArg = new ArrayTypeSymbol(m.ContainingAssembly, classW, default(ImmutableArray<CustomModifier>));
                attrs.First().VerifyValue<object>(0, TypedConstantKind.Type, typeArg);

                attrs = classC2.GetAttributes();
                Assert.Equal(1, attrs.Length);
                typeArg = new ArrayTypeSymbol(m.ContainingAssembly, classW, default(ImmutableArray<CustomModifier>), rank: 2);
                attrs.First().VerifyValue<object>(0, TypedConstantKind.Type, typeArg);

                attrs = classC3.GetAttributes();
                Assert.Equal(1, attrs.Length);
                typeArg = new ArrayTypeSymbol(m.ContainingAssembly, classW, default(ImmutableArray<CustomModifier>));
                typeArg = new ArrayTypeSymbol(m.ContainingAssembly, typeArg, default(ImmutableArray<CustomModifier>), rank: 2);
                attrs.First().VerifyValue<object>(0, TypedConstantKind.Type, typeArg);

                attrs = classC4.GetAttributes();
                Assert.Equal(1, attrs.Length);
                NamedTypeSymbol classYOfW = classY.ConstructIfGeneric(ImmutableArray.Create<TypeSymbol>(classW));
                typeArg = new ArrayTypeSymbol(m.ContainingAssembly, classYOfW, default(ImmutableArray<CustomModifier>), rank: 2);
                typeArg = new ArrayTypeSymbol(m.ContainingAssembly, typeArg, default(ImmutableArray<CustomModifier>));
                attrs.First().VerifyValue<object>(0, TypedConstantKind.Type, typeArg);

                attrs = classC5.GetAttributes();
                Assert.Equal(1, attrs.Length);
                NamedTypeSymbol classYOfInt = classY.ConstructIfGeneric(ImmutableArray.Create<TypeSymbol>(m.ContainingAssembly.GetSpecialType(SpecialType.System_Int32)));
                NamedTypeSymbol substNestedF = classYOfInt.GetTypeMember("F");
                typeArg = new ArrayTypeSymbol(m.ContainingAssembly, substNestedF, default(ImmutableArray<CustomModifier>), rank: 3);
                typeArg = new ArrayTypeSymbol(m.ContainingAssembly, typeArg, default(ImmutableArray<CustomModifier>));
                typeArg = new ArrayTypeSymbol(m.ContainingAssembly, typeArg, default(ImmutableArray<CustomModifier>), rank: 2);
                attrs.First().VerifyValue<object>(0, TypedConstantKind.Type, typeArg);

                attrs = classC6.GetAttributes();
                Assert.Equal(1, attrs.Length);
                NamedTypeSymbol substNestedZ = classYOfInt.GetTypeMember("Z").ConstructIfGeneric(ImmutableArray.Create<TypeSymbol>(classW));
                typeArg = new ArrayTypeSymbol(m.ContainingAssembly, substNestedZ, default(ImmutableArray<CustomModifier>));
                typeArg = new ArrayTypeSymbol(m.ContainingAssembly, typeArg, default(ImmutableArray<CustomModifier>), rank: 2);
                attrs.First().VerifyValue<object>(0, TypedConstantKind.Type, typeArg);
            };

            // Verify attributes from source and then load metadata to see attributes are written correctly.
            CompileAndVerify(compilation, sourceSymbolValidator: attributeValidator, symbolValidator: attributeValidator);
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:97,代码来源:AttributeTests.cs


示例12: IsArrayOfArrays

 private static bool IsArrayOfArrays(ArrayTypeSymbol arrayType)
 {
     return arrayType.ElementType.Kind == SymbolKind.ArrayType;
 }
开发者ID:GloryChou,项目名称:roslyn,代码行数:4,代码来源:ClsComplianceChecker.cs


示例13: GetCustomTypeInfoPayload

        private static BoundExpression GetCustomTypeInfoPayload(LocalSymbol local, CSharpSyntaxNode syntax, CSharpCompilation compilation, out bool hasCustomTypeInfoPayload)
        {
            var byteArrayType = new ArrayTypeSymbol(
                compilation.Assembly,
                compilation.GetSpecialType(SpecialType.System_Byte));

            var flags = CSharpCompilation.DynamicTransformsEncoder.Encode(local.Type, customModifiersCount: 0, refKind: RefKind.None);
            var bytes = DynamicFlagsCustomTypeInfo.Create(flags).GetCustomTypeInfoPayload();
            hasCustomTypeInfoPayload = bytes != null;
            if (!hasCustomTypeInfoPayload)
            {
                return new BoundLiteral(syntax, ConstantValue.Null, byteArrayType);
            }

            var byteType = byteArrayType.ElementType;
            var intType = compilation.GetSpecialType(SpecialType.System_Int32);

            var numBytes = bytes.Count;
            var initializerExprs = ArrayBuilder<BoundExpression>.GetInstance(numBytes);
            foreach (var b in bytes)
            {
                initializerExprs.Add(new BoundLiteral(syntax, ConstantValue.Create(b), byteType));
            }

            var lengthExpr = new BoundLiteral(syntax, ConstantValue.Create(numBytes), intType);
            return new BoundArrayCreation(
                syntax,
                ImmutableArray.Create<BoundExpression>(lengthExpr),
                new BoundArrayInitialization(syntax, initializerExprs.ToImmutableAndFree()),
                byteArrayType);
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:31,代码来源:LocalDeclarationRewriter.cs


示例14: BuildArrayShapeString

        private static string BuildArrayShapeString(ArrayTypeSymbol arrayType)
        {
            PooledStringBuilder pool = PooledStringBuilder.GetInstance();
            StringBuilder builder = pool.Builder;

            builder.Append("[");

            if (arrayType.Rank > 1)
            {
                builder.Append(',', arrayType.Rank - 1);
            }

            builder.Append("]");

            return pool.ToStringAndFree();
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:16,代码来源:NamespaceScopeBuilder.cs


示例15: BuildArrayTypeString

        private string BuildArrayTypeString(ArrayTypeSymbol arrayType, out string assemblyNameSuffix)
        {
            TypeSymbol elementType = arrayType.ElementType;

            string typeArgumentsOpt = null;
            string elementTypeString = elementType.IsArray() ?
                BuildArrayTypeString((ArrayTypeSymbol)elementType, out assemblyNameSuffix) :
                BuildTypeString(elementType, out typeArgumentsOpt, out assemblyNameSuffix);

            PooledStringBuilder pool = PooledStringBuilder.GetInstance();
            StringBuilder builder = pool.Builder;
            builder.Append(elementTypeString);
            AppendTypeArguments(builder, typeArgumentsOpt);
            builder.Append(BuildArrayShapeString(arrayType));
            return pool.ToStringAndFree();
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:16,代码来源:NamespaceScopeBuilder.cs


示例16: TestBaseTypeDynamicTransforms

        public void TestBaseTypeDynamicTransforms()
        {
            CommonTestInitialization();

            // public class Base0 { }
            Assert.Equal(_objectType, _base0Class.BaseType);
            Assert.False(_base0Class.ContainsDynamic());

            // public class Base1<T> { }
            Assert.Equal(_objectType, _base1Class.BaseType);
            Assert.False(_base1Class.ContainsDynamic());

            // public class Base2<T, U> { }
            Assert.Equal(_objectType, _base2Class.BaseType);
            Assert.False(_base2Class.ContainsDynamic());

            // public class Derived<T> : Outer<dynamic>.Inner<Outer<dynamic>.Inner<T[], dynamic>.InnerInner<int>[], dynamic>.InnerInner<dynamic> where T : Derived<T> { ... }
            Assert.False(_derivedClass.ContainsDynamic());
            Assert.True(_derivedClass.BaseType.ContainsDynamic());

            // Outer<dynamic>
            var outerClassOfDynamic = _outerClass.Construct(s_dynamicType);
            // Outer<dynamic>.Inner<T[], dynamic>
            var t = _derivedClass.TypeParameters[0];
            var arrayOfT = new ArrayTypeSymbol(_assembly, t);
            var innerClassOfTArrDynamic = outerClassOfDynamic.GetTypeMember("Inner").Construct(arrayOfT, s_dynamicType);
            // Outer<dynamic>.Inner<T[], dynamic>.InnerInner<int>[]
            var memberInnerInnerOfInt = innerClassOfTArrDynamic.GetTypeMember("InnerInner").Construct(_intType);
            var arrayOfInnerInnerOfInt = new ArrayTypeSymbol(_assembly, memberInnerInnerOfInt);
            // Outer<dynamic>.Inner<Outer<dynamic>.Inner<T[], dynamic>.InnerInner<int>[], dynamic>
            var memberComplicatedInner = outerClassOfDynamic.GetTypeMember("Inner").Construct(arrayOfInnerInnerOfInt, s_dynamicType);
            // Outer<dynamic>.Inner<Outer<dynamic>.Inner<T[], dynamic>.InnerInner<int>[], dynamic>.InnerInner<dynamic>
            var memberInnerInnerOfDynamic = memberComplicatedInner.GetTypeMember("InnerInner").Construct(s_dynamicType);

            Assert.Equal(memberInnerInnerOfDynamic, _derivedClass.BaseType);

            // public class Outer<T> : Base1<dynamic>
            Assert.False(_outerClass.ContainsDynamic());
            Assert.True(_outerClass.BaseType.ContainsDynamic());
            var base1OfDynamic = _base1Class.Construct(s_dynamicType);
            Assert.Equal(base1OfDynamic, _outerClass.BaseType);

            // public class Inner<U, V> : Base2<dynamic, V>
            Assert.False(_innerClass.ContainsDynamic());
            Assert.True(_innerClass.BaseType.ContainsDynamic());
            var base2OfDynamicV = _base2Class.Construct(s_dynamicType, _innerClass.TypeParameters[1]);
            Assert.Equal(base2OfDynamicV, _innerClass.BaseType);

            // public class InnerInner<W> : Base1<dynamic> { }
            Assert.False(_innerInnerClass.ContainsDynamic());
            Assert.True(_innerInnerClass.BaseType.ContainsDynamic());
            Assert.Equal(base1OfDynamic, _innerInnerClass.BaseType);

            // public class Outer2<T> : Base1<dynamic>
            Assert.False(_outer2Class.ContainsDynamic());
            Assert.True(_outer2Class.BaseType.ContainsDynamic());
            Assert.Equal(base1OfDynamic, _outer2Class.BaseType);

            // public class Inner2<U, V> : Base0
            Assert.False(_inner2Class.ContainsDynamic());
            Assert.False(_inner2Class.BaseType.ContainsDynamic());
            Assert.Equal(_base0Class, _inner2Class.BaseType);

            // public class InnerInner2<W> : Base0 { }
            Assert.False(_innerInner2Class.ContainsDynamic());
            Assert.False(_innerInner2Class.BaseType.ContainsDynamic());
            Assert.Equal(_base0Class, _innerInner2Class.BaseType);

            // public class Inner3<U>
            Assert.False(_inner3Class.ContainsDynamic());
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:71,代码来源:DynamicTransformsTests.cs


示例17: GetMatchingElementType

        private static TypeSymbol GetMatchingElementType(ArrayTypeSymbol source, TypeSymbol target, ref HashSet<DiagnosticInfo> useSiteDiagnostics)
        {
            Debug.Assert((object)source != null);
            Debug.Assert((object)target != null);

            // It might be an array of same rank.
            if (target.IsArray())
            {
                var arrayTarget = (ArrayTypeSymbol)target;
                if (!arrayTarget.HasSameShapeAs(source))
                {
                    return null;
                }
                return arrayTarget.ElementType;
            }

            // Or it might be IEnum<T> and source is rank one.

            if (!source.IsSZArray)
            {
                return null;
            }

            // Arrays are specified as being convertible to IEnumerable<T>, ICollection<T> and
            // IList<T>; we also honor their convertibility to IReadOnlyCollection<T> and
            // IReadOnlyList<T>, and make inferences accordingly.

            if (!target.IsPossibleArrayGenericInterface())
            {
                return null;
            }

            return ((NamedTypeSymbol)target).TypeArgumentWithDefinitionUseSiteDiagnostics(0, ref useSiteDiagnostics);
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:34,代码来源:MethodTypeInference.cs


示例18: SubstituteArrayType

        private ArrayTypeSymbol SubstituteArrayType(ArrayTypeSymbol t)
        {
            TypeSymbol element = SubstituteType(t.ElementType);
            if (ReferenceEquals(element, t.ElementType))
            {
                return t;
            }

            ImmutableArray<NamedTypeSymbol> interfaces = t.InterfacesNoUseSiteDiagnostics();
            Debug.Assert(0 <= interfaces.Length && interfaces.Length <= 2);

            if (interfaces.Length == 1)
            {
                Debug.Assert(interfaces[0] is NamedTypeSymbol); // IList<T>
                interfaces = ImmutableArray.Create<NamedTypeSymbol>((NamedTypeSymbol)SubstituteType(interfaces[0]));
            }
            else if (interfaces.Length == 2)
            {
                Debug.Assert(interfaces[0] is NamedTypeSymbol); // IList<T>
                interfaces = ImmutableArray.Create<NamedTypeSymbol>((NamedTypeSymbol)SubstituteType(interfaces[0]), (NamedTypeSymbol)SubstituteType(interfaces[1]));
            }

            return new ArrayTypeSymbol(
                element,
                t.Rank,
                t.BaseTypeNoUseSiteDiagnostics,
                interfaces,
                t.CustomModifiers);
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:29,代码来源:AbstractTypeMap.cs


示例19: TypeMap

        public void TypeMap()
        {
            var source = @"
struct S<T> where T : struct
{
}
";

            var comp = CreateCompilationWithMscorlib(source);
            comp.VerifyDiagnostics();

            var intType = comp.GetSpecialType(SpecialType.System_Int32);
            var customModifiers = ImmutableArray.Create(CSharpCustomModifier.CreateOptional(intType));

            var structType = comp.GlobalNamespace.GetMember<NamedTypeSymbol>("S");
            var typeParamType = structType.TypeParameters.Single();

            var pointerType = new PointerTypeSymbol(typeParamType, customModifiers); // NOTE: We're constructing this manually, since it's illegal.
            var arrayType = new ArrayTypeSymbol(comp.Assembly, typeParamType, customModifiers); // This is legal, but we're already manually constructing types.

            var typeMap = new TypeMap(ImmutableArray.Create(typeParamType), ImmutableArray.Create<TypeSymbol>(intType));

            var substitutedPointerType = (PointerTypeSymbol)typeMap.SubstituteType(pointerType);
            var substitutedArrayType = (ArrayTypeSymbol)typeMap.SubstituteType(arrayType);

            // The map changed the types.
            Assert.Equal(intType, substitutedPointerType.PointedAtType);
            Assert.Equal(intType, substitutedArrayType.ElementType);

            // The map preserved the custom modifiers.
            Assert.Equal(customModifiers, substitutedPointerType.CustomModifiers);
            Assert.Equal(customModifiers, substitutedArrayType.CustomModifiers);
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:33,代码来源:ModifierTests.cs


示例20: ReducedExtensionMethodSymbols

        public void ReducedExtensionMethodSymbols()
        {
            var source =
@"using System.Collections.Generic;
static class S
{
    internal static void M1(this object o) { }
    internal static void M2<T>(this IEnumerable<T> t) { }
    internal static void M3<T, U>(this U u, IEnumerable<T> t) { }
}";
            var compilation = CreateCompilationWithMscorlib(source, references: new[] { SystemCoreRef }, options: TestOptions.ReleaseDll.WithMetadataImportOptions(MetadataImportOptions.Internal));
            Action<ModuleSymbol> validator = module =>
            {
                var type = module.GlobalNamespace.GetMember<NamedTypeSymbol>("S");
                var intType = compilation.GetSpecialType(SpecialType.System_Int32);
                var stringType = compilation.GetSpecialType(SpecialType.System_String);
                var arrayType = new ArrayTypeSymbol(compilation.Assembly, stringType, ImmutableArray.Create<CustomModifier>(), 1);

                // Non-generic method.
                var method = type.GetMember<MethodSymbol>("M1");
                CheckExtensionMethod(method,
                    ImmutableArray.Create<TypeSymbol>(),
                    "void object.M1()",
                    "void S.M1(object o)",
                    "void object.M1()",
                    "void S.M1(object o)");

                // Generic method, one type argument.
                method = type.GetMember<MethodSymbol>("M2");
                CheckExtensionMethod(method,
                    ImmutableArray.Create<TypeSymbol>(intType),
                    "void IEnumerable<int>.M2<int>()",
                    "void S.M2<T>(IEnumerable<T> t)",
                    "void IEnumerable<T>.M2<T>()",
                    "void S.M2<T>(IEnumerable<T> t)");

                // Generic method, multiple type arguments.
                method = type.GetMember<MethodSymbol>("M3");
                CheckExtensionMethod(method,
                    ImmutableArray.Create<TypeSymbol>(intType, arrayType),
                    "void string[].M3<int, string[]>(IEnumerable<int> t)",
                    "void S.M3<T, U>(U u, IEnumerable<T> t)",
                    "void U.M3<T, U>(IEnumerable<T> t)",
                    "void S.M3<T, U>(U u, IEnumerable<T> t)");
            };

            CompileAndVerify(compilation, emitOptions: TestEmitters.CCI, sourceSymbolValidator: validator, symbolValidator: validator);
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:48,代码来源:ExtensionMethodTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Symbols.CSharpAttributeData类代码示例发布时间:2022-05-26
下一篇:
C# ContextQuery.CSharpSyntaxContext类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap