本文整理汇总了C#中IOutput.Write方法的典型用法代码示例。如果您正苦于以下问题:C# IOutput.Write方法的具体用法?C# IOutput.Write怎么用?C# IOutput.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IOutput
的用法示例。
在下文中一共展示了IOutput.Write方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EvaluateFormat
public void EvaluateFormat(object current, Format format, ref bool handled, IOutput output, FormatDetails formatDetails)
{
if (!(current is Guid))
return;
var guid = (Guid)current;
output.Write(guid.ToString().Substring(0, 6), formatDetails);
output.Write("...", formatDetails);
handled = true;
}
示例2: SaveNamedField
/// <summary>
/// Saves a named field, by accessing its value using reflection
/// </summary>
public static void SaveNamedField( IOutput output, RuntimeTypeHandle objTypeHandle, object obj, string fieldName )
{
Type objType = Type.GetTypeFromHandle( objTypeHandle );
FieldInfo fieldInfo = objType.GetField( fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance );
object field = fieldInfo.GetValue( obj );
output.Write( field );
}
示例3: EvaluateFormat
public void EvaluateFormat(object current, Format format, ref bool handled, IOutput output, FormatDetails formatDetails)
{
if (format != null && format.HasNested) return;
var formatText = format != null ? format.Text : "";
TimeSpan fromTime;
if (current is TimeSpan)
{
fromTime = (TimeSpan)current;
}
else if (current is DateTime && formatText.StartsWith("timestring"))
{
formatText = formatText.Substring(10);
fromTime = DateTime.Now.Subtract((DateTime)current);
}
else
{
return;
}
var timeTextInfo = GetTimeTextInfo(formatDetails.Provider);
if (timeTextInfo == null)
{
return;
}
var formattingOptions = TimeSpanFormatOptionsConverter.Parse(formatText);
var timeString = TimeSpanUtility.ToTimeString(fromTime, formattingOptions, timeTextInfo);
output.Write(timeString, formatDetails);
handled = true;
}
示例4: ExportTo
public void ExportTo(IOutput output)
{
output.Write(tag);
output.Write(value);
output.EndLine();
}
示例5: EvaluateFormat
/// <summary>
/// If the source value is an array (or supports ICollection),
/// then each item will be custom formatted.
///
///
/// Syntax:
/// #1: "format|spacer"
/// #2: "format|spacer|last spacer"
/// #3: "format|spacer|last spacer|two spacer"
///
/// The format will be used for each item in the collection, the spacer will be between all items, and the last spacer will replace the spacer for the last item only.
///
/// Example:
/// CustomFormat("{Dates:D|; |; and }", {#1/1/2000#, #12/31/2999#, #9/9/9999#}) = "January 1, 2000; December 31, 2999; and September 9, 9999"
/// In this example, format = "D", spacer = "; ", and last spacer = "; and "
///
///
///
/// Advanced:
/// Composite Formatting is allowed in the format by using nested braces.
/// If a nested item is detected, Composite formatting will be used.
///
/// Example:
/// CustomFormat("{Sizes:{Width}x{Height}|, }", {new Size(4,3), new Size(16,9)}) = "4x3, 16x9"
/// In this example, format = "{Width}x{Height}". Notice the nested braces.
///
/// </summary>
public void EvaluateFormat(object current, Format format, ref bool handled, IOutput output, FormatDetails formatDetails)
{
// This method needs the Highest priority so that it comes before the PluralLocalizationExtension and ConditionalExtension
// This extension requires at least IEnumerable
var enumerable = current as IEnumerable;
if (enumerable == null) return;
// Ignore Strings, because they're IEnumerable.
// This issue might actually need a solution
// for other objects that are IEnumerable.
if (current is string) return;
// If the object is IFormattable, ignore it
if (current is IFormattable) return;
// This extension requires a | to specify the spacer:
if (format == null) return;
var parameters = format.Split("|", 4);
if (parameters.Count < 2) return;
// Grab all formatting options:
// They must be in one of these formats:
// itemFormat|spacer
// itemFormat|spacer|lastSpacer
// itemFormat|spacer|lastSpacer|twoSpacer
var itemFormat = parameters[0];
var spacer = (parameters.Count >= 2) ? parameters[1].Text : "";
var lastSpacer = (parameters.Count >= 3) ? parameters[2].Text : spacer;
var twoSpacer = (parameters.Count >= 4) ? parameters[3].Text : lastSpacer;
if (!itemFormat.HasNested)
{
// The format is not nested,
// so we will treat it as an itemFormat:
var newItemFormat = new Format(itemFormat.baseString);
newItemFormat.startIndex = itemFormat.startIndex;
newItemFormat.endIndex = itemFormat.endIndex;
newItemFormat.HasNested = true;
var newPlaceholder = new Placeholder(newItemFormat, itemFormat.startIndex, formatDetails.Placeholder.NestedDepth);
newPlaceholder.Format = itemFormat;
newPlaceholder.endIndex = itemFormat.endIndex;
newItemFormat.Items.Add(newPlaceholder);
itemFormat = newItemFormat;
}
// Let's buffer all items from the enumerable (to ensure the Count without double-enumeration):
ICollection items = current as ICollection;
if (items == null)
{
var allItems = new List<object>();
foreach (var item in enumerable)
{
allItems.Add(item);
}
items = allItems;
}
int oldCollectionIndex = CollectionIndex; // In case we have nested arrays, we might need to restore the CollectionIndex
CollectionIndex = -1;
foreach (object item in items) {
CollectionIndex += 1; // Keep track of the index
// Determine which spacer to write:
if (spacer == null || CollectionIndex == 0)
{
// Don't write the spacer.
}
else if (CollectionIndex < items.Count - 1) {
output.Write(spacer, formatDetails);
}
else if (CollectionIndex == 1)
{
output.Write(twoSpacer, formatDetails);
}
//.........这里部分代码省略.........
示例6: EvaluateFormat
/// <summary>
/// Do the default formatting, same logic as "String.Format".
/// </summary>
public void EvaluateFormat(object current, Format format, ref bool handled, IOutput output, FormatDetails formatDetails)
{
// This function always handles the method:
handled = true;
// If the format has nested placeholders, we process those first
// instead of formatting the item:
if (format != null && format.HasNested)
{
formatDetails.Formatter.Format(output, format, current, formatDetails);
return;
}
// If the object is null, we shouldn't write anything
if (current == null)
{
return;
}
// (The following code was adapted from the built-in String.Format code)
// We will try using IFormatProvider, IFormattable, and if all else fails, ToString.
var formatter = formatDetails.Formatter;
if (formatter == null) {} // Force the compiler not to complain about unused variable
string result = null;
ICustomFormatter cFormatter;
IFormattable formattable;
// Use the provider to see if a CustomFormatter is available:
if (formatDetails.Provider != null && (cFormatter = formatDetails.Provider.GetFormat(typeof(ICustomFormatter)) as ICustomFormatter) != null)
{
var formatText = format == null ? null : format.GetText();
result = cFormatter.Format(formatText, current, formatDetails.Provider);
}
// IFormattable:
else if ((formattable = current as IFormattable) != null)
{
var formatText = format == null ? null : format.ToString();
result = formattable.ToString(formatText, formatDetails.Provider);
}
// ToString:
else
{
result = current.ToString();
}
// Now that we have the result, let's output it (and consider alignment):
// See if there's a pre-alignment to consider:
if (formatDetails.Placeholder.Alignment > 0)
{
var spaces = formatDetails.Placeholder.Alignment - result.Length;
if (spaces > 0)
{
output.Write(new String(' ', spaces), formatDetails);
}
}
// Output the result:
output.Write(result, formatDetails);
// See if there's a post-alignment to consider:
if (formatDetails.Placeholder.Alignment < 0)
{
var spaces = -formatDetails.Placeholder.Alignment - result.Length;
if (spaces > 0)
{
output.Write(new String(' ', spaces), formatDetails);
}
}
}
示例7: Write
/// <summary>
/// Writes an object to the specified output
/// </summary>
public void Write( IOutput output, object obj )
{
if ( obj == null )
{
output.WriteNull();
return;
}
Type objType = obj.GetType( );
if ( objType.IsArray )
{
output.Write( ( byte )TypeId.Array );
output.Write( ( Array )obj );
return;
}
switch ( objType.Name )
{
case "Type" :
output.Write( ( byte )TypeId.Type );
WriteType( output, ( Type )obj );
return;
case "Boolean" :
output.Write( ( byte )TypeId.Bool );
output.Write( ( Boolean )obj );
return;
case "Byte" :
output.Write( ( byte )TypeId.Byte );
output.Write( ( Byte )obj );
return;
case "SByte" :
output.Write( ( byte )TypeId.SByte );
output.Write( ( SByte )obj );
return;
case "Char" :
output.Write( ( byte )TypeId.Char );
output.Write( ( Char )obj );
return;
case "Int16" :
output.Write( ( byte )TypeId.Int16 );
output.Write( ( Int16 )obj );
return;
case "UInt16" :
output.Write( ( byte )TypeId.UInt16 );
output.Write( ( UInt16 )obj );
return;
case "Int32" :
output.Write( ( byte )TypeId.Int32 );
output.Write( ( Int32 )obj );
return;
case "UInt32" :
output.Write( ( byte )TypeId.UInt32 );
output.Write( ( UInt32 )obj );
return;
case "Int64" :
output.Write( ( byte )TypeId.Int64 );
output.Write( ( Int64 )obj );
return;
case "UInt64" :
output.Write( ( byte )TypeId.UInt64 );
output.Write( ( UInt64 )obj );
return;
case "Single" :
output.Write( ( byte )TypeId.Single );
output.Write( ( Single )obj );
return;
case "Double" :
output.Write( ( byte )TypeId.Double );
output.Write( ( Double )obj );
return;
case "Decimal" :
output.Write( ( byte )TypeId.Decimal );
output.Write( ( Decimal )obj );
return;
case "DateTime" :
output.Write( ( byte )TypeId.DateTime );
output.Write( ( DateTime )obj );
return;
case "String" :
output.Write( ( byte )TypeId.String );
output.Write( ( String )obj );
return;
}
//.........这里部分代码省略.........
示例8: WriteTypeId
/// <summary>
/// Writes a type identifier to the specified output
/// </summary>
private static void WriteTypeId( IOutput output, int typeId )
{
while ( typeId > 127 )
{
byte bitsWithFollowOn = ( byte )( 0x80 | ( typeId & ~0x80 ) );
output.Write( bitsWithFollowOn );
typeId >>= 7;
}
// No follow-on bits required
output.Write( unchecked( ( byte )( typeId ) ) );
}
示例9: OutputExpectedValue
private static void OutputExpectedValue(Expected expected, IOutput output, FormatDetails formatDetails)
{
output.Write(string.Empty + expected.Value, formatDetails);
}
示例10: OutputExpectedExpression
private static void OutputExpectedExpression(Expected expected, IOutput output, FormatDetails formatDetails)
{
output.Write(expected.Expression + Environment.NewLine + NewLineIndent(output), formatDetails);
}