本文整理汇总了C#中INamedTypeSymbol.GetAllMembers方法的典型用法代码示例。如果您正苦于以下问题:C# INamedTypeSymbol.GetAllMembers方法的具体用法?C# INamedTypeSymbol.GetAllMembers怎么用?C# INamedTypeSymbol.GetAllMembers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类INamedTypeSymbol
的用法示例。
在下文中一共展示了INamedTypeSymbol.GetAllMembers方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EventSourceTypeInfo
/// <summary>
/// Initializes a new instance of the <see cref="EventSourceTypeInfo"/> class.
/// </summary>
public EventSourceTypeInfo(SemanticModel semanticModel, INamedTypeSymbol eventSourceClass)
{
if (eventSourceClass == null)
throw new ArgumentNullException("eventSourceClass", "eventSourceClass is null.");
INamedTypeSymbol eventSourceAttributeType = eventSourceClass.ContainingNamespace.GetTypeMembers("EventSourceAttribute", 0).Single();
INamedTypeSymbol eventAttributeType = eventSourceClass.ContainingNamespace.GetTypeMembers("EventAttribute", 0).Single();
EventSourceClass = eventSourceClass;
EventAttributeType = eventAttributeType;
EventSourceAttributeType = eventSourceAttributeType;
EventSourceNamespace = eventSourceClass.ContainingNamespace;
EventKeywordsType = semanticModel.Compilation.GetTypeByMetadataName(EventSourceNamespace.GetFullName() + ".EventKeywords");
EventOpcodeType = semanticModel.Compilation.GetTypeByMetadataName(EventSourceNamespace.GetFullName() + ".EventOpcode");
EventTaskType = semanticModel.Compilation.GetTypeByMetadataName(EventSourceNamespace.GetFullName() + ".EventTask");
WriteEventOverloads = eventSourceClass.GetAllMembers()
.OfType<IMethodSymbol>()
.Where(method => method.Name.Equals("WriteEvent"))
// Only add methods that have at least one parameter, and the first parameter is of type Int32.
.Where(method => method.Parameters.Length >= 1 && method.Parameters[0].Type.SpecialType == SpecialType.System_Int32)
// Only add methods that do not contain 'object' parameters or params parameters.
.Where(method => method.Parameters.All(parameter => !parameter.IsParams && parameter.Type.SpecialType != SpecialType.System_Object))
// Skip the first parameter, which should be (int eventId)
.Select(method => method.Parameters.Skip(1).ToImmutableArray())
.ToImmutableArray();
}
开发者ID:modulexcite,项目名称:EventSourceGenerator-1,代码行数:30,代码来源:EventSourceGenerator.EventSourceTypeInfo.cs
示例2: GetEventSourceTemplateMethods
/// <summary>Gets the event source template methods in this collection.</summary>
/// <param name="sourceClass">The class from which to retrieve methods.</param>
/// <param name="eventSourceBase">The event source base of the <paramref name="sourceClass"/>.</param>
/// <returns>
/// All methods that are candidates to be used for EventSource generation.
/// </returns>
private IEnumerable<IMethodSymbol> GetEventSourceTemplateMethods(INamedTypeSymbol sourceClass, EventSourceTypeInfo eventSourceBase)
{
System.Diagnostics.Debug.Assert(sourceClass.IsType);
foreach (IMethodSymbol method in sourceClass.GetAllMembers().OfType<IMethodSymbol>())
{
if (method.GetAttributes().Any(attribute => attribute.AttributeClass.Equals(eventSourceBase.EventAttributeType)) && method.IsAbstract)
{
yield return method;
}
else if (method.GetAttributes().Any(attribute => attribute.AttributeClass.Name.Equals(TemplateEventAttributeName)))
{
if (!method.IsAbstract)
throw new CodeGeneratorException(method, $"The method {sourceClass.Name}.{method.Name} must be abstract to participate in EventSource generation.");
yield return method;
}
}
}