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


C# ITextFormatter.Format方法代码示例

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


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

示例1: GetPropertyValue

        /// <summary>
        /// Recourse against the current property path to retrieve the property value to return.
        /// </summary>
        /// <param name="obj">The object containing the value to extract.</param>
        /// <param name="currentPathIndex">
        /// The recursion index, indicating the current position in the property path.
        /// </param>
        /// <param name="textFormatter">
        /// The formatter that will be used to format the entity or property values.
        /// </param>
        /// <returns>
        /// The formatted property value obtained matching the current <see cref="FormatParameters" /> 
        /// against the specified array of <see href="System.Object"/>s, and formatting the result
        /// using the specified <paramref name="textFormatter"/>.
        /// </returns>
        private string GetPropertyValue( object obj, int currentPathIndex, ITextFormatter textFormatter )
        {
            // if there is a constant value, returns it
            if ( this.Constant != null ) return textFormatter.Format( this.Format, Constant );

            // if object is null, cannot go ahead with the resolution.)
            if ( obj == null ) return textFormatter.Format( this.Format, null );

            // if the current property in the property path is null or empty,
            // should return the formatted whole object.
            var propertyName = currentPathIndex < this.PropertyPath.Count ? this.PropertyPath[currentPathIndex] : null;
            if ( string.IsNullOrEmpty( propertyName ) )
            {
                return textFormatter.Format( this.Format, obj );
            }

            // else extracts the current property
            var type = obj.GetType();
            var property = type.GetProperty( propertyName );
            if ( property == null )
                throw new FormatException( "Invalid property: " + propertyName );

            // extracts the property value from the object
            var propertyValue = property.GetValue( obj, null );

            // recourse to resolve the property value;
            return GetPropertyValue( propertyValue, currentPathIndex + 1, textFormatter );
        }
开发者ID:SchwarzerLoewe,项目名称:Ecmd,代码行数:43,代码来源:FormatParameters.cs


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