日期:2014-05-20 浏览次数:21057 次
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
namespace ConsoleApplication3
{
    [DataContract]
    public class CityInfo
    {
        [DataMember]
        public string CityId { get; set; }
        [DataMember]
        public string CityName { get; set; }
        [DataMember]
        public string CityAreaNum { get; set; }
    }
    public enum InitializeType : int
    {
        GUI = 0,
        CommandLine = 1
    }
    public enum CityInfoPropertyType : int
    {
        CityId = 0,
        CityName = 1,
        CityAreaNum
    }
    public interface IControl 
    {
        Dictionary<string, CityInfo> DictionaryStore { get; }
        string Add(CityInfo info);
        List<string> Add(List<CityInfo> infos);
        string Delete(CityInfo info);
        List<string> Delete(List<CityInfo> infos);
        string Modify(CityInfo info);
        List<string> Modify(List<CityInfo> infos);
        CityInfo Exists(CityInfoPropertyType type, string  value);
    }
    public abstract class BaseControl : IControl 
    {
        
        public abstract string Add(CityInfo info);
        public abstract Dictionary<string, CityInfo> DictionaryStore { get; }
        private List<string> LoopDo(Func<CityInfo, string> func, List<CityInfo> infos) 
        {
            List<string> results = new List<string>();
            foreach(CityInfo info in infos)
            {
                string tmp = func(info);
                if (!string.IsNullOrEmpty(tmp)) 
                {
                    results.Add(tmp);
                }
            }
            return results;
        }
        public virtual List<string> Add(List<CityInfo> infos)
        {
            return LoopDo(Add, infos);
        }
        public abstract string Delete(CityInfo info);
        public virtual List<string> Delete(List<CityInfo> infos)
        {
            return LoopDo(Delete,infos);
        }
        public abstract string Modify(CityInfo info);
        public List<string> Modify(List<CityInfo> infos)
        {
            return LoopDo(Modify,infos);
        }
        public CityInfo Exists(CityInfoPropertyType type, string value)
        {
            throw new NotImplementedException();
        }
      
    }
    public class CommandLineControl : BaseControl
    {
        public override string Add(CityInfo info)
        {
            throw new NotImplementedException();
        }
        public override Dictionary<string, CityInfo> DictionaryStore
        {
            get { throw new NotImplementedException(); }
        }
        public override string Delete(CityInfo info)
        {
            throw new NotImplementedException();
        }
        public override string Modify(CityInfo info)
        {
            throw new NotImplementedException();
        }
    }
    public class PhoneNote 
    {
        public PhoneNote(InitializeType type) 
        {
            
        }
    }
}