Click here to Skip to main content
15,886,806 members
Articles / Programming Languages / C#

CodeDOM Classes for Solution and Project Files (Part 5)

Rate me:
Please Sign up or sign in to vote.
5.00/5 (12 votes)
30 Nov 2012CDDL7 min read 29.9K   1.2K   18  
CodeDOM objects for VS Solution and Project files.
using System;
using System.Globalization;
using System.Windows.Data;

namespace Nova.Studio
{
    /// <summary>
    /// String converter that trims whitespace and limits strings to a few lines (for use by data bound to XAML).
    /// </summary>
    [ValueConversion(typeof(string), typeof(string))]
    public class StringConverterTrim : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            // Truncate messages to N lines of text maximum with an ellipsis on line N+1
            const int maxLines = 3;
            string text = value.ToString();
            int start = 0;
            for (int i = 0; i < maxLines; ++i)
            {
                start = text.IndexOf('\n', start);
                if (start == -1) break;
                ++start;
            }

            // Truncate message if necessary, and trim leading and trailing whitespace
            return ((start < 0 || text.IndexOf('\n', start) == -1) ? text.Trim() : (text.Substring(0, start).Trim() + "\n..."));
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Common Development and Distribution License (CDDL)


Written By
Software Developer (Senior)
United States United States
I've been writing software since the late 70's, currently focusing mainly on C#.NET. I also like to travel around the world, and I own a Chocolate Factory (sadly, none of my employees are oompa loompas).

Comments and Discussions