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


C# IFormatProvider.GetFormat方法代码示例

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


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

示例1: ToString

        public string ToString(string format, IFormatProvider formatProvider)
        {
            if (formatProvider == null)
            {
                return this.ToString();
            }

            ICustomFormatter fmt = formatProvider.GetFormat(this.GetType()) as ICustomFormatter;

            if (fmt != null)
            {
                return fmt.Format(format, this, formatProvider);
            }

            switch (format)
            {
                case "V":
                    return this.Value;
                case "O":
                    return this.Operator.ToString();
                case "G":
                default:
                    return this.ToString();
            }
        }
开发者ID:jeremyshantz,项目名称:bmc-remedy-search,代码行数:25,代码来源:Clauses.cs

示例2: GetTimeTextInfo

        private TimeTextInfo GetTimeTextInfo(IFormatProvider provider)
        {
            if (provider != null)
            {
                // See if the provider can give us what we want:
                var timeTextInfo = (TimeTextInfo)provider.GetFormat(typeof (TimeTextInfo));
                if (timeTextInfo != null)
                {
                    return timeTextInfo;
                }

                // See if there is a rule for this culture:
                var cultureInfo = provider as CultureInfo;
                if (cultureInfo != null)
                {
                    timeTextInfo = CommonLanguagesTimeTextInfo.GetTimeTextInfo(cultureInfo.TwoLetterISOLanguageName);
                    // If cultureInfo was supplied, 
                    // we will always return, even if null:
                    return timeTextInfo;
                }
            }

            // Return the default if the provider couldn't provide:
            return CommonLanguagesTimeTextInfo.GetTimeTextInfo(defaultTwoLetterISOLanguageName);
        }
开发者ID:Avatarchik,项目名称:AnimatorAccess,代码行数:25,代码来源:TimeFormatter.cs

示例3: ToString

		public string ToString(string format, IFormatProvider formatProvider) {
			if (formatProvider != null) {
				ICustomFormatter fmt = formatProvider.GetFormat(this.GetType()) as ICustomFormatter;
				if (fmt != null)
					return fmt.Format(format, this, formatProvider);
			}

			switch (format) {
				case "g": {
						string s = Group.ToString("x4");
						string x = String.Empty;
						x += ((Mask & 0xf0000000) != 0) ? s[0] : 'x';
						x += ((Mask & 0x0f000000) != 0) ? s[1] : 'x';
						x += ((Mask & 0x00f00000) != 0) ? s[2] : 'x';
						x += ((Mask & 0x000f0000) != 0) ? s[3] : 'x';
						return x;
					}
				case "e": {
						string s = Element.ToString("x4");
						string x = String.Empty;
						x += ((Mask & 0x0000f000) != 0) ? s[0] : 'x';
						x += ((Mask & 0x00000f00) != 0) ? s[1] : 'x';
						x += ((Mask & 0x000000f0) != 0) ? s[2] : 'x';
						x += ((Mask & 0x0000000f) != 0) ? s[3] : 'x';
						return x;
					}
				case "G":
				default: {
						return String.Format("({0},{1})", this.ToString("g", null), this.ToString("e", null));
					}
			}
		}
开发者ID:ZeryZhang,项目名称:fo-dicom,代码行数:32,代码来源:DicomMaskedTag.cs

示例4: ToStringExtended

 /// <summary>
 /// An alternative for the ToString() method of DateTime to work around a problem with implementing custom formatters for DateTime objects
 /// The default implementation, even if given a good IFormatProvider implementation, would never call a custom formatter. It would
 /// still use the default formatter.
 /// </summary>
 /// <param name="dateTime">The date time object.</param>
 /// <param name="provider">The provider.</param>
 /// <param name="format">The format.</param>
 /// <returns></returns>
 public static string ToStringExtended(this DateTime dateTime, string format, IFormatProvider provider)
 {
     var formatter = provider.GetFormat(typeof(DateTimeFormatInfo)) as ICustomFormatter;
     if (formatter != null)
     {
         return formatter.Format(format, dateTime, provider);
     }
     throw new ArgumentException("The format provider argument did not return an instance that implements ICustomFormatter", "provider");
 }
