Click here to Skip to main content
15,885,366 members
Articles / Desktop Programming / Win32

.NET Shell Extensions - Shell Preview Handlers

Rate me:
Please Sign up or sign in to vote.
4.93/5 (23 votes)
20 May 2014MIT8 min read 140.4K   6.1K   71  
Quickly create Shell Preview Handlers for Windows or Outlook using .NET!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SharpShell.Attributes
{
    /// <summary>
    /// The name attribute can be used to give a class display name.
    /// </summary>
    [AttributeUsage(AttributeTargets.Class)]
    public class DisplayNameAttribute : Attribute
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="DisplayNameAttribute"/> class.
        /// </summary>
        /// <param name="displayName">The display name.</param>
        public DisplayNameAttribute(string displayName)
        {
            //   Set the display name.
            DisplayName = displayName;
        }

        /// <summary>
        /// Gets the display name for a type, if defined.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns>The display name of the type, if defined.</returns>
        public static string GetDisplayName(Type type)
        {
            var attribute = type.GetCustomAttributes(typeof (DisplayNameAttribute), true)
                .OfType<DisplayNameAttribute>().FirstOrDefault();
            return attribute != null ? attribute.DisplayName : null;
        }

        /// <summary>
        /// Gets the display name of the (if defined and not empty) for a type.
        /// If there is no display name, or it is empty, the type name is returned.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns>The display name of the (if defined and not empty) for a type, otherwise the type name.</returns>
        public static string GetDisplayNameOrTypeName(Type type)
        {
            //  Return the display name if it is set, otherwise the type name.
            var displayName = GetDisplayName(type);
            return string.IsNullOrEmpty(displayName) ? type.Name : displayName;
        }

    /// <summary>
        /// Gets the display name.
        /// </summary>
        public string DisplayName { get; private set; }
    }
}

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 MIT License


Written By
Software Developer
United Kingdom United Kingdom
Follow my blog at www.dwmkerr.com and find out about my charity at www.childrenshomesnepal.org.

Comments and Discussions