RE: Interface implementation in J#

From: Amit Bhagwat [MSFT] (Amit.vjc_at_online.microsoft.com)
Date: 05/13/04

  • Next message: Lars-Inge Tønnessen: "Re: 'System.FormatException' at Compile time"
    Date: Thu, 13 May 2004 13:11:33 GMT
    
    

    This is a bug in VJ#. We are fixing it in the next version of VJ#.

    --------------------
    >Thread-Topic: Interface implementation in J#
    >thread-index: AcQ35GqxHTmwbrq8T3uaLP7TxTVwog==
    >X-WN-Post: microsoft.public.dotnet.vjsharp
    >From: =?Utf-8?B?U2FtZWVrc2hh?= <anonymous@discussions.microsoft.com>
    >References: <CC3E77B9-2B97-44FC-8FFA-61CC33547AFB@microsoft.com>
    <2HGZvSpNEHA.3196@cpmsftngxa10.phx.gbl>
    >Subject: RE: Interface implementation in J#
    >Date: Tue, 11 May 2004 22:46:05 -0700
    >Lines: 368
    >Message-ID: <793ACE3D-E490-4FDB-BB67-BFBD7248301D@microsoft.com>
    >MIME-Version: 1.0
    >Content-Type: text/plain;
    > charset="Utf-8"
    >Content-Transfer-Encoding: 7bit
    >X-Newsreader: Microsoft CDO for Windows 2000
    >Content-Class: urn:content-classes:message
    >Importance: normal
    >Priority: normal
    >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
    >Newsgroups: microsoft.public.dotnet.vjsharp
    >Path: cpmsftngxa10.phx.gbl
    >Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.vjsharp:6021
    >NNTP-Posting-Host: tk2msftcmty1.phx.gbl 10.40.1.180
    >X-Tomcat-NG: microsoft.public.dotnet.vjsharp
    >
    >Hi,
    Thanks for your cooperation.
    Here is the complete C# code that works fine

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.IO;

    namespace IBindingList_Doc
    {
            
            // sample for IEditableObject
            //<snippet1>
            public class Customer : IEditableObject
            {
           
                    struct CustomerData
                    {
                            internal string id ;
                            internal string firstName ;
                            internal string lastName ;
                    }
            
                    private CustomersList parent;
                    private CustomerData custData;
                    private CustomerData backupData;
                    private bool inTxn = false;

                    // Implements IEditableObject
                    void IEditableObject.BeginEdit()
                    {
                            Console.WriteLine("Start BeginEdit");
                            if (!inTxn)
                            {
                                    this.backupData = custData;
                                    inTxn = true;
                                    Console.WriteLine("BeginEdit - " + this.backupData.lastName);
                            }
                            Console.WriteLine("End BeginEdit");
                    }

                    void IEditableObject.CancelEdit()
                    {
                            Console.WriteLine("Start CancelEdit");
                            if (inTxn)
                            {
                                    this.custData = backupData;
                                    inTxn = false;
                                    Console.WriteLine("CancelEdit - " + this.custData.lastName);
                            }
                            Console.WriteLine("End CancelEdit");
                    }

                    void IEditableObject.EndEdit()
                    {
                            Console.WriteLine("Start EndEdit" + this.custData.id +
    this.custData.lastName);
                            if (inTxn)
                            {
                                    backupData = new CustomerData();
                                    inTxn = false;
                                    Console.WriteLine("Done EndEdit - " + this.custData.id +
    this.custData.lastName);
                            }
                            Console.WriteLine("End EndEdit");
                    }

                    public Customer(string ID) : base()
                    {
                            this.custData = new CustomerData();
                            this.custData.id = ID;
                            this.custData.firstName = "";
                            this.custData.lastName = "";
                    }

                    public string ID
                    {
                            get
                            {
                                    return this.custData.id;
                            }
                    }
            
                    public string FirstName
                    {
                            get
                            {
                                    return this.custData.firstName;
                            }
                            set
                            {
                                    this.custData.firstName = value;
                            }
                    }
                 
                    public string LastName
                    {
                            get
                            {
                                    return this.custData.lastName;
                            }
                            set
                            {
                                    this.custData.lastName = value;
                            }
                    }
           
                    internal CustomersList Parent
                    {
                            get
                            {
                                    return parent;
                            }
                            set
                            {
                                    parent = value ;
                            }
                    }

                    private void OnCustomerChanged()
                    {
                            if (!inTxn && Parent != null)
                            {
                                    Parent.CustomerChanged(this);
                            }
                    }
                    //</snippet1>
                    public override string ToString()
                    {
                            StringWriter sb = new StringWriter();
                            sb.Write(this.FirstName);
                            sb.Write(" ");
                            sb.Write(this.LastName);
                            return sb.ToString();
                    }
            }
            // end of Customer class - sample for IEditableObject

            // sample for IBindingList
            //<snippet2>
            public class CustomersList : CollectionBase, IBindingList
            {
        
                    private ListChangedEventArgs resetEvent = new
    ListChangedEventArgs(ListChangedType.Reset, -1);
                    private ListChangedEventHandler onListChanged;

                    public void LoadCustomers()
                    {
                            IList l = (IList)this;
                            l.Add(ReadCustomer1());
                            l.Add(ReadCustomer2());
                            OnListChanged(resetEvent);
                    }

                    public Customer this[int index]
                    {
                            get
                            {
                                    return (Customer)(List[index]);
                            }
                            set
                            {
                                    List[index] = value;
                            }
                    }

                    public int Add (Customer value)
                    {
                            return List.Add(value);
                    }

                    public Customer AddNew()
                    {
                            return (Customer)((IBindingList)this).AddNew();
                    }

                    public void Remove (Customer value)
                    {
                            List.Remove(value);
                    }

            
                    protected virtual void OnListChanged(ListChangedEventArgs ev)
                    {
                            if (onListChanged != null)
                            {
                                    onListChanged(this, ev);
                            }
                    }
            

                    protected override void OnClear()
                    {
                            foreach (Customer c in List)
                            {
                                    c.Parent = null;
                            }
                    }

                    protected override void OnClearComplete()
                    {
                            OnListChanged(resetEvent);
                    }

                    protected override void OnInsertComplete(int index, object value)
                    {
                            Customer c = (Customer)value;
                            c.Parent = this;
                            OnListChanged(new ListChangedEventArgs(ListChangedType.ItemAdded,
    index));
                    }

                    protected override void OnRemoveComplete(int index, object value)
                    {
                            Customer c = (Customer)value;
                            c.Parent = this;
                            OnListChanged(new ListChangedEventArgs(ListChangedType.ItemDeleted,
    index));
                    }

                    protected override void OnSetComplete(int index, object oldValue, object
    newValue)
                    {
                            if (oldValue != newValue)
                            {

                                    Customer oldcust = (Customer)oldValue;
                                    Customer newcust = (Customer)newValue;
                    
                                    oldcust.Parent = null;
                                    newcust.Parent = this;
                    
                                    
                                    OnListChanged(new ListChangedEventArgs(ListChangedType.ItemAdded,
    index));
                            }
                    }
            
                    // Called by Customer when it changes.
                    internal void CustomerChanged(Customer cust)
                    {
                            
                            int index = List.IndexOf(cust);
                
                            OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged,
    index));
                    }
            

                    // Implements IBindingList.
                    bool IBindingList.AllowEdit
                    {
                            get { return true ; }
                    }

                    bool IBindingList.AllowNew
                    {
                            get { return true ; }
                    }

                    bool IBindingList.AllowRemove
                    {
                            get { return true ; }
                    }

                    bool IBindingList.SupportsChangeNotification
                    {
                            get { return true ; }
                    }
            
                    bool IBindingList.SupportsSearching
                    {
                            get { return false ; }
                    }

                    bool IBindingList.SupportsSorting
                    {
                            get { return false ; }
                    }

                    // Events.
                    public event ListChangedEventHandler ListChanged
                    {
                            add
                            {
                                    onListChanged += value;
                            }
                            remove
                            {
                                    onListChanged -= value;
                            }
                    }

                    // Methods.
                    object IBindingList.AddNew()
                    {
                            Customer c = new Customer(this.Count.ToString());
                            List.Add(c);
                            return c;
                    }

                    // Unsupported properties.
                    bool IBindingList.IsSorted
                    {
                            get { throw new NotSupportedException(); }
                    }

                    ListSortDirection IBindingList.SortDirection
                    {
                            get { throw new NotSupportedException(); }
                    }

                    PropertyDescriptor IBindingList.SortProperty
                    {
                            get { throw new NotSupportedException(); }
                    }

                    // Unsupported Methods.
                    void IBindingList.AddIndex(PropertyDescriptor property)
                    {
                            throw new NotSupportedException();
                    }

                    void IBindingList.ApplySort(PropertyDescriptor property,
    ListSortDirection direction)
                    {
                            throw new NotSupportedException();
                    }

                    int IBindingList.Find(PropertyDescriptor property, object key)
                    {
                            throw new NotSupportedException();
                    }

                    void IBindingList.RemoveIndex(PropertyDescriptor property)
                    {
                            throw new NotSupportedException();
                    }

                    void IBindingList.RemoveSort()
                    {
                            throw new NotSupportedException();
                    }

                    // Worker functions to populate the list with data.
                    private static Customer ReadCustomer1()
                    {
                            Customer cust = new Customer("536-45-1245");
                            cust.FirstName = "Jo";
                            cust.LastName = "Brown";
                            return cust;
                    }
            
                    private static Customer ReadCustomer2()
                    {
                            Customer cust = new Customer("246-12-5645");
                            cust.FirstName = "Robert";
                            cust.LastName = "Brown";
                            return cust;
                    }
            
                    
            //</snippet2>
                    

            }
    }

    >


  • Next message: Lars-Inge Tønnessen: "Re: 'System.FormatException' at Compile time"

    Relevant Pages

    • RE: Compiler Error Message: CS0007
      ... Jim Cheshire, MCSE, MCSD ... Developer Support ... >Importance: normal ... >Priority: normal ...
      (microsoft.public.dotnet.framework.aspnet)
    • Re: give the example of the ..
      ... its fricken high priority. ... > bug. ... > I know the circumstances and severity of every bug you report. ... before we ship because it would annoy the customer and we know we can fix ...
      (comp.software.testing)
    • Re: Permanently disable mouse acceleration
      ... > like yourself takes it personally when I point out a bug in a software ... > system and then discuss various methods of fixing it. ... you don't even know how to write a basic flame. ... > something completely irrelavent to the problem. ...
      (comp.os.linux.setup)
    • Re: Another take on Embarcadero and CodeGear
      ... I don't know whether there is an alternative, but you will have to agree that paying top dollar for a product and then be asked to submit/vote for bug reports is a bit much, especially when you are told that you are not precise enough in your bug report, when your bug reportare being ignored, etc. ... But everything gets a priority. ... else can vote on it. ...
      (borland.public.delphi.non-technical)
    • [ANN]TCAD xp.a.1 released and 30% discount for merry Xmas
      ... add/remove point for TMyPolyline and TMyPolygon ... fixing Rule component bug ... fixing group/ungroup shapes order bug ... TCAD xp.a user can upgrade in free, please tell us the order no. ...
      (borland.public.delphi.thirdpartytools.general)