XPathNodeView.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. //------------------------------------------------------------------------------
  2. // <copyright file="XPathNodeView.cs" company="Microsoft">
  3. // Copyright (c) Microsoft Corporation. All rights reserved.
  4. // </copyright>
  5. // <owner current="true" primary="true">derekdb</owner>
  6. //------------------------------------------------------------------------------
  7. #if ENABLEDATABINDING
  8. using System;
  9. using System.Xml;
  10. using System.Xml.XPath;
  11. using System.Xml.Schema;
  12. using System.Collections;
  13. using System.Collections.Generic;
  14. using System.ComponentModel;
  15. using System.Diagnostics;
  16. namespace System.Xml.XPath.DataBinding
  17. {
  18. public sealed class XPathNodeView : IXPathNavigable, ICustomTypeDescriptor, INotifyPropertyChanged {
  19. XPathDocumentView collection;
  20. XPathNode rowNd;
  21. object[] cols;
  22. internal XPathNodeView(XPathDocumentView col, XPathNode rowNd, object[] columns) {
  23. this.collection = col;
  24. this.rowNd = rowNd;
  25. this.cols = columns;
  26. }
  27. //
  28. // local methods
  29. public XPathDocumentView XPathDocumentView {
  30. get { return this.collection; }
  31. }
  32. public object this[string fieldname] {
  33. get {
  34. if (null == fieldname)
  35. throw new ArgumentNullException("fieldname");
  36. int col = this.collection.RowShape.FindNamedSubShape(fieldname);
  37. if (col == -1)
  38. throw new ArgumentException("fieldname");
  39. Debug.Assert(col >= 0 && col < this.cols.Length);
  40. return this.cols[col];
  41. }
  42. set {
  43. throw new NotSupportedException();
  44. }
  45. }
  46. public object this[int fieldIndex] {
  47. get {
  48. if (fieldIndex < 0 || fieldIndex >= this.cols.Length)
  49. throw new ArgumentOutOfRangeException("fieldIndex");
  50. return this.cols[fieldIndex];
  51. }
  52. set {
  53. throw new NotSupportedException();
  54. }
  55. }
  56. //
  57. // IXPathNavigable Implementation
  58. /// <include file='doc\XPathNodeView.uex' path='docs/doc[@for="XPathNodeView.CreateNavigator"]/*' />
  59. public XPathNavigator CreateNavigator() {
  60. XPathNode nd = this.rowNd;
  61. if (null != nd)
  62. return new XPathDocumentNavigator(this.rowNd, null);
  63. return null;
  64. }
  65. //
  66. // ICustomTypeDescriptor Implementation
  67. /// <include file='doc\XPathNodeView.uex' path='docs/doc[@for="XPathNodeView.GetAttributes"]/*' />
  68. public AttributeCollection GetAttributes() {
  69. return new AttributeCollection((Attribute[])null);
  70. }
  71. /// <include file='doc\XPathNodeView.uex' path='docs/doc[@for="XPathNodeView.GetClassName"]/*' />
  72. public String GetClassName() {
  73. return collection.RowShape.Name;
  74. }
  75. /// <include file='doc\XPathNodeView.uex' path='docs/doc[@for="XPathNodeView.GetComponentName"]/*' />
  76. public String GetComponentName() {
  77. return null;
  78. }
  79. /// <include file='doc\XPathNodeView.uex' path='docs/doc[@for="XPathNodeView.GetConverter"]/*' />
  80. public TypeConverter GetConverter() {
  81. return null;
  82. }
  83. /// <include file='doc\XPathNodeView.uex' path='docs/doc[@for="XPathNodeView.GetDefaultEvent"]/*' />
  84. public EventDescriptor GetDefaultEvent() {
  85. return null;
  86. }
  87. /// <include file='doc\XPathNodeView.uex' path='docs/doc[@for="XPathNodeView.GetDefaultProperty"]/*' />
  88. public PropertyDescriptor GetDefaultProperty() {
  89. return null;
  90. }
  91. /// <include file='doc\XPathNodeView.uex' path='docs/doc[@for="XPathNodeView.GetEditor"]/*' />
  92. public object GetEditor(Type editorBaseType) {
  93. return null;
  94. }
  95. /// <include file='doc\XPathNodeView.uex' path='docs/doc[@for="XPathNodeView.GetEvents"]/*' />
  96. public EventDescriptorCollection GetEvents() {
  97. return null;
  98. }
  99. /// <include file='doc\XPathNodeView.uex' path='docs/doc[@for="XPathNodeView.GetEvents2"]/*' />
  100. public EventDescriptorCollection GetEvents(Attribute[] attributes) {
  101. return null;
  102. }
  103. /// <include file='doc\XPathNodeView.uex' path='docs/doc[@for="XPathNodeView.GetPropertyOwner"]/*' />
  104. public object GetPropertyOwner(PropertyDescriptor pd) {
  105. return null;
  106. }
  107. /// <include file='doc\XPathNodeView.uex' path='docs/doc[@for="XPathNodeView.GetProperties"]/*' />
  108. public PropertyDescriptorCollection GetProperties() {
  109. return collection.GetItemProperties(null);
  110. }
  111. /// <include file='doc\XPathNodeView.uex' path='docs/doc[@for="XPathNodeView.GetProperties2"]/*' />
  112. public PropertyDescriptorCollection GetProperties(Attribute[] attributes) {
  113. return collection.GetItemProperties(null);
  114. }
  115. //
  116. // INotifyPropertyChanged Implementation
  117. /// <include file='doc\XPathNodeView.uex' path='docs/doc[@for="XPathNodeView.PropertyChanged"]/*' />
  118. public event PropertyChangedEventHandler PropertyChanged {
  119. add {
  120. throw new NotSupportedException("INotifyPropertyChanged.PropertyChanged");
  121. }
  122. remove {
  123. throw new NotSupportedException("INotifyPropertyChanged.PropertyChanged");
  124. }
  125. }
  126. //
  127. // internal implementation
  128. // used by XPathNodeViewPropertyDescriptor to access values
  129. internal XPathDocumentView Collection { get { return this.collection; } }
  130. internal object Column(int index) { return cols[index]; }
  131. }
  132. }
  133. #endif