本文整理汇总了C#中INamespaceOrTypeSymbol类的典型用法代码示例。如果您正苦于以下问题:C# INamespaceOrTypeSymbol类的具体用法?C# INamespaceOrTypeSymbol怎么用?C# INamespaceOrTypeSymbol使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
INamespaceOrTypeSymbol类属于命名空间,在下文中一共展示了INamespaceOrTypeSymbol类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Visit
private void Visit(INamespaceOrTypeSymbol type)
{
foreach (var method in type.GetMembers().OfType<IMethodSymbol>())
{
Visit(method);
}
}
示例2: SuppressDefaultTupleElements
/// <summary>
/// If container is a tuple type, any of its tuple element which has a friendly name will cause
/// the suppression of the corresponding default name (ItemN).
/// In that case, Rest is also removed.
/// </summary>
protected static ImmutableArray<ISymbol> SuppressDefaultTupleElements(
INamespaceOrTypeSymbol container, ImmutableArray<ISymbol> symbols)
{
if (container?.IsType != true)
{
return symbols;
}
var type = (ITypeSymbol)container;
if (!type.IsTupleType)
{
return symbols;
}
var tuple = (INamedTypeSymbol)type;
var elementNames = tuple.TupleElementNames;
if (elementNames.IsDefault)
{
return symbols;
}
// TODO This should be revised once we have a good public API for tuple fields
// See https://github.com/dotnet/roslyn/issues/13229
var fieldsToRemove = elementNames.Select((n, i) => IsFriendlyName(i, n) ? "Item" + (i + 1) : null)
.Where(n => n != null).Concat("Rest").ToSet();
return symbols.WhereAsArray(
s => s.Kind != SymbolKind.Field ||
elementNames.Contains(s.Name) ||
!fieldsToRemove.Contains(s.Name));
}
示例3: CompareTo
public static int CompareTo(this INamespaceOrTypeSymbol n1, INamespaceOrTypeSymbol n2)
{
var names1 = s_namespaceOrTypeToNameMap.GetValue(n1, s_getNamePartsCallBack);
var names2 = s_namespaceOrTypeToNameMap.GetValue(n2, s_getNamePartsCallBack);
return CompareNameParts(names1, names2);
}
示例4: CompareTo
public static TypeDiff CompareTo(this INamespaceOrTypeSymbol symbol, INamespaceOrTypeSymbol comparedTo)
{
var result = new TypeDiff();
result.Original = symbol;
result.ComparedTo = comparedTo;
result.MethodDifferences = symbol.GetAllContractMembers().FullOuterJoin(comparedTo.GetAllContractMembers(), SymbolComparer.Instance, (a, b) => a.CompareTo(b));
return result;
}
示例5: AddNamespaceOrTypeDeclarationAsync
public static Task<Document> AddNamespaceOrTypeDeclarationAsync(Solution solution, INamespaceSymbol destination, INamespaceOrTypeSymbol namespaceOrType, CodeGenerationOptions options = default(CodeGenerationOptions), CancellationToken cancellationToken = default(CancellationToken))
{
try {
return (Task<Document>)addNamespaceOrTypeDeclarationAsyncMethod.Invoke (null, new object[] { solution, destination, namespaceOrType, options != null ? options.Instance : null, cancellationToken });
} catch (TargetInvocationException ex) {
ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
return null;
}
}
示例6: GetNameParts
private static void GetNameParts(INamespaceOrTypeSymbol namespaceOrTypeSymbol, List<string> result)
{
if (namespaceOrTypeSymbol == null || (namespaceOrTypeSymbol.IsNamespace && ((INamespaceSymbol)namespaceOrTypeSymbol).IsGlobalNamespace))
{
return;
}
GetNameParts(namespaceOrTypeSymbol.ContainingNamespace, result);
result.Add(namespaceOrTypeSymbol.Name);
}
示例7: dfs_through_members
private void dfs_through_members(TreeNodeCollection treenode, INamespaceOrTypeSymbol symbol)
{
if (symbol != null && symbol.GetMembers() != null)
foreach (var el in symbol.GetMembers()) {
var cur = el as INamespaceOrTypeSymbol;
if (cur != null) {
treenode.Add(cur.Name.ToString());
dfs_through_members(treenode[treenode.Count - 1].Nodes, cur);
}
}
}
示例8: SuppressDefaultTupleElements
/// <summary>
/// If container is a tuple type, any of its tuple element which has a friendly name will cause
/// the suppression of the corresponding default name (ItemN).
/// In that case, Rest is also removed.
/// </summary>
protected static ImmutableArray<ISymbol> SuppressDefaultTupleElements(
INamespaceOrTypeSymbol container, ImmutableArray<ISymbol> symbols)
{
var namedType = container as INamedTypeSymbol;
if (namedType?.IsTupleType != true)
{
// container is not a tuple
return symbols;
}
//return tuple elements followed by other members that are not fields
return ImmutableArray<ISymbol>.CastUp(namedType.TupleElements).
Concat(symbols.WhereAsArray(s => s.Kind != SymbolKind.Field));
}
示例9: TryGetAliasSymbol
public static bool TryGetAliasSymbol(SemanticModel semanticModel, int namespaceId, INamespaceOrTypeSymbol targetSymbol, out IAliasSymbol aliasSymbol)
{
// TODO: given semantic model must be not speculative semantic model for now.
// currently it can't be checked since it is not exposed to common layer yet.
// once exposed, this method itself will make sure it use original semantic model
aliasSymbol = null;
if (!s_treeAliasMap.TryGetValue(semanticModel.Compilation, out var treeMap) ||
!treeMap.TryGetValue((semanticModel.SyntaxTree, namespaceId), out var symbolMap))
{
return false;
}
symbolMap.TryGetValue(targetSymbol, out aliasSymbol);
return true;
}
示例10: CompareTo
public static int CompareTo(this INamespaceOrTypeSymbol n1, INamespaceOrTypeSymbol n2)
{
var names1 = s_namespaceOrTypeToNameMap.GetValue(n1, GetNameParts);
var names2 = s_namespaceOrTypeToNameMap.GetValue(n2, GetNameParts);
for (var i = 0; i < Math.Min(names1.Count, names2.Count); i++)
{
var comp = names1[i].CompareTo(names2[i]);
if (comp != 0)
{
return comp;
}
}
return names1.Count - names2.Count;
}
示例11: Resolve
private static IEnumerable<INamedTypeSymbol> Resolve(
SymbolKeyReader reader,
INamespaceOrTypeSymbol container,
string metadataName,
int arity,
TypeKind typeKind,
bool isUnboundGenericType,
ImmutableArray<SymbolKeyResolution> typeArguments)
{
var types = container.GetTypeMembers(GetName(metadataName), arity);
var result = InstantiateTypes(
reader.Compilation, reader.IgnoreAssemblyKey, types, arity, typeArguments);
return isUnboundGenericType
? result.Select(t => t.ConstructUnboundGenericType())
: result;
}
示例12: FindTypeCompilations
public void FindTypeCompilations(INamespaceOrTypeSymbol symbol)
{
if (symbol.IsNamespace)
{
foreach (var member in (symbol as INamespaceSymbol).GetMembers())
{
FindTypeCompilations(member);
}
}
else
{
var typeSymbol = symbol as ITypeSymbol;
foreach (var attribute in typeSymbol.GetAttributes())
{
if (attribute.AttributeClass.Name == "AssemblyNeutralAttribute")
{
_typeCompilationContexts.Add(new TypeCompilationContext(this, typeSymbol));
}
}
}
}
示例13: GetFullMetadataName
public static string GetFullMetadataName(INamespaceOrTypeSymbol symbol)
{
ISymbol s = symbol;
var sb = new StringBuilder(s.MetadataName);
var last = s;
s = s.ContainingSymbol;
while (!IsRootNamespace(s))
{
if (s is ITypeSymbol && last is ITypeSymbol)
{
sb.Insert(0, '+');
}
else
{
sb.Insert(0, '.');
}
sb.Insert(0, s.MetadataName);
s = s.ContainingSymbol;
}
return sb.ToString();
}
示例14: GetDescription
protected abstract string GetDescription(INamespaceOrTypeSymbol symbol, SemanticModel semanticModel, SyntaxNode root);
示例15: GetAliasForSymbol
public static IAliasSymbol GetAliasForSymbol(INamespaceOrTypeSymbol symbol, SyntaxToken token, SemanticModel semanticModel, CancellationToken cancellationToken)
{
var originalSemanticModel = semanticModel.GetOriginalSemanticModel();
if (!originalSemanticModel.SyntaxTree.HasCompilationUnitRoot)
{
return null;
}
IAliasSymbol aliasSymbol;
var namespaceId = GetNamespaceIdForAliasSearch(semanticModel, token, cancellationToken);
if (namespaceId < 0)
{
return null;
}
if (!AliasSymbolCache.TryGetAliasSymbol(originalSemanticModel, namespaceId, symbol, out aliasSymbol))
{
// add cache
AliasSymbolCache.AddAliasSymbols(originalSemanticModel, namespaceId, semanticModel.LookupNamespacesAndTypes(token.SpanStart).OfType<IAliasSymbol>());
// retry
AliasSymbolCache.TryGetAliasSymbol(originalSemanticModel, namespaceId, symbol, out aliasSymbol);
}
return aliasSymbol;
}