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


C# Symbol.GetSynthesizedAttributes方法代码示例

本文整理汇总了C#中Symbol.GetSynthesizedAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# Symbol.GetSynthesizedAttributes方法的具体用法?C# Symbol.GetSynthesizedAttributes怎么用?C# Symbol.GetSynthesizedAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symbol的用法示例。


在下文中一共展示了Symbol.GetSynthesizedAttributes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ValidateDynamicAttribute

            private static void ValidateDynamicAttribute(Symbol symbol, CSharpCompilation comp, MethodSymbol dynamicAttributeCtorNoArgs,
                 MethodSymbol dynamicAttributeCtorTransformFlags, bool expectedDynamicAttribute, bool[] expectedTransformFlags = null, bool forReturnType = false)
            {
                Assert.True(!forReturnType || symbol.Kind == SymbolKind.Method, "Incorrect usage of ValidateDynamicAttribute");

                var synthesizedDynamicAttributes = symbol.GetSynthesizedAttributes(forReturnType).Where((attr) => string.Equals(attr.AttributeClass.Name, "DynamicAttribute", StringComparison.Ordinal));

                if (!expectedDynamicAttribute)
                {
                    Assert.Empty(synthesizedDynamicAttributes);
                }
                else
                {
                    Assert.Equal(1, synthesizedDynamicAttributes.Count());

                    var dynamicAttribute = synthesizedDynamicAttributes.First();
                    var expectedCtor = expectedTransformFlags == null ? dynamicAttributeCtorNoArgs : dynamicAttributeCtorTransformFlags;
                    Assert.NotNull(expectedCtor);
                    Assert.Equal(expectedCtor, dynamicAttribute.AttributeConstructor);

                    if (expectedTransformFlags == null)
                    {
                        // Dynamic()
                        Assert.Equal(0, dynamicAttribute.CommonConstructorArguments.Length);
                    }
                    else
                    {
                        // Dynamic(bool[] transformFlags)
                        Assert.Equal(1, dynamicAttribute.CommonConstructorArguments.Length);

                        TypedConstant argument = dynamicAttribute.CommonConstructorArguments[0];
                        Assert.Equal(TypedConstantKind.Array, argument.Kind);

                        ImmutableArray<TypedConstant> actualTransformFlags = argument.Values;
                        Assert.Equal(expectedTransformFlags.Length, actualTransformFlags.Length);
                        TypeSymbol booleanType = comp.GetSpecialType(SpecialType.System_Boolean);

                        for (int i = 0; i < actualTransformFlags.Length; i++)
                        {
                            TypedConstant actualTransformFlag = actualTransformFlags[i];

                            Assert.Equal(TypedConstantKind.Primitive, actualTransformFlag.Kind);
                            Assert.Equal(booleanType, actualTransformFlag.Type);
                            Assert.Equal(expectedTransformFlags[i], (bool)actualTransformFlag.Value);
                        }
                    }
                }
            }
开发者ID:Rickinio,项目名称:roslyn,代码行数:48,代码来源:AttributeTests_Dynamic.cs

示例2: ValidateTupleNameAttribute

            private void ValidateTupleNameAttribute(
                Symbol symbol,
                bool expectedTupleNamesAttribute,
                string[] expectedElementNames = null,
                bool forReturnType = false)
            {
                var synthesizedTupleElementNamesAttr = symbol.GetSynthesizedAttributes(forReturnType)
                    .Where(attr => string.Equals(attr.AttributeClass.Name,
                                                 "TupleElementNamesAttribute",
                                                 StringComparison.Ordinal))
                    .ToList();
                if (!expectedTupleNamesAttribute)
                {
                    Assert.Empty(synthesizedTupleElementNamesAttr);
                }
                else
                {
                    var tupleAttr = synthesizedTupleElementNamesAttr.Single();
                    var expectedCtor = _tupleAttrTransformNames;
                    Assert.NotNull(expectedCtor);
                    Assert.Equal(expectedCtor, tupleAttr.AttributeConstructor);

                    if (expectedElementNames == null)
                    {
                        Assert.Empty(tupleAttr.CommonConstructorArguments);
                    }
                    else
                    {
                        Assert.Equal(1, tupleAttr.CommonConstructorArguments.Length);

                        var arg = tupleAttr.CommonConstructorArguments[0];
                        Assert.Equal(TypedConstantKind.Array, arg.Kind);

                        var actualElementNames = arg.Values;
                        Assert.Equal(expectedElementNames.Length, actualElementNames.Length);
                        var stringType = _comp.GetSpecialType(SpecialType.System_String);

                        for (int i =  0; i < actualElementNames.Length; i++)
                        {
                            string expectedName = expectedElementNames[i];
                            TypedConstant actualName = actualElementNames[i];

                            Assert.Equal(TypedConstantKind.Primitive, actualName.Kind);
                            Assert.Equal(stringType, actualName.Type);
                            Assert.Equal(expectedName, (string)actualName.Value);
                        }
                    }
                }
            }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:49,代码来源:AttributeTests_Tuples.cs


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