LogicalView.cs :  » Development » StyleCop » Microsoft » VisualStudio » Shell » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Development » StyleCop 
StyleCop » Microsoft » VisualStudio » Shell » LogicalView.cs
//------------------------------------------------------------------------------
// <copyright file="LogicalView.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>                                                                
//------------------------------------------------------------------------------

namespace Microsoft.VisualStudio.Shell{

    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Globalization;

    /// <include file='doc\LogicalView.uex' path='docs/doc[@for="LogicalView"]' />
    /// <devdoc>
    ///     This enum lists the supported logical views.
    /// </devdoc>
    [TypeConverter(typeof(LogicalViewConverter))]
    public enum LogicalView {

      /// <include file='doc\LogicalView.uex' path='docs/doc[@for="LogicalView.Primary"]/*' />
      Primary,
      /// <include file='doc\LogicalView.uex' path='docs/doc[@for="LogicalView.Any"]/*' />
      Any,
        /// <include file='doc\LogicalView.uex' path='docs/doc[@for="LogicalView.Debugging"]/*' />
        Debugging,
        /// <include file='doc\LogicalView.uex' path='docs/doc[@for="LogicalView.Code"]/*' />
        Code,
        /// <include file='doc\LogicalView.uex' path='docs/doc[@for="LogicalView.Designer"]/*' />
        Designer,
        /// <include file='doc\LogicalView.uex' path='docs/doc[@for="LogicalView.Text"]/*' />
        Text,
        /// <include file='doc\LogicalView.uex' path='docs/doc[@for="LogicalView.UserChoose"]/*' />
        UserChoose,
        /// <include file='doc\LogicalView.uex' path='docs/doc[@for="LogicalView.ProjectSpecific"]/*' />
        ProjectSpecific
    }

    /// <devdoc>
    ///     This type converter inherits from the normal enum
    ///     converter.  It adds the ability to convert to/from
    ///     GUID types.
    /// </devdoc>
    internal class LogicalViewConverter : EnumConverter {

        private Guid[] _guids = new Guid[] {
            new Guid("00000000-0000-0000-0000-000000000000"),
            new Guid("FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF"),
            new Guid("7651A700-06E5-11D1-8EBD-00A0C90F26EA"),
            new Guid("7651A701-06E5-11D1-8EBD-00A0C90F26EA"),
            new Guid("7651A702-06E5-11D1-8EBD-00A0C90F26EA"),
            new Guid("7651A703-06E5-11D1-8EBD-00A0C90F26EA"),
            new Guid("7651A704-06E5-11D1-8EBD-00A0C90F26EA"),
            new Guid("80A3471A-6B87-433E-A75A-9D461DE0645F")
        };

        private LogicalView[] _views = new LogicalView[] {
            LogicalView.Primary,
            LogicalView.Any,
            LogicalView.Debugging,
            LogicalView.Code,
            LogicalView.Designer,
            LogicalView.Text,
            LogicalView.UserChoose,
            LogicalView.ProjectSpecific
        };

        public LogicalViewConverter(Type enumType) : base(enumType) {
            Debug.Assert(_views.Length == _guids.Length, "Mismatch in view / guid relationship");
        }

        /// <devdoc>
        ///     Gets a value indicating whether this converter
        ///     can convert an object in the given source type to an enumeration object using
        ///     the specified context.
        /// </devdoc>
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) {
            if (sourceType == typeof(Guid)) {
                return true;
            }
            return base.CanConvertFrom(context, sourceType);
        }
        
        /// <devdoc>
        ///     Gets a value indicating whether this converter can
        ///     convert an object to the given destination type using the context.
        /// </devdoc>
        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) {
            if (destinationType == typeof(Guid)) {
                return true;
            }
            return base.CanConvertTo(context, destinationType);
        }

        /// <devdoc>
        ///     Converts the specified value object to an enumeration object.
        /// </devdoc>
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) {
            if (value is Guid) {
                for (int i = 0; i < _guids.Length; i++) {
                    if (value.Equals(_guids[i])) {
                        return _views[i];
                    }
                }
            }
            return base.ConvertFrom(context, culture, value);
        }
    
        /// <devdoc>
        ///     Converts the given value object to the specified destination type.
        /// </devdoc>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) {
            if (destinationType == null) {
                throw new ArgumentNullException("destinationType");
            }

            if (destinationType == typeof(Guid) && value != null) {
                for (int i = 0; i < _views.Length; i++) {
                    if (value.Equals(_views[i])) {
                        return _guids[i];
                    }
                }
            }
            
            return base.ConvertTo(context, culture, value, destinationType);
        }
    }
}

www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.