File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
RealTimeWeatherMonitoringApp/Application/Service Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 1+ using RealTimeWeatherMonitoringApp . Application . Common ;
2+ using RealTimeWeatherMonitoringApp . Application . Interfaces ;
3+ using RealTimeWeatherMonitoringApp . Application . Interfaces . Service ;
4+
5+ namespace RealTimeWeatherMonitoringApp . Application . Service ;
6+
7+ public class AutoParsingService < TResult > : IAutoParsingService < TResult >
8+ {
9+ private readonly List < IParsingStrategy < TResult > > _strategies = [ ] ;
10+ public void AddStrategy ( IParsingStrategy < TResult > strategy ) => _strategies . Add ( strategy ) ;
11+ public void RemoveStrategy ( IParsingStrategy < TResult > strategy ) => _strategies . Remove ( strategy ) ;
12+
13+ public ParsingResult < TResult > AutoParse ( string input )
14+ {
15+ foreach ( var strategy in _strategies )
16+ if ( strategy . TryParse ( input , out var result ) )
17+ return new ParsingResult < TResult > ( true , $ "Parsing succeeded with strategy '{ strategy } '")
18+ { Data = result } ;
19+
20+ return new ParsingResult < TResult > ( false , $ "No valid parsing strategy was found for input '{ input } '") ;
21+ }
22+ }
You can’t perform that action at this time.
0 commit comments