本文整理汇总了C#中ISymbol.TypeSwitch方法的典型用法代码示例。如果您正苦于以下问题:C# ISymbol.TypeSwitch方法的具体用法?C# ISymbol.TypeSwitch怎么用?C# ISymbol.TypeSwitch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISymbol
的用法示例。
在下文中一共展示了ISymbol.TypeSwitch方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetOverriddenMember
private static ISymbol GetOverriddenMember(ISymbol symbol)
{
return symbol.TypeSwitch(
(IMethodSymbol method) => (ISymbol)method.OverriddenMethod,
(IPropertySymbol property) => property.OverriddenProperty,
(IEventSymbol @event) => @event.OverriddenEvent);
}
示例2: GetDescription
private static string GetDescription(ISymbol throughMember)
{
return throughMember.TypeSwitch(
(IFieldSymbol field) => field.Name,
(IPropertySymbol property) => property.Name,
_ => Contract.FailWithReturn<string>());
}
示例3: GetDescription
private static string GetDescription(ISymbol throughMember)
{
return throughMember.TypeSwitch(
(IFieldSymbol field) => field.Name,
(IPropertySymbol property) => property.Name);
}
示例4: GetType
private static ITypeSymbol GetType(Compilation compilation, ISymbol symbol)
{
return symbol.TypeSwitch(
(IFieldSymbol field) => field.Type,
(IPropertySymbol property) => property.Type,
(ISymbol _) => compilation.GetSpecialType(SpecialType.System_Object));
}
示例5: GetType
private static ITypeSymbol GetType(ISymbol symbol)
{
return symbol.TypeSwitch(
(IEventSymbol f) => f.Type,
(IFieldSymbol f) => f.ContainingType.TypeKind == TypeKind.Enum ? null : f.Type,
(IMethodSymbol m) => IncludeReturnType(m) ? m.ReturnType : null,
(IPropertySymbol p) => p.Type,
(INamedTypeSymbol n) => n.IsDelegateType() ? n.DelegateInvokeMethod.ReturnType : null,
_ => null);
}
示例6: IsApplicable
/// <summary>
/// Is this method or property a valid place to set a breakpoint and does it match the expected parameter count?
/// </summary>
private bool IsApplicable(ISymbol methodOrProperty, int? parameterCount, CancellationToken cancellationToken)
{
// You can only set a breakpoint on methods (including constructors/destructors) and properties.
var kind = methodOrProperty.Kind;
if (!(kind == SymbolKind.Method || kind == SymbolKind.Property))
{
return false;
}
// You can't set a breakpoint on an abstract method or property.
if (methodOrProperty.IsAbstract)
{
return false;
}
// If parameters were provided, check to make sure the method or property has the expected number
// of parameters (but we don't actually validate the type or name of the supplied parameters).
if (parameterCount != null)
{
if (methodOrProperty.TypeSwitch(
(IMethodSymbol method) => method.Parameters.Length != parameterCount,
(IPropertySymbol property) => property.Parameters.Length != parameterCount))
{
return false;
}
}
// Finally, check to make sure we have source, and if we've got a method symbol, make sure it
// has a body to set a breakpoint on.
if ((methodOrProperty.Language == _language) && methodOrProperty.Locations.Any(location => location.IsInSource))
{
if (methodOrProperty.IsKind(SymbolKind.Method))
{
return HasMethodBody((IMethodSymbol)methodOrProperty, cancellationToken);
}
// Non-abstract properties are always applicable, because you can set a breakpoint on the
// accessor methods (get and/or set).
return true;
}
return false;
}