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


C# IOutput.Write方法代码示例

本文整理汇总了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;
        }
开发者ID:amartynenko,项目名称:SmartFormat,代码行数:12,代码来源:UserExtensionTests.cs

示例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 );
 }
开发者ID:johann-gambolputty,项目名称:robotbastards,代码行数:10,代码来源:CustomTypeWriterCache.cs

示例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;

        }
开发者ID:Avatarchik,项目名称:AnimatorAccess,代码行数:29,代码来源:TimeFormatter.cs

示例4: ExportTo

 public void ExportTo(IOutput output)
 {
     output.Write(tag);
     output.Write(value);
     output.EndLine();
 }
开发者ID:Phazyck,项目名称:CsvToYnab,代码行数:6,代码来源:Entry.cs

示例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);
                }
//.........这里部分代码省略.........
开发者ID:kukawski,项目名称:SmartFormat,代码行数:101,代码来源:ListFormatter.cs

示例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);
                }
            }
        }
开发者ID:Avatarchik,项目名称:AnimatorAccess,代码行数:77,代码来源:DefaultFormatter.cs

示例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;
            }
//.........这里部分代码省略.........
开发者ID:johann-gambolputty,项目名称:robotbastards,代码行数:101,代码来源:BinaryTypeWriter.cs

示例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 ) ) );
        }
开发者ID:johann-gambolputty,项目名称:robotbastards,代码行数:16,代码来源:BinaryTypeWriter.cs

示例9: OutputExpectedValue

 private static void OutputExpectedValue(Expected expected, IOutput output, FormatDetails formatDetails)
 {
     output.Write(string.Empty + expected.Value, formatDetails);
 }
开发者ID:soxtoby,项目名称:EasyAssertions,代码行数:4,代码来源:ExpectedFormatter.cs

示例10: OutputExpectedExpression

 private static void OutputExpectedExpression(Expected expected, IOutput output, FormatDetails formatDetails)
 {
     output.Write(expected.Expression + Environment.NewLine + NewLineIndent(output), formatDetails);
 }
开发者ID:soxtoby,项目名称:EasyAssertions,代码行数:4,代码来源:ExpectedFormatter.cs


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