当前位置: 首页>>代码示例>>C#>>正文


C# IEditableObject接口代码示例

本文整理汇总了C#中System.ComponentModel.IEditableObject接口的典型用法代码示例。如果您正苦于以下问题:C# IEditableObject接口的具体用法?C# IEditableObject怎么用?C# IEditableObject使用的例子?那么恭喜您, 这里精选的接口代码示例或许可以为您提供帮助。


IEditableObject接口属于System.ComponentModel命名空间,在下文中一共展示了IEditableObject接口的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: if

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;
            this.OnCustomerChanged();
        }
    }
         
    public string LastName 
    {
        get 
        {
            return this.custData.lastName;
        }
        set 
        {
            this.custData.lastName = value;
            this.OnCustomerChanged();
        }
    }
   
    internal CustomersList Parent 
    {
        get 
        {
            return parent;
        }
        set 
        {
            parent = value ;
        }
    }

    private void OnCustomerChanged() 
    {
        if (!inTxn && Parent != null) 
        {
            Parent.CustomerChanged(this);
        }
    }
    
    public override string ToString() 
    {
        StringWriter sb = new StringWriter();
        sb.Write(this.FirstName);
        sb.Write(" ");
        sb.Write(this.LastName);
        return sb.ToString();
    }   
}
开发者ID:.NET开发者,项目名称:System.ComponentModel,代码行数:123,代码来源:IEditableObject


注:本文中的System.ComponentModel.IEditableObject接口示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。