1 //------------------------------------------------------------------------------
2 // <copyright file="LogicalView.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //------------------------------------------------------------------------------
7 namespace Microsoft
.VisualStudio
.Shell
{
10 using System
.ComponentModel
;
11 using System
.Diagnostics
;
12 using System
.Globalization
;
14 /// <include file='doc\LogicalView.uex' path='docs/doc[@for="LogicalView"]' />
16 /// This enum lists the supported logical views.
18 [TypeConverter(typeof(LogicalViewConverter
))]
19 public enum LogicalView
{
21 /// <include file='doc\LogicalView.uex' path='docs/doc[@for="LogicalView.Primary"]/*' />
23 /// <include file='doc\LogicalView.uex' path='docs/doc[@for="LogicalView.Any"]/*' />
25 /// <include file='doc\LogicalView.uex' path='docs/doc[@for="LogicalView.Debugging"]/*' />
27 /// <include file='doc\LogicalView.uex' path='docs/doc[@for="LogicalView.Code"]/*' />
29 /// <include file='doc\LogicalView.uex' path='docs/doc[@for="LogicalView.Designer"]/*' />
31 /// <include file='doc\LogicalView.uex' path='docs/doc[@for="LogicalView.Text"]/*' />
33 /// <include file='doc\LogicalView.uex' path='docs/doc[@for="LogicalView.UserChoose"]/*' />
35 /// <include file='doc\LogicalView.uex' path='docs/doc[@for="LogicalView.ProjectSpecific"]/*' />
40 /// This type converter inherits from the normal enum
41 /// converter. It adds the ability to convert to/from
44 internal class LogicalViewConverter
: EnumConverter
{
46 private Guid
[] _guids
= new Guid
[] {
47 new Guid("00000000-0000-0000-0000-000000000000"),
48 new Guid("FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF"),
49 new Guid("7651A700-06E5-11D1-8EBD-00A0C90F26EA"),
50 new Guid("7651A701-06E5-11D1-8EBD-00A0C90F26EA"),
51 new Guid("7651A702-06E5-11D1-8EBD-00A0C90F26EA"),
52 new Guid("7651A703-06E5-11D1-8EBD-00A0C90F26EA"),
53 new Guid("7651A704-06E5-11D1-8EBD-00A0C90F26EA"),
54 new Guid("80A3471A-6B87-433E-A75A-9D461DE0645F")
57 private LogicalView
[] _views
= new LogicalView
[] {
60 LogicalView
.Debugging
,
64 LogicalView
.UserChoose
,
65 LogicalView
.ProjectSpecific
68 public LogicalViewConverter(Type enumType
) : base(enumType
) {
69 Debug
.Assert(_views
.Length
== _guids
.Length
, "Mismatch in view / guid relationship");
73 /// Gets a value indicating whether this converter
74 /// can convert an object in the given source type to an enumeration object using
75 /// the specified context.
77 public override bool CanConvertFrom(ITypeDescriptorContext context
, Type sourceType
) {
78 if (sourceType
== typeof(Guid
)) {
81 return base.CanConvertFrom(context
, sourceType
);
85 /// Gets a value indicating whether this converter can
86 /// convert an object to the given destination type using the context.
88 public override bool CanConvertTo(ITypeDescriptorContext context
, Type destinationType
) {
89 if (destinationType
== typeof(Guid
)) {
92 return base.CanConvertTo(context
, destinationType
);
96 /// Converts the specified value object to an enumeration object.
98 public override object ConvertFrom(ITypeDescriptorContext context
, CultureInfo culture
, object value) {
100 for (int i
= 0; i
< _guids
.Length
; i
++) {
101 if (value.Equals(_guids
[i
])) {
106 return base.ConvertFrom(context
, culture
, value);
110 /// Converts the given value object to the specified destination type.
112 public override object ConvertTo(ITypeDescriptorContext context
, CultureInfo culture
, object value, Type destinationType
) {
113 if (destinationType
== null) {
114 throw new ArgumentNullException("destinationType");
117 if (destinationType
== typeof(Guid
) && value != null) {
118 for (int i
= 0; i
< _views
.Length
; i
++) {
119 if (value.Equals(_views
[i
])) {
125 return base.ConvertTo(context
, culture
, value, destinationType
);