本文整理汇总了C#中ISymbol.IsConstructor方法的典型用法代码示例。如果您正苦于以下问题:C# ISymbol.IsConstructor方法的具体用法?C# ISymbol.IsConstructor怎么用?C# ISymbol.IsConstructor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISymbol
的用法示例。
在下文中一共展示了ISymbol.IsConstructor方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsThirdPartyNavigationAllowed
private static bool IsThirdPartyNavigationAllowed(ISymbol symbolToNavigateTo, int caretPosition, Document document, CancellationToken cancellationToken)
{
var syntaxRoot = document.GetSyntaxRootAsync(cancellationToken).WaitAndGetResult(cancellationToken);
var syntaxFactsService = document.GetLanguageService<ISyntaxFactsService>();
var containingTypeDeclaration = syntaxFactsService.GetContainingTypeDeclaration(syntaxRoot, caretPosition);
if (containingTypeDeclaration != null)
{
var semanticModel = document.GetSemanticModelAsync(cancellationToken).WaitAndGetResult(cancellationToken);
var containingTypeSymbol = semanticModel.GetDeclaredSymbol(containingTypeDeclaration, cancellationToken) as ITypeSymbol;
// Allow third parties to navigate to all symbols except types/constructors
// if we are navigating from the corresponding type.
if (containingTypeSymbol != null &&
(symbolToNavigateTo is ITypeSymbol || symbolToNavigateTo.IsConstructor()))
{
var candidateTypeSymbol = symbolToNavigateTo is ITypeSymbol
? symbolToNavigateTo
: symbolToNavigateTo.ContainingType;
if (containingTypeSymbol == candidateTypeSymbol)
{
// We are navigating from the same type, so don't allow third parties to perform the navigation.
// This ensures that if we navigate to a class from within that class, we'll stay in the same file
// rather than navigate to, say, XAML.
return false;
}
}
}
return true;
}
示例2: TryAppendSymbol
public bool TryAppendSymbol(ISymbol symbol)
{
if (symbol == null)
{
return false;
}
var format = Format;
if (symbol.IsConstructor())
{
format = format.WithMemberOptions(SymbolDisplayMemberOptions.IncludeParameters | SymbolDisplayMemberOptions.IncludeExplicitInterface);
}
var parts = SemanticModel != null
? symbol.ToMinimalDisplayParts(SemanticModel, Position, format)
: symbol.ToDisplayParts(format);
AppendParts(parts);
return true;
}
示例3: MapSymbol
// public static IEnumerable<ISymbol> GetSymbols(
// this SemanticModel semanticModel,
// SyntaxToken token,
// Workspace workspace,
// bool bindLiteralsToUnderlyingType,
// CancellationToken cancellationToken)
// {
// var languageServices = workspace.Services.GetLanguageServices(token.Language);
// var syntaxFacts = languageServices.GetService<ISyntaxFactsService>();
// if (!syntaxFacts.IsBindableToken(token))
// {
// return SpecializedCollections.EmptyEnumerable<ISymbol>();
// }
//
// var semanticFacts = languageServices.GetService<ISemanticFactsService>();
//
// return GetSymbolsEnumerable(
// semanticModel, semanticFacts, syntaxFacts,
// token, bindLiteralsToUnderlyingType, cancellationToken)
// .WhereNotNull()
// .Select(MapSymbol);
// }
private static ISymbol MapSymbol(ISymbol symbol)
{
return symbol.IsConstructor() && symbol.ContainingType.IsAnonymousType
? symbol.ContainingType
: symbol;
}
示例4: FilterAndCreateSpansAsync
private async Task<IEnumerable<DocumentHighlights>> FilterAndCreateSpansAsync(
IEnumerable<ReferencedSymbol> references, Solution solution, IImmutableSet<Document> documentsToSearch, ISymbol symbol, CancellationToken cancellationToken)
{
references = references.FilterUnreferencedSyntheticDefinitions();
references = references.FilterNonMatchingMethodNames(solution, symbol);
references = references.FilterToAliasMatches(symbol as IAliasSymbol);
if (symbol.IsConstructor())
{
references = references.Where(r => r.Definition.OriginalDefinition.Equals(symbol.OriginalDefinition));
}
var additionalReferences = new List<Location>();
foreach (var document in documentsToSearch)
{
additionalReferences.AddRange(await GetAdditionalReferencesAsync(document, symbol, cancellationToken).ConfigureAwait(false));
}
return await CreateSpansAsync(solution, symbol, references, additionalReferences, documentsToSearch, cancellationToken).ConfigureAwait(false);
}
示例5: TryClassifySymbol
private bool TryClassifySymbol(
NameSyntax name,
ISymbol symbol,
SemanticModel semanticModel,
CancellationToken cancellationToken,
out ClassifiedSpan classifiedSpan)
{
if (symbol != null)
{
// see through using aliases
if (symbol.Kind == SymbolKind.Alias)
{
symbol = (symbol as IAliasSymbol).Target;
}
else if (symbol.IsConstructor() && name.IsParentKind(SyntaxKind.Attribute))
{
symbol = symbol.ContainingType;
}
}
if (name.IsVar &&
IsInVarContext(name))
{
var alias = semanticModel.GetAliasInfo(name, cancellationToken);
if (alias == null || alias.Name != "var")
{
if (!IsSymbolCalledVar(symbol))
{
// We bound to a symbol. If we bound to a symbol called "var" then we want to
// classify this appropriately as a type. Otherwise, we want to classify this as
// a keyword.
classifiedSpan = new ClassifiedSpan(name.Span, ClassificationTypeNames.Keyword);
return true;
}
}
}
if (symbol != null)
{
// Use .Equals since we can't rely on object identity for constructed types.
if (symbol is ITypeSymbol)
{
var classification = GetClassificationForType((ITypeSymbol)symbol);
if (classification != null)
{
var token = name.GetNameToken();
classifiedSpan = new ClassifiedSpan(token.Span, classification);
return true;
}
}
}
classifiedSpan = default(ClassifiedSpan);
return false;
}
示例6: OriginalSymbolsMatch
internal static bool OriginalSymbolsMatch(
ISymbol searchSymbol,
ISymbol symbolToMatch,
Solution solution,
Compilation searchSymbolCompilation,
Compilation symbolToMatchCompilation,
CancellationToken cancellationToken)
{
if (symbolToMatch == null)
{
return false;
}
if (OriginalSymbolsMatchCore(searchSymbol, symbolToMatch, solution, searchSymbolCompilation, symbolToMatchCompilation, cancellationToken))
{
return true;
}
if (searchSymbol.Kind == SymbolKind.Namespace && symbolToMatch.Kind == SymbolKind.Namespace)
{
// if one of them is a merged namespace symbol and other one is its constituent namespace symbol, they are equivalent.
var namespace1 = (INamespaceSymbol)searchSymbol;
var namespace2 = (INamespaceSymbol)symbolToMatch;
var namespace1Count = namespace1.ConstituentNamespaces.Length;
var namespace2Count = namespace2.ConstituentNamespaces.Length;
if (namespace1Count != namespace2Count)
{
if ((namespace1Count > 1 &&
namespace1.ConstituentNamespaces.Any(n => NamespaceSymbolsMatch(n, namespace2, solution, cancellationToken))) ||
(namespace2Count > 1 &&
namespace2.ConstituentNamespaces.Any(n2 => NamespaceSymbolsMatch(namespace1, n2, solution, cancellationToken))))
{
return true;
}
}
}
if (searchSymbol.Kind == SymbolKind.NamedType && symbolToMatch.IsConstructor())
{
return OriginalSymbolsMatch(searchSymbol, symbolToMatch.ContainingType, solution, searchSymbolCompilation, symbolToMatchCompilation, cancellationToken);
}
return false;
}
示例7: Format
private string Format(ISymbol symbol)
{
if (symbol is ITypeSymbol || symbol is INamespaceSymbol)
{
return FormatTypeOrNamespace((INamespaceOrTypeSymbol)symbol);
}
if (symbol.MatchesKind(SymbolKind.Alias, SymbolKind.Local, SymbolKind.Parameter))
{
return Format(symbol.GetSymbolType());
}
var containingType = FormatTypeOrNamespace(symbol.ContainingType);
var name = symbol.ToDisplayString(NameFormat);
if (symbol.IsConstructor())
{
return string.Format("{0}.#ctor", containingType);
}
if (symbol.GetTypeArguments().Any())
{
return string.Format("{0}.{1}``{2}", containingType, name, symbol.GetTypeArguments().Length);
}
return string.Format("{0}.{1}", containingType, name);
}
示例8: TryGetMethodReference
public bool TryGetMethodReference(ISymbol semanticMethod, out IMethodReference cciMethod) {
Contract.Requires(semanticMethod == null || semanticMethod.Kind == SymbolKind.Method);
Contract.Ensures(!Contract.Result<bool>() || Contract.ValueAtReturn(out cciMethod) != null);
cciMethod = null;
#region Check input
if (semanticMethod == null) {
return false;
}
#endregion
#region Check cache
if (ContractsPackageAccessor.Current.VSOptionsPage.Caching)
if (_semanticMembersToCCIMethods.TryGetValue(semanticMethod, out cciMethod))
return (!(cciMethod is Dummy)) && cciMethod != null;
#endregion
#region Set up our working cci method
var workingCciMethod = new Microsoft.Cci.MutableCodeModel.MethodReference();
#endregion
#region Set the intern factory
workingCciMethod.InternFactory = Host.InternFactory;
#endregion
#region Get calling conventions
workingCciMethod.CallingConvention = CSharpToCCIHelper.GetCallingConventionFor(semanticMethod);
#endregion
#region Get containing type reference
ITypeReference containingType;
if (!TryGetTypeReference(semanticMethod.ContainingType, out containingType))
goto ReturnFalse;
workingCciMethod.ContainingType = containingType;
#endregion
#region Get return type reference
if (semanticMethod.IsConstructor())
workingCciMethod.Type = this.Host.PlatformType.SystemVoid;
else {
ITypeReference returnType;
if (!TryGetTypeReference(semanticMethod.ReturnType(), out returnType))
goto ReturnFalse;
workingCciMethod.Type = returnType;
}
#endregion
#region Get name
if (!semanticMethod.IsConstructor() && semanticMethod.Name == null) goto ReturnFalse;
workingCciMethod.Name = Host.NameTable.GetNameFor(semanticMethod.IsConstructor()?".ctor":semanticMethod.Name);
#endregion
#region Get generic param count
if (semanticMethod.TypeParameters().IsDefault)
workingCciMethod.GenericParameterCount = 0;
else
workingCciMethod.GenericParameterCount = (ushort)semanticMethod.TypeParameters().Length;
#endregion
#region Get parameter references
List<IParameterTypeInformation> cciParameters;
if (semanticMethod.Parameters().IsDefault) goto ReturnFalse;
Contract.Assume(semanticMethod.Parameters().Length <= ushort.MaxValue, "Should be a postcondition?");
if (!TryGetParametersList(semanticMethod.Parameters(), out cciParameters))
goto ReturnFalse;
workingCciMethod.Parameters = cciParameters;
#endregion
#region Get the assembly reference (this also ensures the assembly gets loaded properly)
IAssemblyReference assemblyReference;
TryGetAssemblyReference(semanticMethod.ContainingAssembly, out assemblyReference);
#endregion
cciMethod = workingCciMethod;
return true;
#region ReturnFalse:
ReturnFalse:
cciMethod = Dummy.MethodReference;
if (ContractsPackageAccessor.Current.VSOptionsPage.Caching)
_semanticMembersToCCIMethods[semanticMethod] = cciMethod;
return false;
#endregion
}
示例9: FormatSymbol
public override string FormatSymbol(ISymbol symbol)
{
if (symbol is ITypeSymbol || symbol is INamespaceSymbol)
{
return FormatNamespaceOrTypeSymbol((INamespaceOrTypeSymbol)symbol);
}
if (symbol.MatchesKind(SymbolKind.Alias, SymbolKind.Local, SymbolKind.Parameter))
{
return FormatSymbol(symbol.GetSymbolType());
}
var containingType = FormatNamespaceOrTypeSymbol(symbol.ContainingType);
var name = symbol.ToDisplayString(NameFormat);
if (symbol.IsConstructor())
{
return $"{containingType}.#ctor";
}
if (symbol.GetTypeArguments().Any())
{
return $"{containingType}.{name}``{symbol.GetTypeArguments().Length}";
}
return $"{containingType}.{name}";
}
示例10: GetDisplayName
private static string GetDisplayName(ISymbol symbol)
{
return symbol.IsConstructor() ? symbol.ContainingType.Name : symbol.Name;
}
示例11: WouldNavigateToSymbol
public bool WouldNavigateToSymbol(ISymbol symbol, Solution solution, out string filePath, out int lineNumber, out int charOffset)
{
if (WouldNotifyToSpecificSymbol(symbol, solution, out filePath, out lineNumber, out charOffset))
{
return true;
}
// If the symbol being considered is a constructor and no third parties choose to
// navigate to the constructor, then try the constructor's containing type.
if (symbol.IsConstructor() && WouldNotifyToSpecificSymbol(symbol.ContainingType, solution, out filePath, out lineNumber, out charOffset))
{
return true;
}
filePath = null;
lineNumber = 0;
charOffset = 0;
return false;
}
示例12: TryThirdPartyNavigation
private static bool TryThirdPartyNavigation(ISymbol symbol, Solution solution, ITypeSymbol containingTypeSymbol)
{
// Allow third parties to navigate to all symbols except types/constructors
// if we are navigating from the corresponding type.
if (containingTypeSymbol != null &&
(symbol is ITypeSymbol || symbol.IsConstructor()))
{
var candidateTypeSymbol = symbol is ITypeSymbol
? symbol
: symbol.ContainingType;
if (containingTypeSymbol == candidateTypeSymbol)
{
// We are navigating from the same type, so don't allow third parties to perform the navigation.
// This ensures that if we navigate to a class from within that class, we'll stay in the same file
// rather than navigate to, say, XAML.
return false;
}
}
var symbolNavigationService = solution.Workspace.Services.GetService<ISymbolNavigationService>();
// Notify of navigation so third parties can intercept the navigation
return symbolNavigationService.TrySymbolNavigationNotify(symbol, solution);
}
示例13: GetSearchName
private static string GetSearchName(ISymbol symbol)
{
if (symbol.IsConstructor() || symbol.IsStaticConstructor())
{
return symbol.ContainingType.Name;
}
else if (symbol.IsIndexer() && symbol.Name == WellKnownMemberNames.Indexer)
{
return "this";
}
return symbol.Name;
}