当前位置: 首页>>代码示例>>C#>>正文


C# IFormatter.Format方法代码示例

本文整理汇总了C#中IFormatter.Format方法的典型用法代码示例。如果您正苦于以下问题:C# IFormatter.Format方法的具体用法?C# IFormatter.Format怎么用?C# IFormatter.Format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IFormatter的用法示例。


在下文中一共展示了IFormatter.Format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Format

        /// <inheritdoc />
        public string Format(object obj, IFormatter formatter)
        {
            Type type = obj.GetType();
            PropertyInfo keyProperty = type.GetProperty("Key");
            PropertyInfo valueProperty = type.GetProperty("Value");

            object key = keyProperty.GetValue(obj, null);
            object value = valueProperty.GetValue(obj, null);

            return string.Concat(formatter.Format(key), ": ", formatter.Format(value));
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:12,代码来源:KeyValuePairFormattingRule.cs

示例2: FormatMessage

        public override string FormatMessage(IFormatter<object> formatter)
        {
            if(ActualValue == null)
                return string.Format(ExpectMessages.EqualFormat, formatter.Format(null), formatter.Format(ExpectedString));
            var n = ActualString.IndexOfDifference(ExpectedString);
            var displayActual = formatter.Format(Center(ActualString, n, DisplayWidth));
            var displayExpected = formatter.Format(Center(ExpectedString, n, DisplayWidth));

            var format = string.Format("{0}\n{1}\n{2}^", Preamble, MessageFormat,
                new string('-', displayActual.IndexOfDifference(displayExpected) + ExpectMessages.EqualFormat.IndexOf('{')));
            return string.Format(format, displayActual, displayExpected);
        }
开发者ID:drunkcod,项目名称:Cone,代码行数:12,代码来源:StringEqualExpect.cs

示例3: Print

        public void Print(Client client, IFormatter formatter)
        {
            var result = formatter.Format(client);

            Console.WriteLine(result);

            // class Print does nto suit format strings, so to keep OOP principles
            // we create StringBasicFormat - a class only to format string when we need it
        }
开发者ID:cap7ainjack,项目名称:OOP-Csharp,代码行数:9,代码来源:Printer.cs

示例4: Format

        /// <inheritdoc />
        public string Format(object obj, IFormatter formatter)
        {
            var enumerable = (IEnumerable)obj;

            var str = new StringBuilder();
            str.Append('[');

            bool first = true;
            foreach (object value in enumerable)
            {
                if (first)
                    first = false;
                else
                    str.Append(", ");

                str.Append(formatter.Format(value));
            }

            str.Append(']');
            return str.ToString();
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:22,代码来源:EnumerableFormattingRule.cs

示例5: FormatExpression

 public virtual string FormatExpression(IFormatter<Expression> formatter)
 {
     return formatter.Format(body);
 }
开发者ID:kitofr,项目名称:Cone,代码行数:4,代码来源:BooleanExpect.cs

示例6: ToString

 public string ToString(IFormatter<object> formatter)
 {
     return formatter.Format(Value);
 }
开发者ID:kitofr,项目名称:Cone,代码行数:4,代码来源:BooleanExpect.cs

示例7: FormatActual

 public virtual string FormatActual(IFormatter<object> formatter)
 {
     return formatter.Format(Actual);
 }
开发者ID:drunkcod,项目名称:Cone,代码行数:4,代码来源:MemberMethodExpect.cs

示例8: Format

 static void Format(IFormatter f) => Console.WriteLine(f.Format(1, 2, 3));
开发者ID:ufcpp,项目名称:UfcppSample,代码行数:1,代码来源:Program.cs

示例9: FormatExpected

 public override string FormatExpected(IFormatter<object> formatter)
 {
     return string.Format(methodDisplay(arguments), formatter.Format(arguments[0]));
 }
开发者ID:drunkcod,项目名称:Cone,代码行数:4,代码来源:StringMethodExpect.cs

示例10: Setup

 public void Setup()
 {
     _baseDate = DateTime.Now;
     _numberOfObjects = 10;
     _objectsToFormat = new List<DummyObject>();
     for (int i = 0; i < _numberOfObjects; i++)
     {
         _objectsToFormat.Add(new DummyObject()
                                  {
                                      SomeInt = i,
                                      SomeString = i.ToString(),
                                      SomeDateTime = _baseDate.AddDays(i),
                                      CompositeObj = new DummyObject() {SomeInt = 10 + i}
                                  });
     }
     _formatter = new Formatter<DummyObject>()
         .With(y => y.SomeInt, 0, 5, y => y.ToString("00000"))
         .With(y => y.SomeString, 2, 6, y => y.ToString().PadLeft(6, '_'))
         .With(y => y.SomeDateTime, 1, 8, y => y.ToString(_dateFormat))
         .WithDelimiter(";");
     _result = _formatter.Format(_objectsToFormat);
 }
开发者ID:mastoj,项目名称:TJ.FileFormatter,代码行数:22,代码来源:FormatterTests.cs

示例11: FormatRecursive

        private static string FormatRecursive(object obj, IFormatter formatter)
        {
            Type objType = obj.GetType();

            var result = new StringBuilder();
            result.Append('{');
            result.Append(objType);
            result.Append(": ");

            var accessors = new List<KeyValuePair<string, Func<object, object>>>();
            foreach (FieldInfo field in objType.GetFields(BindingFlags.Instance | BindingFlags.Public))
            {
                accessors.Add(new KeyValuePair<string, Func<object, object>>(field.Name, field.GetValue));
            }

            foreach (PropertyInfo property in objType.GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                PropertyInfo capturedProperty = property; // avoid unintended variable capture in the lambda.
                if (property.CanRead && property.GetIndexParameters().Length == 0)
                    accessors.Add(new KeyValuePair<string, Func<object, object>>(property.Name,
                        x => capturedProperty.GetValue(x, null)));
            }

            accessors.Sort((a, b) => a.Key.CompareTo(b.Key));

            for (int i = 0; i < accessors.Count; i++)
            {
                object value;
                try
                {
                    value = accessors[i].Value(obj);
                }
                catch (Exception)
                {
                    continue;
                }

                if (i != 0)
                    result.Append(", ");

                result.Append(accessors[i].Key);
                result.Append(" = ");
                result.Append(formatter.Format(value));
            }

            result.Append('}');
            return result.ToString();
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:48,代码来源:StructuralFormattingRule.cs

示例12: Format

 /// <inheritdoc />
 public string Format(object obj, IFormatter formatter)
 {
     var entry = (DictionaryEntry)obj;
     return string.Concat(formatter.Format(entry.Key), ": ", formatter.Format(entry.Value));
 }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:6,代码来源:DictionaryEntryFormattingRule.cs

示例13: FormatExpected

 public override string FormatExpected(IFormatter<object> formatter) {
     return string.Format("url ending with {0}", formatter.Format(arguments[1]));
 }
开发者ID:Rklasens,项目名称:DataBoss,代码行数:3,代码来源:CustomMethodExpectProviderSample.cs

示例14: FormatRecord

 // This method takes an object that supports the IFormatter
 // interface. It will call that object's Format() method.
 private static void FormatRecord(IFormatter record)
 {
     record.Format();
 }
开发者ID:Meowse,项目名称:student1,代码行数:6,代码来源:Interfaces.cs

示例15: Print

 public void Print(string name, IFormatter formatter)
 {
     Console.WriteLine(formatter.Format(name));
 }
开发者ID:nok32,项目名称:Web-Services-and-Cloud,代码行数:4,代码来源:Printer.cs


注:本文中的IFormatter.Format方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。