Example #1
0
        internal MailSmartFormatter() : base()
        {
            // Register all default extensions here:
            // Add all extensions:
            // Note, the order is important; the extensions
            // will be executed in this order:
            var listFormatter = new ListFormatter(this);

            base.AddExtensions(
                (ISource)listFormatter,
                new ReflectionSource(this),
                new DictionarySource(this),
                // new XmlSource(this),
                // These default extensions reproduce the String.Format behavior:
                new DefaultSource(this)
                );
            base.AddExtensions(
                (IFormatter)listFormatter,
                new PluralLocalizationFormatter("en"),
                new ConditionalFormatter(),
                new TimeFormatter("en"),
                //new XElementFormatter(),
                new ChooseFormatter(),
                new DefaultFormatter()
                );
        }
Example #2
0
        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),
                new XmlSource(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 XElementFormatter(),
                new ChooseFormatter(),
                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(
                listFormatter, // ListFormatter MUST be first
                new DictionarySource(formatter),
                new ValueTupleSource(formatter),
                new XmlSource(formatter),
                new ReflectionSource(formatter),

                // The DefaultSource reproduces the string.Format behavior:
                new DefaultSource(formatter)
                );
            formatter.AddExtensions(
                listFormatter,
                new PluralLocalizationFormatter(),
                new ConditionalFormatter(),
                new TimeFormatter(),
                new XElementFormatter(),
                new ChooseFormatter(),
                new SubStringFormatter(),
                new IsMatchFormatter(),
                new DefaultFormatter()
                );

            return(formatter);
        }
Example #4
0
        internal MailSmartFormatter() : base()
        {
            // Register all default extensions here:
            // Add all extensions:
            // Note, the order is important; the extensions
            // will be executed in this order:
            var listFormatter = new ListFormatter(this);

            AddExtensions(
                (ISource)listFormatter, // ListFormatter MUST be first
                new DictionarySource(this),
                new ValueTupleSource(this),
                new SmartObjectsSource(this),
                new JsonSource(this),
                //new XmlSource(this),
                new ReflectionSource(this),
                // The DefaultSource reproduces the string.Format behavior:
                new DefaultSource(this)
                );
            AddExtensions(
                (IFormatter)listFormatter,
                new PluralLocalizationFormatter("en"),
                new ConditionalFormatter(),
                new TimeFormatter("en"),
                //new XElementFormatter(),
                new ChooseFormatter(),
                new DefaultFormatter()
                );

            Templates = new TemplateFormatter(this);
            AddExtensions(Templates);
        }
Example #5
0
        public void Objects_Not_Implementing_IList_Are_Not_Processed()
        {
            var items = new[] { "one", "two", "three" };

            var formatter     = new SmartFormatter();
            var listFormatter = new ListFormatter(formatter);

            formatter.SourceExtensions.Add(listFormatter);
            formatter.FormatterExtensions.Add(listFormatter);
            formatter.SourceExtensions.Add(new DefaultSource(formatter));
            formatter.FormatterExtensions.Add(new DefaultFormatter());

            Assert.AreEqual("one, two, and three", formatter.Format("{0:list:{}|, |, and }", new object[] { items }));
            Assert.Throws <FormattingException>(() => formatter.Format("{0:list:{}|, |, and }", new { Index = 100 })); // no formatter found
        }
Example #6
0
        public void TestShouldFormatToNumberedListSequentially()
        {
            // Given
            var list = new List <string> {
                "the first", "THE SECOND", "tHe Third"
            };

            // When
            var result = ListFormatter.FormatSequential(list);

            // Then
            Assert.AreEqual("1. The first", result[0]);
            Assert.AreEqual("2. The second", result[1]);
            Assert.AreEqual("3. The third", result[2]);
        }
Example #7
0
        static Localizer()
        {
            formatter = new SmartFormatter();

            var listFormatter = new ListFormatter(formatter);

            formatter.AddExtensions(
                listFormatter,
                new DefaultSource(formatter)
                );

            formatter.AddExtensions(
                listFormatter,
                new CustomPluralLocalizationFormatter("en"),
                new ChooseFormatter(),
                new DefaultFormatter()
                );
        }
Example #8
0
        public void CreateIndex()
        {
            StringBuilder optAttribute = new StringBuilder();

            if (_indexAttributes.IsUnique)
            {
                optAttribute.AppendFormat("{0} ", UniqueKwd);
            }
            if (_indexAttributes.IsClustered)
            {
                optAttribute.AppendFormat("{0} ", ClusteredKwd);
            }
            string columnList = ListFormatter.ToString(_indexAttributes.IndexColumns, ", ", ColNameFmt);

            string createIndexDDL = string.Format(CreateIndexSqlFmt, optAttribute.ToString(), _indexAttributes.IndexName, _indexAttributes.TableName, columnList);

            using (SqlCommand cmd = new SqlCommand(createIndexDDL, _connection))
            {
                cmd.ExecuteNonQuery();
            }
        }
        public static void GetCreateValueExpression(object value,
                                                    ClrSimpleTypeInfo typeDef,
                                                    CodeExpressionCollection collection)
        {
            if (value == null)
            {
                collection.Add(new CodePrimitiveExpression(value));
                return;
            }

            switch (typeDef.Variety)
            {
            case XmlSchemaDatatypeVariety.List:
                string str = ListFormatter.ToString(value);
                collection.Add(new CodePrimitiveExpression(str));
                break;

            case XmlSchemaDatatypeVariety.Atomic:
                if (value is string)
                {
                    collection.Add(new CodePrimitiveExpression(value));
                }
                else
                {
                    collection.Add(CreateTypedValueExpression(typeDef.InnerType.Datatype, value));
                }
                break;

            case XmlSchemaDatatypeVariety.Union:
                GetCreateUnionValueExpression(value, typeDef as UnionSimpleTypeInfo, collection);
                break;

            default:
                break;
            }
        }
Example #10
0
 protected TorrentSpecificListCommandBase()
 {
     _formatter = new ListFormatter<T>(PrintTable, PrintList);
 }
Example #11
0
 protected ListCommandBase()
 {
     _formatter = new ListFormatter <T>(PrintTable, PrintList);
 }