开发者ID:slavo,项目名称:Stamp.Net,代码行数:18,代码来源:DateTimeExtensions.cs

示例5: GetInstance

		public static DateTimeFormatInfo GetInstance(IFormatProvider fp) {
			if (fp != null) {
				DateTimeFormatInfo dtf = (DateTimeFormatInfo)fp.GetFormat(typeof(DateTimeFormatInfo));
				if (dtf != null) {
					return dtf;
				}
			}

			return CurrentInfo;
		}
开发者ID:bradparks,项目名称:DotNetAnywhere,代码行数:10,代码来源:DateTimeFormatInfo.cs

示例6: Parse

        public decimal Parse(IFormatProvider provider, decimal defaultValue = default(decimal), bool round = false)
        {
            var result = _converter.Parse(provider, defaultValue);

            if (round)
            {
                provider = provider ?? CultureInfo.CurrentCulture;
                var numberFormat = (NumberFormatInfo)provider.GetFormat(typeof(NumberFormatInfo)) ?? CultureInfo.CurrentCulture.NumberFormat;
                return Math.Round(result, numberFormat.CurrencyDecimalDigits);
            }

            return result;
        }
开发者ID:brennanfee,项目名称:FluentConversions,代码行数:13,代码来源:CurrencyConversionsDefault.cs

示例7: Parse

        public decimal? Parse(IFormatProvider provider, bool round = false)
        {
            var result = _converter.Parse(provider);
            if (!result.HasValue)
                return null;

            if (round)
            {
                provider = provider ?? CultureInfo.CurrentCulture;
                var numberFormat = (NumberFormatInfo)provider.GetFormat(typeof(NumberFormatInfo)) ?? CultureInfo.CurrentCulture.NumberFormat;
                return Math.Round(result.Value, numberFormat.CurrencyDecimalDigits);
            }

            return result;
        }
开发者ID:brennanfee,项目名称:FluentConversions,代码行数:15,代码来源:CurrencyConversionsNullable.cs

示例8: SetDateTimeFormat

        /// <summary>
        /// Sets a DateTime formatter to be used for outputting the DateTime values
        /// </summary>
        /// <param name="formatProvider">Format provider</param>
        /// <returns>A Collapse instance, used for chaining</returns>
        public Collapse SetDateTimeFormat(IFormatProvider formatProvider)
        {
            if(formatProvider == null)
                throw new ArgumentNullException("formatProvider", "Format provider was not supplied.");

            DateTimeFormatInfo formatInfo =
                formatProvider.GetFormat(typeof(DateTimeFormatInfo)) as DateTimeFormatInfo;

            if (formatInfo == null)
                throw new DateTimeFormatInvalidException();

            SetDateTimeFormat(
                String.Format("{0} {1}", formatInfo.ShortDatePattern, formatInfo.LongTimePattern));

            return this;
        }
开发者ID:kornelijepetak,项目名称:collapse-xml,代码行数:21,代码来源:Collapse.Formatting.cs

示例9: NumberFormatInfo

		NumberFormatInfo(IFormatProvider provider)
	{
		if(provider == null)
		{
			return System.Globalization.NumberFormatInfo.CurrentInfo;
		}
		else
		{
			NumberFormatInfo nfi =
				(NumberFormatInfo) provider.GetFormat(
								typeof(System.Globalization.NumberFormatInfo));
			if(nfi != null)
			{
				return nfi;
			}
			else
			{
				return System.Globalization.NumberFormatInfo.CurrentInfo;
			}
		}
	}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:21,代码来源:Formatter.cs

