本文整理汇总了C#中ImmutableArray.IndexOfAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# ImmutableArray.IndexOfAttribute方法的具体用法?C# ImmutableArray.IndexOfAttribute怎么用?C# ImmutableArray.IndexOfAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImmutableArray
的用法示例。
在下文中一共展示了ImmutableArray.IndexOfAttribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PostDecodeWellKnownAttributes
internal override void PostDecodeWellKnownAttributes(ImmutableArray<CSharpAttributeData> boundAttributes, ImmutableArray<AttributeSyntax> allAttributeSyntaxNodes, DiagnosticBag diagnostics, AttributeLocation symbolPart, WellKnownAttributeData decodedData)
{
Debug.Assert(!boundAttributes.IsDefault);
Debug.Assert(!allAttributeSyntaxNodes.IsDefault);
Debug.Assert(boundAttributes.Length == allAttributeSyntaxNodes.Length);
Debug.Assert(_lazyCustomAttributesBag != null);
Debug.Assert(_lazyCustomAttributesBag.IsDecodedWellKnownAttributeDataComputed);
Debug.Assert(symbolPart == AttributeLocation.None);
var data = (TypeWellKnownAttributeData)decodedData;
if (this.IsComImport)
{
Debug.Assert(boundAttributes.Any());
// Symbol with ComImportAttribute must have a GuidAttribute
if (data == null || data.GuidString == null)
{
int index = boundAttributes.IndexOfAttribute(this, AttributeDescription.ComImportAttribute);
diagnostics.Add(ErrorCode.ERR_ComImportWithoutUuidAttribute, allAttributeSyntaxNodes[index].Name.Location, this.Name);
}
if (this.TypeKind == TypeKind.Class)
{
var baseType = this.BaseTypeNoUseSiteDiagnostics;
if ((object)baseType != null && baseType.SpecialType != SpecialType.System_Object)
{
// CS0424: '{0}': a class with the ComImport attribute cannot specify a base class
diagnostics.Add(ErrorCode.ERR_ComImportWithBase, this.Locations[0], this.Name);
}
var initializers = this.StaticInitializers;
if (!initializers.IsDefaultOrEmpty)
{
foreach (var initializerGroup in initializers)
{
foreach (var singleInitializer in initializerGroup)
{
if (!singleInitializer.FieldOpt.IsMetadataConstant)
{
// CS8028: '{0}': a class with the ComImport attribute cannot specify field initializers.
diagnostics.Add(ErrorCode.ERR_ComImportWithInitializers, singleInitializer.Syntax.GetLocation(), this.Name);
}
}
}
}
initializers = this.InstanceInitializers;
if (!initializers.IsDefaultOrEmpty)
{
foreach (var initializerGroup in initializers)
{
foreach (var singleInitializer in initializerGroup)
{
// CS8028: '{0}': a class with the ComImport attribute cannot specify field initializers.
diagnostics.Add(ErrorCode.ERR_ComImportWithInitializers, singleInitializer.Syntax.GetLocation(), this.Name);
}
}
}
}
}
else if ((object)this.ComImportCoClass != null)
{
Debug.Assert(boundAttributes.Any());
// Symbol with CoClassAttribute must have a ComImportAttribute
int index = boundAttributes.IndexOfAttribute(this, AttributeDescription.CoClassAttribute);
diagnostics.Add(ErrorCode.WRN_CoClassWithoutComImport, allAttributeSyntaxNodes[index].Location, this.Name);
}
// Report ERR_DefaultMemberOnIndexedType if type has a default member attribute and has indexers.
if (data != null && data.HasDefaultMemberAttribute && this.Indexers.Any())
{
Debug.Assert(boundAttributes.Any());
int index = boundAttributes.IndexOfAttribute(this, AttributeDescription.DefaultMemberAttribute);
diagnostics.Add(ErrorCode.ERR_DefaultMemberOnIndexedType, allAttributeSyntaxNodes[index].Name.Location);
}
base.PostDecodeWellKnownAttributes(boundAttributes, allAttributeSyntaxNodes, diagnostics, symbolPart, decodedData);
}
示例2: PostDecodeWellKnownAttributes
internal override void PostDecodeWellKnownAttributes(ImmutableArray<CSharpAttributeData> boundAttributes, ImmutableArray<AttributeSyntax> allAttributeSyntaxNodes, DiagnosticBag diagnostics, AttributeLocation symbolPart, WellKnownAttributeData decodedData)
{
Debug.Assert(!boundAttributes.IsDefault);
Debug.Assert(!allAttributeSyntaxNodes.IsDefault);
Debug.Assert(boundAttributes.Length == allAttributeSyntaxNodes.Length);
Debug.Assert(_lazyCustomAttributesBag != null);
Debug.Assert(_lazyCustomAttributesBag.IsDecodedWellKnownAttributeDataComputed);
Debug.Assert(symbolPart == AttributeLocation.None);
var data = (CommonFieldWellKnownAttributeData)decodedData;
int? fieldOffset = data != null ? data.Offset : null;
if (fieldOffset.HasValue)
{
if (this.ContainingType.Layout.Kind != LayoutKind.Explicit)
{
Debug.Assert(boundAttributes.Any());
// error CS0636: The FieldOffset attribute can only be placed on members of types marked with the StructLayout(LayoutKind.Explicit)
int i = boundAttributes.IndexOfAttribute(this, AttributeDescription.FieldOffsetAttribute);
diagnostics.Add(ErrorCode.ERR_StructOffsetOnBadStruct, allAttributeSyntaxNodes[i].Name.Location);
}
}
else if (!this.IsStatic && !this.IsConst)
{
if (this.ContainingType.Layout.Kind == LayoutKind.Explicit)
{
// error CS0625: '<field>': instance field types marked with StructLayout(LayoutKind.Explicit) must have a FieldOffset attribute
diagnostics.Add(ErrorCode.ERR_MissingStructOffset, this.ErrorLocation, this);
}
}
base.PostDecodeWellKnownAttributes(boundAttributes, allAttributeSyntaxNodes, diagnostics, symbolPart, decodedData);
}