• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# IFormatProvider类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中IFormatProvider的典型用法代码示例。如果您正苦于以下问题:C# IFormatProvider类的具体用法?C# IFormatProvider怎么用?C# IFormatProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



IFormatProvider类属于命名空间,在下文中一共展示了IFormatProvider类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Parse

	// Parsing methods.
	public static short Parse(String s, NumberStyles style,
							  IFormatProvider provider)
			{
				NumberParser.ValidateIntegerStyle(style);
				return Convert.ToInt16(NumberParser.ParseInt32
					(s, style, NumberFormatInfo.GetInstance(provider), 32768));
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:8,代码来源:Int16.cs


示例2: LessThanEqualTo

        public bool LessThanEqualTo(string version, IFormatProvider provider)
        {
            Version v = ConvertToVersion(version, provider);

            return this._major < v.Major || (this._major == v.Major && this._minor < v.Minor) ||
                   (this._major == v.Major && this._minor == v.Minor && this._build < v._build);
        }
开发者ID:EngageSoftware,项目名称:Engage-Publish,代码行数:7,代码来源:Version.cs


示例3: DebuggerWriter

 /// <summary>
 /// Initializes a new instance of the <see cref="DebuggerWriter"/> class with the specified level, category and format Repository.
 /// </summary>
 /// <param name="level">A description of the importance of the messages.</param>
 /// <param name="category">The category of the messages.</param>
 /// <param name="formatRepository">An <see cref="IFormatRepository"/> object that controls formatting.</param>
 public DebuggerWriter(int level, string category, IFormatProvider formatRepository)
     : base(formatRepository)
 {
     this.level = level;
     this.category = category;
     isOpen = true;
 }
开发者ID:shaimuli,项目名称:Simple.SAMS,代码行数:13,代码来源:DebuggerWriter.cs


示例4: MongoDBCapped

        /// <summary>
        /// Adds a sink that writes log events as documents to a MongoDb database.
        /// </summary>
        /// <param name="loggerConfiguration">The logger configuration.</param>
        /// <param name="databaseUrl">The URL of a created MongoDB collection that log events will be written to.</param>
        /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
        /// <param name="cappedMaxSizeMb">Max total size in megabytes of the created capped collection. (Default: 50mb)</param>
        /// <param name="cappedMaxDocuments">Max number of documents of the created capped collection.</param>
        /// <param name="collectionName">Name of the collection. Default is "log".</param>
        /// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param>
        /// <param name="period">The time to wait between checking for event batches.</param>
        /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
        /// <returns>Logger configuration, allowing configuration to continue.</returns>
        /// <exception cref="ArgumentNullException">A required parameter is null.</exception>
        public static LoggerConfiguration MongoDBCapped(
            this LoggerSinkConfiguration loggerConfiguration,
            string databaseUrl,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
            long cappedMaxSizeMb = 50,
            long? cappedMaxDocuments = null,
            string collectionName = null,
            int batchPostingLimit = MongoDBSink.DefaultBatchPostingLimit,
            TimeSpan? period = null,
            IFormatProvider formatProvider = null)
        {
            if (loggerConfiguration == null) throw new ArgumentNullException("loggerConfiguration");
            if (databaseUrl == null) throw new ArgumentNullException("databaseUrl");

            var optionsBuilder = CollectionOptions.SetCapped(true).SetMaxSize(cappedMaxSizeMb * 1024 * 1024);

            if (cappedMaxDocuments.HasValue)
            {
                optionsBuilder = optionsBuilder.SetMaxDocuments(cappedMaxDocuments.Value);
            }

            var defaultedPeriod = period ?? MongoDBSink.DefaultPeriod;
            return loggerConfiguration.Sink(
                new MongoDBSink(
                    databaseUrl,
                    batchPostingLimit,
                    defaultedPeriod,
                    formatProvider,
                    collectionName ?? MongoDBSink.DefaultCollectionName,
                    optionsBuilder),
                restrictedToMinimumLevel);
        }
开发者ID:BugBusted,项目名称:serilog,代码行数:46,代码来源:LoggerConfigurationMongoDBExtensions.cs


示例5: FormatHelper

        /// <summary>
        /// Default ctor
        /// </summary>
        internal FormatHelper(StringBuilder result, IFormatProvider provider, string format, params object[] args)
        {
            this.result = result;
            this.provider = provider;
            this.format = format;
            this.args = args;
            if (format == null)
                throw new ArgumentNullException("format");
            if (args == null)
                throw new ArgumentNullException("args");

            if (this.result == null)
            {
                /* Try to approximate the size of result to avoid reallocations */
                int i, len;

                len = 0;
                for (i = 0; i < args.Length; ++i)
                {
                    string s = args[i] as string;
                    if (s != null)
                        len += s.Length;
                    else
                        break;
                }
                if (i == args.Length)
                    this.result = new StringBuilder(len + format.Length);
                else
                    this.result = new StringBuilder();
            }
        }
开发者ID:nguyenkien,项目名称:api,代码行数:34,代码来源:FormatHelper.cs


示例6: StringWriter

 public StringWriter(StringBuilder sb, IFormatProvider formatProvider) : base(formatProvider) {
     if (sb==null)
         throw new ArgumentNullException("sb", Environment.GetResourceString("ArgumentNull_Buffer"));
     Contract.EndContractBlock();
     _sb = sb;
     _isOpen = true;
 }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:7,代码来源:stringwriter.cs


示例7: FormatWith

        public static string FormatWith(this string format, IFormatProvider provider, params object[] args)
        {
            if (format == null)
                throw new ArgumentNullException("format");

            return string.Format(provider, format, args);
        }
开发者ID:tiloc,项目名称:fhir-net-api,代码行数:7,代码来源:StringExtensions.cs


示例8: Format

        public string Format(string format, object arg, IFormatProvider formatProvider)
        {
            if (!(arg is DateTime)) throw new NotSupportedException();

            var dt = (DateTime)arg;

            string suffix;

            if (dt.Day % 10 == 1)
            {
                suffix = "st";
            }
            else if (dt.Day % 10 == 2)
            {
                suffix = "nd";
            }
            else if (dt.Day % 10 == 3)
            {
                suffix = "rd";
            }
            else
            {
                suffix = "th";
            }

            return string.Format("{1}{2} {0:MMMM} {0:yyyy}", arg, dt.Day, suffix);
        }
开发者ID:parrymike,项目名称:myMDS_Dev,代码行数:27,代码来源:CustomDateProvider.cs


示例9: DebugWriter

 /// <summary>
 /// Initializes a new instance of the <see cref="DebugWriter"/> class with the specified level, category and format provider.
 /// </summary>
 /// <param name="level">A description of the importance of the messages.</param>
 /// <param name="category">The category of the messages.</param>
 /// <param name="formatProvider">An <see cref="IFormatProvider"/> object that controls formatting.</param>
 public DebugWriter(int level, string category, IFormatProvider formatProvider)
     : base(formatProvider)
 {
     this.level = level;
     this.category = category;
     this.isOpen = true;
 }
开发者ID:BookSwapSteve,项目名称:Exceptionless,代码行数:13,代码来源:DebugWriter.cs


示例10: ToNaturalString

        /// <summary>
        /// Converts the value of a <see cref="TimeSpan"/> object to its equivalent natural string representation.
        /// </summary>
        /// <param name="timeSpan">A <see cref="TimeSpan"/>.</param>
        /// <param name="provider">An <see cref="IFormatProvider"/>.</param>
        /// <returns>The natural string representation of the <see cref="TimeSpan"/>.</returns>
        public static string ToNaturalString(this TimeSpan timeSpan, IFormatProvider provider)
        {
            List<string> parts = new List<string>();

            // Days
            if (timeSpan.Days != 0)
            {
                parts.Add(GetStringWithUnits(timeSpan.Days, "Day", provider));
            }

            // Hours
            if (timeSpan.Hours != 0 || parts.Count != 0)
            {
                parts.Add(GetStringWithUnits(timeSpan.Hours, "Hour", provider));
            }

            // Minutes
            if (timeSpan.Minutes != 0 || parts.Count != 0)
            {
                parts.Add(GetStringWithUnits(timeSpan.Minutes, "Minute", provider));
            }

            // Seconds
            parts.Add(GetStringWithUnits(timeSpan.Seconds, "Second", provider));

            // Join parts
            return string.Join(
                Resources.ResourceManager.GetString("TimeSpanExtensionsUnitSeparator", provider),
                parts);
        }
开发者ID:lilbro1062000,项目名称:Hourglass,代码行数:36,代码来源:TimeSpanExtensions.cs


示例11: LoggrSink

        /// <summary>
        /// Construct a sink that saves logs to the specified storage account. Properties are being send as data and the level is used as tag.
        /// </summary>
        ///  <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
        /// <param name="logKey">The log key as found on the loggr website.</param>
        /// <param name="apiKey">The api key as found on the loggr website.</param>
        /// <param name="useSecure">Use a SSL connection. By default this is false.</param>
        /// <param name="userNameProperty">Specifies the property name to read the username from. By default it is UserName.</param>
        public LoggrSink(IFormatProvider formatProvider, string logKey, string apiKey, bool useSecure = false, string userNameProperty = "UserName")
        {
            _formatProvider = formatProvider;
            _userNameProperty = userNameProperty;

            _client = new LogClient(logKey, apiKey, useSecure);
        }
开发者ID:nberardi,项目名称:serilog,代码行数:15,代码来源:LoggrSink.cs


示例12: ToInt16

        /// <summary>
        ///     Converts the given string to a Int16.
        /// </summary>
        /// <exception cref="ArgumentNullException">The value can not be null.</exception>
        /// <exception cref="ArgumentNullException">The format provider can not be null.</exception>
        /// <param name="value">The string to convert.</param>
        /// <param name="formatProvider">The format provider.</param>
        /// <returns>Returns the converted Int16.</returns>
        public static Int16 ToInt16( this String value, IFormatProvider formatProvider )
        {
            value.ThrowIfNull( nameof( value ) );
            formatProvider.ThrowIfNull( nameof( formatProvider ) );

            return Convert.ToInt16( value, formatProvider );
        }
开发者ID:MannusEtten,项目名称:Extend,代码行数:15,代码来源:String.ToInt16.cs


示例13: ToString

        /// <summary>
        /// Returns the string representation of this object</summary>
        /// <param name="format">Optional standard numeric format string for a floating point number.
        /// If null, "R" is used for round-trip support in case the string is persisted.
        /// http://msdn.microsoft.com/en-us/library/vstudio/dwhawy9k(v=vs.100).aspx </param>
        /// <param name="formatProvider">Optional culture-specific formatting provider. This is usually
        /// a CultureInfo object or NumberFormatInfo object. If null, the current culture is used.
        /// Use CultureInfo.InvariantCulture for persistence.</param>
        /// <returns>String representation of object</returns>
        public string ToString(string format, IFormatProvider formatProvider)
        {
            string listSeparator = StringUtil.GetNumberListSeparator(formatProvider);

            // For historic reasons, use "R" for round-trip support, in case this string is persisted.
            if (format == null)
                format = "R";

            return String.Format(
                "{1}{0} {2}{0} {3}{0} {4}{0} {5}{0} {6}{0} {7}{0} {8}{0} {9}{0} {10}{0} {11}{0} {12}",
                listSeparator,
                m_ctrlPoints[0].X.ToString(format, formatProvider),
                m_ctrlPoints[0].Y.ToString(format, formatProvider),
                m_ctrlPoints[0].Z.ToString(format, formatProvider),
                m_ctrlPoints[1].X.ToString(format, formatProvider),
                m_ctrlPoints[1].Y.ToString(format, formatProvider),
                m_ctrlPoints[1].Z.ToString(format, formatProvider),
                m_ctrlPoints[2].X.ToString(format, formatProvider),
                m_ctrlPoints[2].Y.ToString(format, formatProvider),
                m_ctrlPoints[2].Z.ToString(format, formatProvider),
                m_ctrlPoints[3].X.ToString(format, formatProvider),
                m_ctrlPoints[3].Y.ToString(format, formatProvider),
                m_ctrlPoints[3].Z.ToString(format, formatProvider));

        }
开发者ID:JanDeHud,项目名称:LevelEditor,代码行数:34,代码来源:BezierCurve.cs


示例14: ToString

        public string ToString(string format, IFormatProvider formatProvider)
        {
            if (format.Contains(",") || format.Contains(";"))
            {
                string[] fieldArray = format.Split(';')[0].Split(',');
                string separator = format.Split(';')[1];

                List<string> fieldResults = new List<string>();

                foreach (string field in fieldArray)
                {
                    if (_dictionary.HasValueFor(field.Trim()))
                    {
                        fieldResults.Add(_dictionary.ValueFor(field.Trim()).ToString());
                    }
                }

                return string.Join(separator, fieldResults.ToArray());
            }
            else if (_dictionary.HasValueFor(format))
            {
                object value = _dictionary.ValueFor(format);

                return value == null ? null : value.ToString();
            }

            return null;
        }
开发者ID:gregorypilar,项目名称:interlace,代码行数:28,代码来源:FormattingPropertyDictionaryWrapper.cs


示例15: Format

 public string Format(string format, object arg, IFormatProvider formatProvider)
 {
     if (arg != null)
     {
         string fmt;
         switch (format)
         {
             case "S": // second
                 fmt = String.Format(new HMSFormatter("{0} seconds", "{0} second"), "{0}", arg);
                 break;
             case "M": // minute
                 fmt = String.Format(new HMSFormatter("{0} minutes", "{0} minute"), "{0}", arg);
                 break;
             case "H": // hour
                 fmt = String.Format(new HMSFormatter("{0} hours", "{0} hour"), "{0}", arg);
                 break;
             case "D": // day
                 fmt = String.Format(new HMSFormatter("{0} days", "{0} day"), "{0}", arg);
                 break;
             default:
                 // plural/ singular
                 fmt = String.Format((int)arg > 1 ? _plural : _singular, arg);  // watch the cast to int here...
                 break;
         }
         return fmt;
     }
     return String.Format(format, arg);
 }
开发者ID:hexafluoride,项目名称:byteflood,代码行数:28,代码来源:HMSFormatter.cs


示例16: Format

        /// <summary>
        /// Converts the value of a specified object to an equivalent string
        /// representation using specified format and the invariant-culture
        /// formatting information.
        /// </summary>
        /// <param name="format">
        /// A format string containing formatting specifications.
        /// </param>
        /// <param name="arg">An object to format.</param>
        /// <param name="formatProvider">
        /// An IFormatProvider object that supplies format information about
        /// the current instance.
        /// </param>
        /// <returns>
        /// The string representation of the value of arg, formatted as specified
        /// by format and the invariant-culture.
        /// </returns>
        public string Format(string format, object arg, IFormatProvider formatProvider)
        {
            if (format == null)
            {
                var convertible = arg as IConvertible;
                if (convertible != null)
                {
                    switch (convertible.GetTypeCode())
                    {
                        case TypeCode.Boolean:
                            return GetBool((bool)arg);

                        case TypeCode.DateTime:
                            return GetDateTime((DateTime)arg);

                        case TypeCode.Decimal:
                            return GetDecimal((decimal)arg);

                        case TypeCode.Double:
                            return GetFloatingPoint((double)arg);

                        case TypeCode.Single:
                            return GetFloatingPoint((float)arg);
                    }
                }
            }

            var formatter = new StringBuilder();
            formatter.AppendFormat(CultureInfo.InvariantCulture, "{0:" + format + "}", arg);
            return formatter.ToString();
        }
开发者ID:karun10,项目名称:KML2SQL,代码行数:48,代码来源:KmlFormatter.cs


示例17: Log4Net

 public static LoggerConfiguration Log4Net(
     this LoggerSinkConfiguration loggerConfiguration,
     LogEventLevel restrictedToMinimumLevel,
     IFormatProvider formatProvider)
 {
     return loggerConfiguration.Log4Net(null, restrictedToMinimumLevel, formatProvider);
 }
开发者ID:modulexcite,项目名称:serilog-sinks-log4net,代码行数:7,代码来源:LoggerConfigurationLog4NetExtensions.cs


示例18: ToDateTime

 /// <summary>
 /// Parses this TextValue and converts it to a DateTime value.
 /// </summary>
 /// <returns>The parsed DateTime or January 1 1970 if the TextValue was not possible to parse.</returns>
 public override DateTime ToDateTime(IFormatProvider provider)
 {
     DateTime dt;
     if (!DateTime.TryParse(InternalValue, out dt))
         dt = new DateTime(1970, 1, 1);
     return dt;
 }
开发者ID:patrikha,项目名称:Hansoft-ObjectWrapper,代码行数:11,代码来源:TextValue.cs


示例19: NamedFormat

        public static string NamedFormat(string format, IFormatProvider provider, object formatObject, bool throwExceptionIfNotFound)
        {
            if (format == null)
                throw new ArgumentNullException("format");

            Regex r = new Regex(@"(?<start>\{)+(?<property>[\w\.\[\]]+)(?<format>:[^}]+)?(?<end>\})+",
                RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);

            List<object> formatValues = new List<object>();
            string rewrittenFormat = r.Replace(format, delegate(Match m)
            {
                Group startGroup = m.Groups["start"];
                Group propertyGroup = m.Groups["property"];
                Group formatGroup = m.Groups["format"];
                Group endGroup = m.Groups["end"];

                string propertyName = propertyGroup.Value;

                formatValues.Add(GetObjectValue(propertyName, formatObject, throwExceptionIfNotFound));

                return new string('{', startGroup.Captures.Count) + (formatValues.Count - 1) + formatGroup.Value
                  + new string('}', endGroup.Captures.Count);
            });

            return string.Format(provider, rewrittenFormat, formatValues.ToArray());
        }
开发者ID:amazing-andrew,项目名称:Quartz.TextToSchedule,代码行数:26,代码来源:NamedFormatHelper.cs


示例20: ToString

        public static String ToString(Double value, SIUnit unit, String format, IFormatProvider formatProvider)
        {
            var unitStr = unit.Symbol;

            if (value != 0)
            {
                var scale = 0;
                var log10 = Math.Log10(value);

                if (log10 < 0)
                {
                    value = MakeLarger(value, unit, out scale);
                }
                else if (log10 > 0)
                {
                    value = MakeSmaller(value, unit, out scale);
                }

                if (scale != 0)
                {
                    unitStr = Prefixes[scale].Symbol + unit.Symbol;
                }
            }

            return String.Format(formatProvider, "{0} {1}", value, unitStr);
        }
开发者ID:razaraz,项目名称:Pscx,代码行数:26,代码来源:SIPrefixes.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IFormatter类代码示例发布时间:2022-05-24
下一篇:
C# IFormFile类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap