private IEnumerable <GeneratorInfo> GetGeneratorsFromContainer(PolygonGeneratorProvider generatorProvider) => generatorProvider.GetGenerators() .Select(g => new GeneratorInfo(this, (g.GetType() .GetCustomAttributes(typeof(FriendlyNameAttribute), true) .FirstOrDefault() as FriendlyNameAttribute)?.FriendlyName ?? g.GetType().Name, g));
public PolygonManagementViewModel(PolygonGeneratorProvider generatorProvider = null, IDialogHandler dialogHandler = null, PolygonClipper clipper = null, AreaCalculator areaCalculator = null) { Polygons = new ObservableCollection <Polygon>(); DialogHandler = dialogHandler; Clipper = clipper; AreaCalculator = areaCalculator; GenerateAndAddPolygonCommand = new DelegateCommand( GenerateAndAddPolygon, () => SelectedPolygonGenerator != null); ClipPolygonsCommand = new DelegateCommand( ClipPolygons, () => Polygons.Count == 2 && Clipper != null); Polygons.CollectionChanged += (_, __) => ClipPolygonsCommand.RaiseCanExecuteChanged(); CalculateAreaForSelectedPolygonCommand = new DelegateCommand( CalculateAreaForSelectedPolygon, () => SelectedPolygon != null && !IsCalculatingArea && AreaCalculator != null); CancelAreaCalculationCommand = new DelegateCommand( () => CancelSource.Cancel(), () => IsCalculatingArea); if (generatorProvider != null) { Generators = GetGeneratorsFromContainer(generatorProvider); SelectedPolygonGenerator = Generators.LastOrDefault()?.Generator; } MouseCommand = new DelegateCommand <Polygon>((x) => SelectedPolygon = x); }