1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
//------------------------------------------------------------------------------
// <copyright file="XmlDataSourceNodeDescriptor.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.UI.WebControls {
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing.Design;
using System.Security.Permissions;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.Util;
using System.Xml;
using System.Xml.XPath;
using AttributeCollection = System.ComponentModel.AttributeCollection;
/// <devdoc>
/// </devdoc>
internal sealed class XmlDataSourceNodeDescriptor : ICustomTypeDescriptor, IXPathNavigable {
private XmlNode _node;
/// <devdoc>
/// Creates a new instance of XmlDataSourceView.
/// </devdoc>
public XmlDataSourceNodeDescriptor(XmlNode node) {
Debug.Assert(node != null, "Did not expect null node");
_node = node;
}
AttributeCollection ICustomTypeDescriptor.GetAttributes() {
return AttributeCollection.Empty;
}
string ICustomTypeDescriptor.GetClassName() {
return GetType().Name;
}
string ICustomTypeDescriptor.GetComponentName() {
return null;
}
TypeConverter ICustomTypeDescriptor.GetConverter() {
return null;
}
EventDescriptor ICustomTypeDescriptor.GetDefaultEvent() {
return null;
}
PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty() {
return null;
}
object ICustomTypeDescriptor.GetEditor(Type editorBaseType) {
return null;
}
EventDescriptorCollection ICustomTypeDescriptor.GetEvents() {
return null;
}
EventDescriptorCollection ICustomTypeDescriptor.GetEvents(Attribute[] attrs) {
return null;
}
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties() {
return ((ICustomTypeDescriptor)this).GetProperties(null);
}
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attrFilter) {
System.Collections.Generic.List<PropertyDescriptor> list = new System.Collections.Generic.List<PropertyDescriptor>();
XmlAttributeCollection attrs = _node.Attributes;
if (attrs != null) {
for (int i = 0; i < attrs.Count; i++) {
list.Add(new XmlDataSourcePropertyDescriptor(attrs[i].Name));
}
}
return new PropertyDescriptorCollection(list.ToArray());
}
object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor pd) {
if (pd is XmlDataSourcePropertyDescriptor) {
return this;
}
return null;
}
XPathNavigator IXPathNavigable.CreateNavigator() {
return _node.CreateNavigator();
}
private class XmlDataSourcePropertyDescriptor : PropertyDescriptor {
private string _name;
public XmlDataSourcePropertyDescriptor(string name) : base(name, null) {
_name = name;
}
public override Type ComponentType {
get {
return typeof(XmlDataSourceNodeDescriptor);
}
}
public override bool IsReadOnly {
get {
return true;
}
}
public override Type PropertyType {
get {
return typeof(string);
}
}
public override bool CanResetValue(object o) {
return false;
}
public override object GetValue(object o) {
XmlDataSourceNodeDescriptor node = o as XmlDataSourceNodeDescriptor;
if (node != null) {
XmlAttributeCollection attrs = node._node.Attributes;
if (attrs != null) {
XmlAttribute attr = attrs[_name];
if (attr != null) {
return attr.Value;
}
}
}
return String.Empty;
}
public override void ResetValue(object o) {
}
public override void SetValue(object o, object value) {
}
public override bool ShouldSerializeValue(object o) {
return true;
}
}
}
}
|