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


C# IFormatProvider类代码示例

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


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


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