示例10: ToInt32

    public int ToInt32(IFormatProvider provider)
    {
        bool toMinValue = true;

        if (provider != null)
        {
            TestFormatProvider format = provider.GetFormat(typeof(TestFormatProvider)) as TestFormatProvider;
            if ((format != null) && format.ToInt16MaxValue)
            {
                toMinValue = false;
            }
        }

        if (toMinValue)
        {
            return Int32.MinValue;
        }
        else
        {
            return Int32.MaxValue;
        }
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:22,代码来源:converttoint32_10.cs

示例11: ToString

        public string ToString(string format, IFormatProvider formatProvider)
        {
            if (formatProvider != null)
            {
                ICustomFormatter fmt = formatProvider.GetFormat(this.GetType()) as ICustomFormatter;
                if (fmt != null)
                {
                    return fmt.Format(format, this, formatProvider);
                }
            }

            switch (format)
            {
                case "n":
                    return Name;
                case "p":
                    return PhoneNumber;
                case "a":
                    return Name + PhoneNumber;
                default:
                    return Name;
            }
        }
开发者ID:hanoKim,项目名称:Effective,代码行数:23,代码来源:3_IFormatable.cs

示例12: ToJavaFormatString

        public static string ToJavaFormatString(string format, IFormatProvider provider, DateTimeKind kind, bool dateTimeOffset, out bool useInvariant, out bool foundDateTimeKind, out bool useUtc)
        {
            if (string.IsNullOrEmpty(format))
                format = "G";

            DateTimeFormatInfo dtfi = null;

            if (provider != null)
                dtfi = (DateTimeFormatInfo)provider.GetFormat(typeof(DateTimeFormatInfo));

            if (dtfi == null)
                dtfi = DateTimeFormatInfo.CurrentInfo;

            bool needsTranslation = true;

            if (format.Length == 1 && dtfi != null)
            {
                format = GetStandardPattern(format[0], dtfi, dateTimeOffset, out useUtc, out useInvariant, out needsTranslation);

                if (format == null)
                    throw new FormatException(
                        "format is not one of the format specifier characters defined for DateTimeFormatInfo");
            }
            else
            {
                useInvariant = false;
                useUtc = false;
            }

            if (needsTranslation)
                format = ConvertFormatStringNetToJava(format, kind, out foundDateTimeKind);
            else
                foundDateTimeKind = false;

            return format;
        }
开发者ID:sebastianhaba,项目名称:api,代码行数:36,代码来源:DateTimeFormatting.cs

示例13: Format

        public string Format(string format, object arg, IFormatProvider formatProvider)
        {
            if (formatProvider != null)
            {
                ICustomFormatter fmt = formatProvider.GetFormat(this.GetType()) as ICustomFormatter;
                if (fmt != null) { return fmt.Format(format, this, formatProvider); }
            }

            Question question = null;
            if (arg is Question)
            {
                question = arg as Question;
            }
            else
            {
                var questions = arg as Question[];
                question = questions.First(e => e.Key == format);
            }

            if (question.Value != null)
                return question.Value.ToString();

            return string.Format(format, "{0}", arg);
        }
开发者ID:Cellenza,项目名称:smart-apero,代码行数:24,代码来源:QuestionFormatter.cs

示例14: ToString

        public override string ToString(string format, IFormatProvider provider)
        {
            if (provider != null)
            {
                ICustomFormatter formatter = provider.GetFormat(GetType()) as ICustomFormatter;
                if (formatter != null)
                    return formatter.Format(format, this, provider);
            }

            var builder = new System.Text.StringBuilder();
            DoToString(builder, format, 0);

            return builder.ToString();
        }
开发者ID:andyhebear,项目名称:Continuum,代码行数:14,代码来源:VariableItem.cs

示例15: GetInstance

 public static NumberFormatInfo GetInstance(IFormatProvider formatProvider) {
     // Fast case for a regular CultureInfo
     NumberFormatInfo info;
     CultureInfo cultureProvider = formatProvider as CultureInfo;
     if (cultureProvider != null && !cultureProvider.m_isInherited) {
         info = cultureProvider.numInfo;
         if (info != null) {
             return info;
         }
         else {
             return cultureProvider.NumberFormat;
         }
     }
     // Fast case for an NFI;
     info = formatProvider as NumberFormatInfo;
     if (info != null) {
         return info;
     }
     if (formatProvider != null) {
         info = formatProvider.GetFormat(typeof(NumberFormatInfo)) as NumberFormatInfo;
         if (info != null) {
             return info;
         }
     }
     return CurrentInfo;
 }
开发者ID:l1183479157,项目名称:coreclr,代码行数:26,代码来源:NumberFormatInfo.cs


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