private AddProperties ( IEnumerable |
||
symbols | IEnumerable |
|
regCallback | Action |
|
return | void |
/// <summary> /// Builds the EF-specific view of the current semantic model /// </summary> /// <returns>false if no DbContext or known entity types were discovered, true otherwise</returns> public bool Build() { //Bail immediately if EntityFramework is not referenced if (!_context.SemanticModel .Compilation .ReferencedAssemblyNames .Any(asm => asm.Name == "EntityFramework" && asm.Version.Major == 6)) { return false; } var typeSymbols = _context.SemanticModel .LookupSymbols(_context.Node .GetLocation() .SourceSpan .Start) .OfType<INamedTypeSymbol>(); var symbols = typeSymbols.Where(t => t.UltimatelyDerivesFromDbContext()); _dbContextSymbols = new ReadOnlyCollection<INamedTypeSymbol>(symbols.ToList()); if (_dbContextSymbols.Count == 0) return false; //TODO: Need to follow any related types that hang off of the primary entities (referenced via DbSet<T>) var entityTypes = _dbContextSymbols.SelectMany(dbc => { var dbSetProps = dbc.GetMembers() .Where(m => m.Kind == SymbolKind.Property) .Cast<IPropertySymbol>() .Where(t => t.IsDbSetProperty()); return dbSetProps; }) .Select(p => p.Type) .OfType<INamedTypeSymbol>() .Where(t => t.TypeArguments.Length == 1) .Select(t => t.TypeArguments.First()) .OfType<INamedTypeSymbol>(); _entityTypeSymbols = new ReadOnlyCollection<INamedTypeSymbol>(entityTypes.ToList()); _clsInfo = new Dictionary<ITypeSymbol, EFCodeFirstClassInfo>(); _propertiesToCls = new Dictionary<string, List<EFCodeFirstClassInfo>>(); foreach (var clsSymbol in _entityTypeSymbols) { var clsSymbols = clsSymbol.GetMembers() .Where(m => m.Kind == SymbolKind.Property) .Cast<IPropertySymbol>(); var clsInfo = new EFCodeFirstClassInfo(clsSymbol); clsInfo.AddProperties(clsSymbols, (sym) => { if (!_propertiesToCls.ContainsKey(sym.Name)) _propertiesToCls[sym.Name] = new List<EFCodeFirstClassInfo>(); _propertiesToCls[sym.Name].Add(clsInfo); }); _clsInfo[clsSymbol] = clsInfo; } return _clsInfo.Count > 0; }
/// <summary> /// Builds the EF-specific view of the current semantic model /// </summary> /// <returns>false if no DbContext or known entity types were discovered, true otherwise</returns> public bool Build() { //Bail immediately if EntityFramework is not referenced if (!_context.SemanticModel .Compilation .ReferencedAssemblyNames .Any(asm => asm.Name == "EntityFramework" && asm.Version.Major == 6)) { return(false); } var typeSymbols = _context.SemanticModel .LookupSymbols(_context.Node .GetLocation() .SourceSpan .Start) .OfType <INamedTypeSymbol>(); var symbols = typeSymbols.Where(t => t.UltimatelyDerivesFromDbContext()); _dbContextSymbols = new ReadOnlyCollection <INamedTypeSymbol>(symbols.ToList()); if (_dbContextSymbols.Count == 0) { return(false); } //TODO: Need to follow any related types that hang off of the primary entities (referenced via DbSet<T>) var entityTypes = _dbContextSymbols.SelectMany(dbc => { var dbSetProps = dbc.GetMembers() .Where(m => m.Kind == SymbolKind.Property) .Cast <IPropertySymbol>() .Where(t => t.IsDbSetProperty()); return(dbSetProps); }) .Select(p => p.Type) .OfType <INamedTypeSymbol>() .Where(t => t.TypeArguments.Length == 1) .Select(t => t.TypeArguments.First()) .OfType <INamedTypeSymbol>(); _entityTypeSymbols = new ReadOnlyCollection <INamedTypeSymbol>(entityTypes.ToList()); _clsInfo = new Dictionary <ITypeSymbol, EFCodeFirstClassInfo>(); _propertiesToCls = new Dictionary <string, List <EFCodeFirstClassInfo> >(); foreach (var clsSymbol in _entityTypeSymbols) { var clsSymbols = clsSymbol.GetMembers() .Where(m => m.Kind == SymbolKind.Property) .Cast <IPropertySymbol>(); var clsInfo = new EFCodeFirstClassInfo(clsSymbol); clsInfo.AddProperties(clsSymbols, (sym) => { if (!_propertiesToCls.ContainsKey(sym.Name)) { _propertiesToCls[sym.Name] = new List <EFCodeFirstClassInfo>(); } _propertiesToCls[sym.Name].Add(clsInfo); }); _clsInfo[clsSymbol] = clsInfo; } return(_clsInfo.Count > 0); }