本文整理汇总了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);
}
}
}
}
示例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);
}
}
}
}