Click here to Skip to main content
15,892,809 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 141.3K   6.1K   72  
Quickly create Shell Preview Handlers for Windows or Outlook using .NET!
using System;
using System.Linq;

namespace SharpShell.Attributes
{
    /// <summary>
    /// The ServerTypeAttribute can be used internally by SharpShell
    /// to mark the type of a server base class. By setting this type,
    /// classes derived from the decorated class will be able to use
    /// the COMServerAssociationAttribute without any extra configuration.
    /// </summary>
    internal class ServerTypeAttribute : Attribute
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ServerTypeAttribute"/> class.
        /// </summary>
        /// <param name="serverType">Type of the server.</param>
        public ServerTypeAttribute(ServerType serverType)
        {
            //  Set the server type.
            ServerType = serverType;
        }

        /// <summary>
        /// Gets the server type of a type of the association.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns>The ServerType of the type, or None if not set.</returns>
        public static ServerType GetServerType(Type type)
        {
            var attribute = type.GetCustomAttributes(typeof(ServerTypeAttribute), true)
                .OfType<ServerTypeAttribute>().FirstOrDefault();
            return attribute != null ? attribute.ServerType : ServerType.None;
        }

        /// <summary>
        /// Gets the type of the server.
        /// </summary>
        /// <value>
        /// The type of the server.
        /// </value>
        public ServerType ServerType { 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