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


C# Symbols.ArrayTypeSymbol类代码示例

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


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


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