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


C# ISymbol.HasAttribute方法代码示例

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


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

示例1: CheckMember

		/// <summary>
		///   Checks whether the <paramref name="symbol" />'s implementing member for <paramref name="interfaceMember" /> has the
		///   correct port kind.
		/// </summary>
		/// <param name="context">The context in which the analysis should be performed.</param>
		/// <param name="symbol">The symbol that should be analyzed.</param>
		/// <param name="compilation">The compilation the symbol is declared in.</param>
		/// <param name="interfaceMember">The interface member that should be checked.</param>
		private static void CheckMember(SymbolAnalysisContext context, ITypeSymbol symbol, Compilation compilation, ISymbol interfaceMember)
		{
			var implementingMember = symbol.FindImplementationForInterfaceMember(interfaceMember);

			var interfaceIsRequired = interfaceMember.HasAttribute<RequiredAttribute>(compilation);
			var interfaceIsProvided = interfaceMember.HasAttribute<ProvidedAttribute>(compilation);

			var implementationIsRequired = implementingMember.HasAttribute<RequiredAttribute>(compilation) || implementingMember.IsExtern;
			var implementationIsProvided = implementingMember.HasAttribute<ProvidedAttribute>(compilation) || !implementingMember.IsExtern;

			// If we can't uniquely classify the port kind of either the interface member or the implementation, 
			// there is another problem that another analyzer deals with. So let's just ignore it here.
			if ((interfaceIsRequired && interfaceIsProvided) || (implementationIsProvided && implementationIsRequired))
				return;

			var location = implementingMember.ContainingType.Equals(symbol) ? implementingMember : symbol;
			if (interfaceIsRequired && !implementationIsRequired)
			{
				_requiredPortImplementedAsProvidedPort.Emit(context, location,
					implementingMember.ToDisplayString(), interfaceMember.ToDisplayString());
			}

			if (interfaceIsProvided && !implementationIsProvided)
			{
				_providedPortImplementedAsRequiredPort.Emit(context, location,
					implementingMember.ToDisplayString(), interfaceMember.ToDisplayString());
			}
		}
开发者ID:isse-augsburg,项目名称:ssharp,代码行数:36,代码来源:PortImplementationAnalyzer.cs

示例2: HasNotNullAttribute

 private static bool HasNotNullAttribute(ISymbol symbol)
 {
     return symbol.HasAttribute("NotNullAttribute");
 }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:4,代码来源:NotNullDiagnosticAnalyzer.cs


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