/// <summary> /// Turns the argument into its formatted representation. /// </summary> /// <remarks> /// <para> /// This method turns the argument into its formatted representation. /// </para> /// <para> /// Method <see cref="ICustomFormatter.Format(String, Object, IFormatProvider)"/> /// is called if the argument is derived from <see cref="ICustomFormatter"/>. /// </para> /// <para> /// Method <see cref="IFormattable.ToString(String, IFormatProvider)"/> is called /// if the argument is derived from <see cref="IFormattable"/>. /// </para> /// <para> /// Method <see cref="Object.ToString()"/> is called in any other case.. /// </para> /// </remarks> /// <param name="token"> /// The token to be processed. /// </param> /// <param name="options"> /// The options to be used. /// </param> /// <param name="argument"> /// The argument to be formatted. /// </param> /// <returns> /// The argument in its formatted representation. /// </returns> private static String ToFormattedValue(this BaseToken token, Options options, Object argument) { if (token.Format.Length < 1) { return(argument.ToString()); } ICustomFormatter custom = null; if (options.Provider != null) { custom = options.Provider.GetFormat(typeof(ICustomFormatter)) as ICustomFormatter; } if (custom != null) { return(custom.Format(token.Format, argument, options.Provider)); } else if (argument is IFormattable helper) { return(helper.ToString(token.Format, options.Provider)); } else { return(argument.ToString()); } }
public string ToString(string format, IFormatProvider formatProvider) { if (formatProvider != null) { ICustomFormatter formatter = formatProvider.GetFormat(this.GetType()) as ICustomFormatter; if (formatter != null) { return(formatter.Format(format, this, formatProvider)); } } if (format == null) { format = "G"; } switch (format) { case "n": return(this.timeSpan.ToString(FormatPattern)); case "~": case "G": default: return("~" + this.timeSpan.ToString(FormatPattern)); } }
/// <summary>G prints something like "System.Void Smokey.Foo() instructions". /// F prints the instructions.</summary> /// <exception cref="System.ArgumentException">Thrown if the format string is invalid.</exception> public 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)); } } string result; switch (format) { case "F": result = DoGetFlatString(); break; case "": case "G": case null: result = string.Format("{0} Instructions", m_method); break; default: throw new ArgumentException(format + " isn't a valid TypedInstructionCollection format string"); } return(result); }
/// <summary> /// The ToString implementation. /// </summary> /// <param name="format">The format specifier to use, /// e.g. <b>Console.WriteLine(rule.ToString("n"));</b></param> /// <param name="provider">Allow clients to format output for their own types using /// [ICustomFormatter](https://msdn.microsoft.com/en-us/library/system.icustomformatter.aspx).</param> /// <returns>The formatted string.</returns> /// <exception cref="FormatException">thrown if an invalid format string is specified.</exception> /// \par Format specifiers: /// \arg \c G Default when not using a format specifier. /// \arg \c N Name - User's AccuRev principal name. /// \arg \c H Host - IP address of the host machine. /// \arg \c D Duration - Length of time the user has been logged on. public string ToString(string format, IFormatProvider provider) { if (provider != null) { ICustomFormatter fmt = provider.GetFormat(this.GetType()) as ICustomFormatter; if (fmt != null) { return(fmt.Format(format, this, provider)); } } if (String.IsNullOrEmpty(format)) { format = "G"; } switch (format.ToUpperInvariant()) { case "G": // default when not using a format specifier return($"{Name}, {Host}, {Duration}"); case "N": // user's AccuRev principal name return(Name); case "H": // IP address of the host machine return(Host); case "D": // length of time user has been logged on return(Duration.ToString()); default: throw new FormatException($"The {format} format string is not supported."); } }
string IFormattable.ToString(string value, IFormatProvider formatProvider) { if (value == null) { return(ToString(formatProvider)); } if (formatProvider != null) { ICustomFormatter cp = (ICustomFormatter)formatProvider.GetFormat(typeof(ICustomFormatter)); if (cp != null) { return(String.Format("sc#{0}{1} {2}{3} {4}{5} {6}", cp.Format(value, A, formatProvider), cp.Format(value, ',', formatProvider), cp.Format(value, R, formatProvider), cp.Format(value, ',', formatProvider), cp.Format(value, G, formatProvider), cp.Format(value, ',', formatProvider), cp.Format(value, B, formatProvider))); } } return(String.Format("sc#{0}{1} {2}{3} {4}{5} {6}", A.ToString(value, formatProvider), ','.ToString(formatProvider), R.ToString(value, formatProvider), ','.ToString(formatProvider), G.ToString(value, formatProvider), ','.ToString(formatProvider), B.ToString(value, formatProvider))); }
string ICustomFormatter.Format(string format, object arg, IFormatProvider formatProvider) { Func <string, object, IFormatProvider, string> formatter = null; if (arg != null) { for (Type type = arg.GetType(); type != null; type = type.BaseType) { if (_formatters.TryGetValue(type, out formatter)) { break; } } } if (formatter != null) { return(formatter(format, arg, _formatProvider)); } ICustomFormatter customFormatter = _formatProvider != null ? (ICustomFormatter)_formatProvider.GetFormat(typeof(ICustomFormatter)) : null; if (customFormatter != null) { return(customFormatter.Format(format, arg, _formatProvider)); } IFormattable formattable = arg as IFormattable; if (formattable != null) { return(formattable.ToString(format, _formatProvider)); } return(arg != null?arg.ToString() : string.Empty); }
/// <summary> /// The actual implementation of the \e ToString method. /// </summary> /// <param name="format">The format specifier to use, e.g. <b>Console.WriteLine(stream.ToString("lv"));</b></param> /// <param name="provider">Allow clients to format output for their own types using [ICustomFormatter](https://msdn.microsoft.com/en-us/library/system.icustomformatter.aspx).</param> /// <returns>The formatted string.</returns> /// <exception cref="FormatException">thrown if an invalid format string is specified.</exception> /// \par Format specifiers: /// \arg \c G Stream name. Default when not using a format specifier. /// \arg \c LV Long version (verbose). /// \arg \c I Stream ID number. /// \arg \c T [Stream type](@ref AcUtils#StreamType): \e unknown, \e normal, \e dynamic, \e regular, \e workspace, \e snapshot, \e passthru, \e passthrough, \e gated or \e staging. /// \arg \c BT Stream's basis time: snapshot stream creation or dynamic stream time basis. /// \arg \c C Time the stream was created. /// \arg \c BN Basis stream name. /// \arg \c BI Basis stream ID number. /// \arg \c D Depot name. /// \arg \c DY \e True if dynamic, \e False in the case of workspace, snapshot or passthrough. /// \arg \c H \e True if stream is hidden, \e False otherwise. /// \arg \c DG \e True if stream has a default group, \e False otherwise. public string ToString(string format, IFormatProvider provider) { if (provider != null) { ICustomFormatter fmt = provider.GetFormat(this.GetType()) as ICustomFormatter; if (fmt != null) { return(fmt.Format(format, this, provider)); } } if (String.IsNullOrEmpty(format)) { format = "G"; } switch (format.ToUpperInvariant()) { case "G": // stream name; default when not using a format specifier return(Name); // general format should be short since it can be called by anything case "LV": // long version (verbose) return($"{Name} ({ID}) {{{Type}}} {Time}{Environment.NewLine}" + $"Basis: {BasisName} ({BasisID}){Environment.NewLine}" + $"Depot: {Depot}, Hidden: {Hidden}{(Hidden ? String.Empty : ", HasDefaultGroup: " + HasDefaultGroup)}"); case "I": // stream's ID number return(ID.ToString()); case "T": // type of stream: unknown, normal, dynamic, regular, workspace, snapshot, passthru, passthrough, gated, staging return(Type.ToString()); case "BT": // stream's time basis return(Time.ToString()); case "C": // stream's creation time or last time its name, time basis or state (remove, reactivate, reparent) changed return(StartTime.ToString()); case "BN": // basis stream name return(BasisName); case "BI": // basis stream ID number return(BasisID.ToString()); case "D": // depot name return(Depot.ToString()); case "DY": // true if dynamic, false in the case of workspace, snapshot or passthrough return(IsDynamic.ToString()); case "H": // True if stream is hidden, False otherwise return(Hidden.ToString()); case "DG": // True if stream has a default group, False otherwise return(HasDefaultGroup.ToString()); default: throw new FormatException($"The {format} format string is not supported."); } }
/// <summary>Formats the value of the current instance using the specified format.</summary> /// <returns>The value of the current instance in the specified format.</returns> /// <param name="format">The format to use.-or- A null reference (Nothing in Visual Basic) to use the default format defined for the type of the <see cref="T:System.IFormattable" /> implementation. </param> /// <param name="formatProvider">The provider to use to format the value.-or- A null reference (Nothing in Visual Basic) to obtain the numeric format information from the current locale setting of the operating system. </param> public string ToString(string format, IFormatProvider formatProvider) { //Supported formats: C - compact, F - full, I - only id, J - json if (format == null) { format = "G"; } format = format.ToLower(); ICustomFormatter formatter = formatProvider?.GetFormat(GetType()) as ICustomFormatter; if (formatter != null) { return(formatter.Format(format, this, formatProvider)); } switch (format) { case "c": return(PrintC()); case "f": return(PrintF()); case "j": return(PrintJ()); //case "i": //case "g": default: return(PrintI()); } }
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)); }
private static void _GetDefaultOutput(object sender, ExtendFormatEventArgs e) { CustomFormatInfo info = e.FormatInfo; // Let's see if there are nested items: if (info.HasNested) { info.CustomFormatNested(); return; } // Let's do the default formatting: // We will try using IFormatProvider, IFormattable, and if all else fails, ToString. // (This code was adapted from the built-in String.Format code) if (info.Provider != null) { // Use the provider to see if a CustomFormatter is available: ICustomFormatter formatter = info.Provider.GetFormat(typeof(ICustomFormatter)) as ICustomFormatter; if (formatter != null) { info.Write(formatter.Format(info.Format, info.Current, info.Provider)); return; } } // Now try to format the object, using its own built-in formatting if possible: if (info.Current is IFormattable) { info.Write(((IFormattable)info.Current).ToString(info.Format, info.Provider)); } else { info.Write(info.Current.ToString()); } }
/// <summary> /// Formulate string. /// </summary> /// <param name="ctx"></param> /// <param name="argument"></param> /// <param name="format">string that contains the formatting, e.g. "X8"</param> /// <param name="result"></param> /// <returns></returns> public bool TryEvaluate(ref FunctionEvaluationContext ctx, object argument, object format, out object result) { if (argument == null) { result = null; return(false); } string formatStr = format?.ToString(); // Try custom format provider if (ctx.FormatProvider != null) { ICustomFormatter customFormatter__ = ctx.FormatProvider.GetFormat(typeof(ICustomFormatter)) as ICustomFormatter; if (customFormatter__ != null) { string custom_formatter_result = customFormatter__.Format(formatStr, argument, ctx.Culture); if (custom_formatter_result != null) { result = custom_formatter_result; return(true); } } } if (argument is Enum @enum) { string separator = null; if (formatStr == null || formatStr == "" || formatStr == "g" || formatStr == "G" || formatStr == "f" || formatStr == "F") { separator = ", "; } else if (formatStr == "|") { separator = formatStr; } else if (formatStr == " |") { separator = " | "; } if (separator != null) { LineString enum_string = ctx.EvaluateEnum(@enum, separator); if (enum_string.Value != null) { result = enum_string.Value; return(true); } } } if (formatStr != null && argument is IFormattable formattable) { result = formattable.ToString(formatStr, ctx.Culture); return(true); } if (ctx.Culture.GetFormat(typeof(ICustomFormatter)) is ICustomFormatter customFormatter_) { result = customFormatter_.Format(formatStr, argument, ctx.Culture); return(true); } result = ctx.Culture == null?String.Format("{0:" + formatStr + "}", argument) : String.Format(ctx.Culture, "{0:" + formatStr + "}", argument); return(true); }
/// <summary> /// Supports fml (First Middle Last), lfm (Last, First Middle) /// </summary> /// <param name="format"></param> /// <param name="formatProvider"></param> /// <returns></returns> public string ToString(string format, IFormatProvider formatProvider = null) { if (formatProvider != null) { ICustomFormatter fmt = formatProvider.GetFormat(this.GetType()) as ICustomFormatter; if (fmt != null) { return(fmt.Format(format, this, formatProvider)); } } switch (format) { case "lfm": return(String.Format("{0}, {1} {2}", this.LastName, this.FirstName, this.MiddleName)); case "lfMI": return(String.Format("{0}, {1} {2}.", this.LastName, this.FirstName, this.MiddleName.SubstringSafe(0, 1))); case "fMIl": return(String.Format("{0} {1}. {2}", this.FirstName, this.MiddleName.SubstringSafe(0, 1), this.LastName)); case "fl": return(String.Format("{0} {1}", this.FirstName, this.LastName)); case "fml": case "G": default: return(String.Format("{0} {1} {2}", this.FirstName, this.MiddleName, this.LastName)); } }
public string ToString(string aFormat, IFormatProvider aFormatProvider) { if (aFormatProvider != null) { ICustomFormatter formatter = aFormatProvider.GetFormat(this.GetType()) as ICustomFormatter; if (formatter != null) { return(formatter.Format(aFormat, this, aFormatProvider)); } } string ret = string.Empty; string format = aFormat != null ? aFormat : "full"; // switch (format) { case "full": ret = string.Format("0x{0} [{1}]", Hex, Binary); break; default: ret = iValue.ToString(aFormat, aFormatProvider); break; } // return(ret); }
public static string ToString(object target, string formatName) { if (target == null) { return(String.Empty); } if (!HasFormatterSpecified(target)) { Func <object, string> customFormatter = ChoGlobalObjectFormatters.GetObjectFormatHandler(target.GetType(), formatName); if (customFormatter != null) { return(customFormatter(target)); } else { ICustomFormatter formatter = ChoFormatProvider.Instance.GetFormat(target.GetType()) as ICustomFormatter; if (formatter != null) { return(formatter.Format(formatName, target, null)); } else { return(ToString(target)); } } } else { return(ToString(target)); } }
public string ToString(string formato, IFormatProvider proveedor) { if (proveedor != null) { ICustomFormatter formatter = proveedor.GetFormat(this.GetType()) as ICustomFormatter; if (formatter != null) { return(formatter.Format(formato, this, proveedor)); } } /*PropertiesMap map = new PropertiesMap(); * map.Add(FOCO, this.Focus, "", proveedor); * map.Add(POSICION, this.Position, "F3", proveedor); * map.Add(DIRECCION, this.Direction, "F3", proveedor); * map.Add(AMBIENTE, this.Ambient, "F3", proveedor); * map.Add(DIFUSO, this.Diffuse, "F3", proveedor); * map.Add(specular, this.specular, "F3", proveedor); * map.Add(ATENUACION_CONSTANTE, this.ConstantAttenuation, "F3", proveedor); * map.Add(ATENUACION_LINEAR, this.LinearAttenuation, "F3", proveedor); * map.Add(ATENUACION_CUADRATICA, this.QuadraticAttenuation, "F3", proveedor); * map.Add(CORTE_FOCO, this.SpotCutoff, "F3", proveedor); * map.Add(EXPONENTE_FOCO, this.SpotExponent, "F3", proveedor); * return map.ToString();*/ return("Light"); }
private string Format(object argument, string format) { if (argument == null) { return(string.Empty); } ICustomFormatter formatter = formatProvider == null ? null : formatProvider.GetFormat(typeof(ICustomFormatter)) as ICustomFormatter; if (formatter != null) { return(formatter.Format(format, argument, formatProvider)); } var formattable = argument as IFormattable; if (formattable != null) { return(formattable.ToString(format, formatProvider)); } return(argument.ToString()); }
/// <summary> /// Returns a string representation of the unit. /// </summary> /// <remarks> /// The format string can be either 'UN' (Unit Name) or 'US' (Unit Symbol). /// </remarks> public string ToString(string format, IFormatProvider formatProvider) { if (format == null) { format = "US"; } if (formatProvider != null) { ICustomFormatter formatter = formatProvider.GetFormat(GetType()) as ICustomFormatter; if (formatter != null) { return(formatter.Format(format, this, formatProvider)); } } switch (format) { case "UN": return(Name); case "US": default: return(Symbol); } }
string IFormattable.ToString(string value, IFormatProvider formatProvider) { if (IsIdentity) { return("Identity"); } if (String.IsNullOrEmpty(value)) { value = null; } if (formatProvider != null) { ICustomFormatter cp = (ICustomFormatter)formatProvider.GetFormat(typeof(ICustomFormatter)); if (cp != null) { return(String.Format("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}", cp.Format(value, m_11, formatProvider), cp.Format(null, ',', formatProvider), cp.Format(value, m_12, formatProvider), cp.Format(null, ',', formatProvider), cp.Format(value, m_21, formatProvider), cp.Format(null, ',', formatProvider), cp.Format(value, m_22, formatProvider), cp.Format(null, ',', formatProvider), cp.Format(value, offset_x, formatProvider), cp.Format(null, ',', formatProvider), cp.Format(value, offset_y, formatProvider))); } } return(String.Format("{0},{1},{2},{3},{4},{5}", m_11.ToString(value, formatProvider), m_12.ToString(value, formatProvider), m_21.ToString(value, formatProvider), m_22.ToString(value, formatProvider), offset_x.ToString(value, formatProvider), offset_y.ToString(value, formatProvider))); }
string IFormattable.ToString(string format, IFormatProvider formatProvider) { if (formatProvider != null) { ICustomFormatter fmt = formatProvider.GetFormat(GetType()) as ICustomFormatter; if (fmt != null) { return(fmt.Format(format, this, formatProvider)); } } switch (format) { case "Na": return(Name); case "Nu": return(Number.ToString()); case "Ad": return(Address); default: return("Name=" + Name + ",Number=" + Number.ToString() + ",Address=" + Address); } }
/// <summary> /// /// </summary> /// <param name="format"> /// "n" production name or type name /// "r" uses render method, otherwise ToString() is returned /// "p" for path /// </param> /// <param name="formatProvider"></param> /// <returns></returns> public string ToString(string format, IFormatProvider formatProvider = null) { if (formatProvider != null) { ICustomFormatter formatter = formatProvider.GetFormat(this.GetType()) as ICustomFormatter; if (formatter != null) { return(formatter.Format(format, this, formatProvider)); } } switch (format) { case "n": return(this.ProductionName ?? string.Format("({0})", this.GetType().Name + ")")); case "r": return(Render()); case "p": return(string.Format(@"\{0:p}\{1}", this.Parent, this.ProductionName ?? string.Format("({0})", this.GetType().Name))); default: return(this.ToString()); } }
/// <summary> /// Formatea este vector segun el proveedor indicado. /// Busca en <c>IFormatProvider</c> los formatos: /// <c>ICustomFormatter</c>: delega el formateo en este objeto. /// <c>VectorFormatInfo</c>: Obtiene la informacion de formato. /// </summary> public string ToString(string formato, IFormatProvider proveedor) { if (proveedor != null) { ICustomFormatter formatter = proveedor.GetFormat(this.GetType()) as ICustomFormatter; if (formatter != null) { return(formatter.Format(formato, this, proveedor)); } } char f = 'G'; if (!string.IsNullOrEmpty(formato)) { formato = formato.ToUpper(); f = char.ToUpper(formato[0]); } switch (f) { case 'G': default: return(new StringBuilder() .AppendFormat("W: ").AppendLine(this.W.ToString("F3")) .AppendFormat("X: ").AppendLine(this.X.ToString("F3")) .AppendFormat("Y: ").AppendLine(this.Y.ToString("F3")) .AppendFormat("Z: ").AppendLine(this.Z.ToString("F3")) .ToString()); } }
public SupportTextComparerAdapter(ISupportTextComparer supportTextComparer, ICustomFormatter customFormatter, IFormatProvider formatProvider, string formatString, string defaultEmptyText) { this.SupportTextComparer = supportTextComparer; this.CustomFormatter = customFormatter; this.FormatProvider = formatProvider; this.FormatString = formatString; this.DefaultEmptyText = defaultEmptyText; }
/// <summary> /// Shows a string representation of the amount, formatted according to the passed format string, /// using the given format provider. /// </summary> /// <remarks> /// Valid format strings are 'GG', 'GN', 'GL', 'NG', 'NN', 'NL' (where the first letter represents /// the value formatting (General, Numeric), and the second letter represents the unit formatting /// (General, Name, Label)), or a custom number format with 'UG', 'UN' or 'UL' (UnitGeneral, /// UnitName or UnitLabel) representing the unit (i.e. "#,##0.00 UL"). /// </remarks> public string ToString(string format, IFormatProvider formatProvider) { if (format == null) { format = "GG"; } if (formatProvider != null) { ICustomFormatter formatter = formatProvider.GetFormat(this.GetType()) as ICustomFormatter; if (formatter != null) { return(formatter.Format(format, this, formatProvider)); } } String[] formats = format.Split('|'); Amount amount = this; if (formats.Length >= 2) { if (formats[1] == "?") { amount = amount.ConvertedTo(UnitManager.ResolveToNamedUnit(amount.Unit, true)); } else { amount = amount.ConvertedTo(formats[1]); } } switch (formats[0]) { case "GG": return(String.Format(formatProvider, "{0:G} {1:G}", amount.Value, amount.Unit).TrimEnd(null)); case "GN": return(String.Format(formatProvider, "{0:G} {1:N}", amount.Value, amount.Unit).TrimEnd(null)); case "GL": return(String.Format(formatProvider, "{0:G} {1:L}", amount.Value, amount.Unit).TrimEnd(null)); case "NG": return(String.Format(formatProvider, "{0:N} {1:G}", amount.Value, amount.Unit).TrimEnd(null)); case "NN": return(String.Format(formatProvider, "{0:N} {1:N}", amount.Value, amount.Unit).TrimEnd(null)); case "NL": return(String.Format(formatProvider, "{0:N} {1:L}", amount.Value, amount.Unit).TrimEnd(null)); default: formats[0] = formats[0].Replace("UG", "\"" + amount.Unit.ToString("G", formatProvider) + "\""); formats[0] = formats[0].Replace("UN", "\"" + amount.Unit.ToString("N", formatProvider) + "\""); formats[0] = formats[0].Replace("UL", "\"" + amount.Unit.ToString("L", formatProvider) + "\""); return(amount.Value.ToString(formats[0], formatProvider).TrimEnd(null)); } }
/// <summary> /// The ToString implementation. /// </summary> /// <param name="format">The format specifier to use, e.g. <b>Console.WriteLine(rule.ToString("k"));</b></param> /// <param name="provider">Allow clients to format output for their own types using [ICustomFormatter](https://msdn.microsoft.com/en-us/library/system.icustomformatter.aspx).</param> /// <returns>The formatted string.</returns> /// <exception cref="FormatException">thrown if an invalid format string is specified.</exception> /// \par Format specifiers: /// \arg \c G Long version and default when not using a format specifier. /// \arg \c K [RuleKind](@ref AcUtils#RuleKind) - Kind of rule in use. /// \arg \c T [ElementType](@ref AcUtils#ElementType) - Type of element the rule was placed on: \e dir, \e text, \e binary, \e ptext, \e elink, or \e slink. /// \arg \c L Location - Depot-relative path of the element the rule affects. /// \arg \c S SetInStream - Stream or workspace the rule is applied to. /// \arg \c X XlinkToStream - If cross-link the basis stream for the SetInStream. public string ToString(string format, IFormatProvider provider) { if (provider != null) { ICustomFormatter fmt = provider.GetFormat(this.GetType()) as ICustomFormatter; if (fmt != null) { return(fmt.Format(format, this, provider)); } } if (String.IsNullOrEmpty(format)) { format = "G"; } switch (format.ToUpperInvariant()) { case "G": { string text; if (!String.IsNullOrEmpty(_xlinkToStream)) { text = $"SetInStream: {SetInStream}{Environment.NewLine}" + $"Cross-link (basis): {XlinkToStream}{Environment.NewLine}" + $"Location: {Location}{Environment.NewLine}" + $"Rule kind: {Kind}{Environment.NewLine}" + $"Element type: {Type}{Environment.NewLine}"; } else { text = $"SetInStream: {SetInStream}{Environment.NewLine}" + $"Location: {Location}{Environment.NewLine}" + $"Rule kind: {Kind}{Environment.NewLine}" + $"Element type: {Type}{Environment.NewLine}"; } return(text); } case "K": // kind of rule in use return(Kind.ToString()); case "T": // type of element the rule was placed on return(Type.ToString()); case "L": // depot-relative path of the element the rule affects return(Location); case "S": // stream or workspace the rule is applied to return(SetInStream); case "X": // if cross-link the basis stream for the SetInStream return(XlinkToStream); default: throw new FormatException($"The {format} format string is not supported."); } }
/** Creates a new report */ public Report() { // Send all output to the Appendable object sb StringBuilder sb = new StringBuilder(); ICustomFormatter formatter = new ICustomFormatter(sb); // Add a heading addHeading("Chocoholics Anonymous"); }//default constructor
/// <summary> /// The ToString implementation. /// </summary> /// <param name="format">The format specifier to use, e.g. <b>Console.WriteLine(elem.ToString("fs"));</b></param> /// <param name="provider">Allow clients to format output for their own types /// using [ICustomFormatter](https://msdn.microsoft.com/en-us/library/system.icustomformatter.aspx).</param> /// <returns>The formatted string.</returns> /// <exception cref="FormatException">thrown if an invalid format string is specified.</exception> /// \par Format specifiers: /// \arg \c LV Long version (verbose). /// \arg \c G Location, the depot-relative path of the element (default when not using a format specifier). /// \arg \c F \e True if the element is a folder, \e False otherwise. /// \arg \c E \e True if the executable bit is set, \e False if cleared. UNIX/Linux systems only. /// \arg \c I Element ID. /// \arg \c T The element's type: \e dir, \e text, \e binary, \e ptext, \e elink, or \e slink. /// \arg \c FS File size in bytes. /// \arg \c MT Element's modification time. /// \arg \c H "Hierarchy type" of the element, one of two possible values: \e parallel or \e serial. /// \arg \c V Virtual stream\\version number format, e.g. \c 5\12 /// \arg \c R Real stream\\version number format. /// \arg \c N The named stream-name\\version-number designation, e.g. \c MARS_STAGE\7 or \c MARS_STAGE_barnyrd\24 /// \arg \c L Stream where the element is located when it has (\e underlap)(\e member) or (\e overlap)(\e member) status. /// \arg \c TB Name of first time-based stream found when <tt>stat -s \<stream\> -o -B -fox</tt> is used to retrieve elements with (\e overlap) and/or (\e underlap) status. /// \arg \c S The version's status, e.g. (\e kept)(\e member) public string ToString(string format, IFormatProvider provider) { if (provider != null) { ICustomFormatter fmt = provider.GetFormat(this.GetType()) as ICustomFormatter; if (fmt != null) return fmt.Format(format, this, provider); } if (String.IsNullOrEmpty(format)) format = "G"; switch (format.ToUpperInvariant()) { case "LV": // long version (verbose) { if (_modTime != null) return $"{Location}, {Status}{Environment.NewLine}" + $"\tEID: {EID} {{{ElementType}}}, Size: {Size}, ModTime: {ModTime},{Environment.NewLine}" + $"\t{NamedVersion}, Virtual: {VirStreamNumber}\\{VirVersionNumber}, Real: {RealStreamNumber}\\{RealVersionNumber}"; else return $"{Location}, {Status}{Environment.NewLine}" + $"\tEID: {EID} {{{ElementType}}}{Environment.NewLine}" + $"\t{NamedVersion}, Virtual: {VirStreamNumber}\\{VirVersionNumber}, Real: {RealStreamNumber}\\{RealVersionNumber}"; } case "G": // location, the depot-relative path of the element (default when not using a format specifier) return Location; case "F": // True if the element is a folder, False otherwise return Folder.ToString(); case "E": // UNIX/Linux systems only: True if the executable bit is set, False if cleared return Executable.ToString(); case "I": // element ID return EID.ToString(); case "T": // element's type: dir, text, binary, ptext, elink, or slink return ElementType.ToString(); case "FS": // file size in bytes return (Size == null) ? String.Empty : Size.ToString(); case "MT": // element's modification time return ModTime.ToString(); case "H": // hierarchy type: parallel or serial return HierType; case "V": // virtual stream\\version number designation, e.g. 5\12 return $"{VirStreamNumber}\\{VirVersionNumber}"; case "R": // real stream\\version number designation, e.g. 5\12 return $"{RealStreamNumber}\\{RealVersionNumber}"; case "N": // named stream\version number format, e.g. MARS_STAGE\7 or MARS_STAGE_barnyrd\24 return NamedVersion; case "L": // stream where element is located when it has (\e underlap)(\e member) or (\e overlap)(\e member) status return LapStream; case "TB": // first time-based stream found when 'stat -s stream -o -B -fox' is used to retrieve elements with (overlap) and/or (underlap) status return TimeBasedStream; case "S": // version's status, e.g. (kept)(member) return Status; default: throw new FormatException($"The {format} format string is not supported."); } }
public void Add(Type formatType, ICustomFormatter formatter) { ChoGuard.ArgumentNotNull(formatType, "FormatType"); lock (_padLock) { _formatProviders.AddOrUpdate(formatType, formatter); } }
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 "X": { if (PrivateCreator != null) { return(String.Format("({0:x4},xx{1:x2}:{2})", Group, Element & 0xff, PrivateCreator.Creator)); } else { return(String.Format("({0:x4},{1:x4})", Group, Element)); } } case "g": { if (PrivateCreator != null) { return(String.Format("{0:x4},{1:x4}:{2}", Group, Element, PrivateCreator.Creator)); } else { return(String.Format("{0:x4},{1:x4}", Group, Element)); } } case "J": { return(String.Format("{0:X4}{1:X4}", Group, Element)); } case "G": default: { if (PrivateCreator != null) { return(String.Format("({0:x4},{1:x4}:{2})", Group, Element, PrivateCreator.Creator)); } else { return(String.Format("({0:x4},{1:x4})", Group, Element)); } } } }
public string ToString(string format, IFormatProvider formatProvider) { ICustomFormatter customFormatter = formatProvider as ICustomFormatter; if (customFormatter == null) { return(this.ToString()); } return(customFormatter.Format(format, this, null)); }
public static string ToString(this TimeSpan timeSpan, string format, ICustomFormatter formatter) { if (formatter == null) { throw new ArgumentNullException(); } TimeSpanFormatter tsFormatter = (TimeSpanFormatter)formatter; format = Regex.Replace(format, CustomFormatsRegex, new MatchEvaluator(m => MatchReplacer(m, timeSpan, tsFormatter))); return timeSpan.ToString(format); }
public DependsOnISomeFactory(ISomeFactory dep) { created = dep.CreateOne(); }
/// <summary> /// Initializes a new instance of the <see cref="Enumerable"/> class. /// </summary> /// <param name="fallbackProvider">The <see cref="IFormatProvider"/> to fall back on; or <c>null</c>.</param> /// <param name="fallbackFormatter">The <see cref="ICustomFormatter"/> to fall back on; or <c>null</c>.</param> protected Enumerable( IFormatProvider fallbackProvider = null, ICustomFormatter fallbackFormatter = null ) : base(fallbackProvider, fallbackFormatter) { }
/// <summary> /// Initializes a new instance of the <see cref="FallbackBase"/> class. /// </summary> /// <param name="fallbackProvider">The <see cref="IFormatProvider"/> to fall back on; or <c>null</c>.</param> /// <param name="fallbackFormatter">The <see cref="ICustomFormatter"/> to fall back on; or <c>null</c>.</param> protected FallbackBase( IFormatProvider fallbackProvider = null, ICustomFormatter fallbackFormatter = null ) { this.fallbackProvider = fallbackProvider; this.fallbackFormatter = fallbackFormatter; }