1 //------------------------------------------------------------------------------
2 // <copyright file="SchemaImporterExtensionElement.cs" company="Microsoft Corporation">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
8 namespace System
.Xml
.Serialization
.Configuration
11 using System
.Configuration
;
12 using System
.ComponentModel
;
13 using System
.Globalization
;
14 using System
.Reflection
;
15 using System
.Security
.Permissions
;
17 public sealed class SchemaImporterExtensionElement
: ConfigurationElement
19 public SchemaImporterExtensionElement()
21 this.properties
.Add(this.name
);
22 this.properties
.Add(this.type
);
25 public SchemaImporterExtensionElement(string name
, string type
) : this()
28 this[this.type
] = new TypeAndName(type
);
31 public SchemaImporterExtensionElement(string name
, Type type
) : this()
37 [ConfigurationProperty(ConfigurationStrings
.Name
, IsRequired
=true, IsKey
= true)]
40 get { return (string)this[this.name]; }
41 set { this[this.name] = value; }
44 protected override ConfigurationPropertyCollection Properties
48 return this.properties
;
52 [ConfigurationProperty(ConfigurationStrings
.Type
, IsRequired
=true, IsKey
= false)]
53 [TypeConverter(typeof(TypeTypeConverter
))]
56 get { return ((TypeAndName) this[this.type]).type; }
57 set { this[this.type] = new TypeAndName(value); }
62 get { return this.Name; }
65 ConfigurationPropertyCollection properties
= new ConfigurationPropertyCollection();
67 readonly ConfigurationProperty name
=
68 new ConfigurationProperty(ConfigurationStrings
.Name
, typeof(string), null,
69 ConfigurationPropertyOptions
.IsKey
);
71 readonly ConfigurationProperty type
=
72 new ConfigurationProperty(ConfigurationStrings
.Type
, typeof(Type
), null,
73 new TypeTypeConverter(), null, ConfigurationPropertyOptions
.IsRequired
);
77 public TypeAndName(string name
)
79 this.type
= Type
.GetType(name
, true, true);
83 public TypeAndName(Type type
)
88 public override int GetHashCode()
90 return type
.GetHashCode();
93 public override bool Equals(object comparand
)
95 return type
.Equals(((TypeAndName
) comparand
).type
);
98 public readonly Type type
;
99 public readonly string name
;
102 class TypeTypeConverter
: TypeConverter
{
103 public override bool CanConvertFrom(ITypeDescriptorContext context
, Type sourceType
) {
104 if (sourceType
== typeof(string)) {
107 return base.CanConvertFrom(context
, sourceType
);
110 public override object ConvertFrom(ITypeDescriptorContext context
, CultureInfo culture
, object value) {
111 if (value is string) {
112 return new TypeAndName((string) value);
115 return base.ConvertFrom(context
, culture
, value);
118 public override object ConvertTo(ITypeDescriptorContext context
, CultureInfo culture
, object value, Type destinationType
) {
119 if (destinationType
== typeof(string)) {
120 TypeAndName castedValue
= (TypeAndName
) value;
121 return castedValue
.name
== null ? castedValue
.type
.AssemblyQualifiedName
: castedValue
.name
;
124 return base.ConvertTo(context
, culture
, value, destinationType
);