The Labs \ Source Viewer \ SSCLI \ System.Xml.XPath.DataBinding \ XPathNodeView

  1. //------------------------------------------------------------------------------
  2. // <copyright file="XPathNodeView.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. #if ENABLEDATABINDING
  16. using System;
  17. using System.Xml;
  18. using System.Xml.XPath;
  19. using System.Xml.Schema;
  20. using System.Collections;
  21. using System.Collections.Generic;
  22. using System.ComponentModel;
  23. using System.Diagnostics;
  24. namespace System.Xml.XPath.DataBinding
  25. {
  26.     public sealed class XPathNodeView : IXPathNavigable, ICustomTypeDescriptor, INotifyPropertyChanged
  27.     {
  28.         XPathDocumentView collection;
  29.         XPathNode rowNd;
  30.         object[] cols;
  31.        
  32.         internal XPathNodeView(XPathDocumentView col, XPathNode rowNd, object[] columns)
  33.         {
  34.             this.collection = col;
  35.             this.rowNd = rowNd;
  36.             this.cols = columns;
  37.         }
  38.        
  39.         //
  40.         // local methods
  41.        
  42.         public XPathDocumentView XPathDocumentView {
  43.             get { return this.collection; }
  44.         }
  45.        
  46.         public object this[string fieldname]
  47.         {
  48.             get {
  49.                 if (null == fieldname)
  50.                     throw new ArgumentNullException("fieldname");
  51.                 int col = this.collection.RowShape.FindNamedSubShape(fieldname);
  52.                 if (col == -1)
  53.                     throw new ArgumentException("fieldname");
  54.                 Debug.Assert(col >= 0 && col < this.cols.Length);
  55.                 return this.cols[col];
  56.             }
  57.             set {
  58.                 throw new NotSupportedException();
  59.             }
  60.         }
  61.        
  62.         public object this[int fieldIndex]
  63.         {
  64.             get {
  65.                 if (fieldIndex < 0 || fieldIndex >= this.cols.Length)
  66.                     throw new ArgumentOutOfRangeException("fieldIndex");
  67.                 return this.cols[fieldIndex];
  68.             }
  69.             set {
  70.                 throw new NotSupportedException();
  71.             }
  72.         }
  73.        
  74.         //
  75.         // IXPathNavigable Implementation
  76.        
  77.         /// <include file='doc\XPathNodeView.uex' path='docs/doc[@for="XPathNodeView.CreateNavigator"]/*' />
  78.         public XPathNavigator CreateNavigator()
  79.         {
  80.             XPathNode nd = this.rowNd;
  81.             if (null != nd)
  82.                 return new XPathDocumentNavigator(this.rowNd, null);
  83.             return null;
  84.         }
  85.        
  86.         //
  87.         // ICustomTypeDescriptor Implementation
  88.        
  89.         /// <include file='doc\XPathNodeView.uex' path='docs/doc[@for="XPathNodeView.GetAttributes"]/*' />
  90.         public AttributeCollection GetAttributes()
  91.         {
  92.             return new AttributeCollection((Attribute[])null);
  93.         }
  94.        
  95.         /// <include file='doc\XPathNodeView.uex' path='docs/doc[@for="XPathNodeView.GetClassName"]/*' />
  96.         public string GetClassName()
  97.         {
  98.             return collection.RowShape.Name;
  99.         }
  100.        
  101.         /// <include file='doc\XPathNodeView.uex' path='docs/doc[@for="XPathNodeView.GetComponentName"]/*' />
  102.         public string GetComponentName()
  103.         {
  104.             return null;
  105.         }
  106.        
  107.         /// <include file='doc\XPathNodeView.uex' path='docs/doc[@for="XPathNodeView.GetConverter"]/*' />
  108.         public TypeConverter GetConverter()
  109.         {
  110.             return null;
  111.         }
  112.        
  113.         /// <include file='doc\XPathNodeView.uex' path='docs/doc[@for="XPathNodeView.GetDefaultEvent"]/*' />
  114.         public EventDescriptor GetDefaultEvent()
  115.         {
  116.             return null;
  117.         }
  118.        
  119.         /// <include file='doc\XPathNodeView.uex' path='docs/doc[@for="XPathNodeView.GetDefaultProperty"]/*' />
  120.         public PropertyDescriptor GetDefaultProperty()
  121.         {
  122.             return null;
  123.         }
  124.        
  125.         /// <include file='doc\XPathNodeView.uex' path='docs/doc[@for="XPathNodeView.GetEditor"]/*' />
  126.         public object GetEditor(Type editorBaseType)
  127.         {
  128.             return null;
  129.         }
  130.        
  131.         /// <include file='doc\XPathNodeView.uex' path='docs/doc[@for="XPathNodeView.GetEvents"]/*' />
  132.         public EventDescriptorCollection GetEvents()
  133.         {
  134.             return null;
  135.         }
  136.        
  137.         /// <include file='doc\XPathNodeView.uex' path='docs/doc[@for="XPathNodeView.GetEvents2"]/*' />
  138.         public EventDescriptorCollection GetEvents(Attribute[] attributes)
  139.         {
  140.             return null;
  141.         }
  142.        
  143.         /// <include file='doc\XPathNodeView.uex' path='docs/doc[@for="XPathNodeView.GetPropertyOwner"]/*' />
  144.         public object GetPropertyOwner(PropertyDescriptor pd)
  145.         {
  146.             return null;
  147.         }
  148.        
  149.         /// <include file='doc\XPathNodeView.uex' path='docs/doc[@for="XPathNodeView.GetProperties"]/*' />
  150.         public PropertyDescriptorCollection GetProperties()
  151.         {
  152.             return collection.GetItemProperties(null);
  153.         }
  154.        
  155.         /// <include file='doc\XPathNodeView.uex' path='docs/doc[@for="XPathNodeView.GetProperties2"]/*' />
  156.         public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
  157.         {
  158.             return collection.GetItemProperties(null);
  159.         }
  160.        
  161.        
  162.         //
  163.         // INotifyPropertyChanged Implementation
  164.        
  165.         /// <include file='doc\XPathNodeView.uex' path='docs/doc[@for="XPathNodeView.PropertyChanged"]/*' />
  166.         public event PropertyChangedEventHandler PropertyChanged {
  167.             add {
  168.                 throw new NotSupportedException("INotifyPropertyChanged.PropertyChanged");
  169.             }
  170.             remove {
  171.                 throw new NotSupportedException("INotifyPropertyChanged.PropertyChanged");
  172.             }
  173.         }
  174.        
  175.         //
  176.         // internal implementation
  177.        
  178.         // used by XPathNodeViewPropertyDescriptor to access values
  179.         internal XPathDocumentView Collection {
  180.             get { return this.collection; }
  181.         }
  182.         internal object Column(int index)
  183.         {
  184.             return cols[index];
  185.         }
  186.     }
  187. }
  188. #endif

Developer Fusion