/// <summary> /// Initializes a new instance of the <see cref="StrategyNameGenerator"/>. /// </summary> /// <param name="strategy">Strategy.</param> public StrategyNameGenerator(Strategy strategy) { if (strategy == null) throw new ArgumentNullException("strategy"); _strategy = strategy; _strategy.SecurityChanged += () => { if (_selectors.Contains("Security")) Refresh(); }; _strategy.PortfolioChanged += () => { if (_selectors.Contains("Portfolio")) Refresh(); }; ShortName = new string(_strategy.GetType().Name.Where(char.IsUpper).ToArray()); _formatter = Smart.CreateDefaultSmartFormat(); _formatter.SourceExtensions.Add(new Source(_formatter, new Dictionary<string, string> { { "FullName", _strategy.GetType().Name }, { "ShortName", ShortName }, })); _selectors = new SynchronizedSet<string>(); AutoGenerateStrategyName = true; Pattern = "{ShortName}{Security:_{0.Security}|}{Portfolio:_{0.Portfolio}|}"; }
public static SmartFormatter CreateDefaultSmartFormat() { // Register all default extensions here: var result = new SmartFormatter(); // Add all extensions: // Note, the order is important; the extensions // will be executed in this order: var listFormatter = new ListFormatter(result); result.AddExtensions( (ISource)listFormatter, new ReflectionSource(result), new DictionarySource(result), // These default extensions reproduce the String.Format behavior: new DefaultSource(result) ); result.AddExtensions( (IFormatter)listFormatter, new PluralLocalizationFormatter("en"), new ConditionalFormatter(), new TimeFormatter("en"), new DefaultFormatter() ); return result; }
public void SetUp() { formatter = Smart.CreateDefaultSmartFormat(); formatter.ErrorAction = ErrorAction.ThrowError; formatter.FormatterExtensions.Insert(0, ExpectedFormatter.Instance); expected = Substitute.For<Expected>(); expected.Value.Returns("value"); }
public Source(SmartFormatter formatter, Dictionary<string, string> values) { if (formatter == null) throw new ArgumentNullException("formatter"); if (values == null) throw new ArgumentNullException("values"); formatter.Parser.AddAlphanumericSelectors(); formatter.Parser.AddAdditionalSelectorChars("_"); formatter.Parser.AddOperators("."); _values = values; }
public static SmartFormatter CreateDefaultSmartFormat() { // Register all default extensions here: var result = new SmartFormatter(); return result .AddExtensions( new PluralLocalizationFormatter("en"), new ListFormatter(result), new ConditionalFormatter(), new TimeFormatter("en"), new ReflectionSource(result), new DictionarySource(result), new DefaultSource(result), new DefaultFormatter() ); }
static Localizer() { formatter = new SmartFormatter(); var listFormatter = new ListFormatter(formatter); formatter.AddExtensions( listFormatter, new DefaultSource(formatter) ); formatter.AddExtensions( listFormatter, new PluralLocalizationFormatter("en"), new ChooseFormatter(), new DefaultFormatter() ); }
public static SmartFormatter CreateDefaultSmartFormat() { // Register all default extensions here: var result = new SmartFormatter(); // Add all extensions: // Note, the order is important; the extensions // will be executed in this order: result.AddExtensions( new ListFormatter(result), new PluralLocalizationFormatter("en"), new ConditionalFormatter(), new TimeFormatter("en"), new ReflectionSource(result), new DictionarySource(result), // These default extensions reproduce the String.Format behavior: new DefaultSource(result), new DefaultFormatter() ); return(result); }
public static SmartFormatter CreateDefaultSmartFormat() { // Register all default extensions here: var formatter = new SmartFormatter(); // Add all extensions: // Note, the order is important; the extensions // will be executed in this order: var listFormatter = new ListFormatter(formatter); // sources for specific types must be in the list before ReflectionSource formatter.AddExtensions( (ISource)listFormatter, // ListFormatter MUST be first new DictionarySource(formatter), new ValueTupleSource(formatter), new SmartObjectsSource(formatter), new JsonSource(formatter), new XmlSource(formatter), new ReflectionSource(formatter), // The DefaultSource reproduces the string.Format behavior: new DefaultSource(formatter) ); formatter.AddExtensions( (IFormatter)listFormatter, new PluralLocalizationFormatter("en"), new ConditionalFormatter(), new TimeFormatter("en"), new XElementFormatter(), new ChooseFormatter(), new SubStringFormatter(), new DefaultFormatter() ); return(formatter); }