本文整理汇总了C#中Compilation.GetSymbolsWithName方法的典型用法代码示例。如果您正苦于以下问题:C# Compilation.GetSymbolsWithName方法的具体用法?C# Compilation.GetSymbolsWithName怎么用?C# Compilation.GetSymbolsWithName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Compilation
的用法示例。
在下文中一共展示了Compilation.GetSymbolsWithName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAllEntityTypesFromDbContext
public static IEnumerable<INamedTypeSymbol> GetAllEntityTypesFromDbContext(Compilation compilation, out INamedTypeSymbol dbContextTypeSymbol)
{
var allTypeSymbols = compilation.GetSymbolsWithName(s => true, SymbolFilter.Type).Cast<INamedTypeSymbol>();
dbContextTypeSymbol = allTypeSymbols.Single(t => t.BaseType.Name == "DbContext");
var entityTypeSymbols = dbContextTypeSymbol
.GetMembers()
.Where(m => m.Kind == SymbolKind.Property)
.Cast<IPropertySymbol>()
.Where(p => p.Type.Name == "DbSet")
.Select(p => p.Type)
.Cast<INamedTypeSymbol>()
.Select(t => t.TypeArguments[0])
.Cast<INamedTypeSymbol>();
return entityTypeSymbols;
}
示例2: GetTypeByName
public static INamedTypeSymbol GetTypeByName(string className, Compilation compilation)
{
var type = compilation.GetTypeByMetadataName(className);
// Another way to access the info
if (type == null)
{
Func<string, bool> pred = s => { return s.Equals(className); };
var symbols = compilation.GetSymbolsWithName(pred, SymbolFilter.Type);
if (symbols.Count() > 0)
{
type = symbols.First() as INamedTypeSymbol;
}
}
return type;
}