📄 moodphrasecollection.cs
字号:
namespace Imps.Client.Core
{
using Imps.Utils;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Xml;
public class MoodPhraseCollection : ICollection<string>, IEnumerable<string>, IEnumerable, IDataCanProposed
{
private List<string> _col;
private bool _hasProposedValue;
private int _upperBound;
public MoodPhraseCollection() : this(5)
{
}
public MoodPhraseCollection(int uppderBound)
{
this.UpperBound = uppderBound;
this._col = new List<string>(uppderBound);
}
public void Add(string item)
{
item = StringHelper.ReplaceCrLfToSpace(item);
int index = this._col.IndexOf(item);
if (index != 0)
{
if (index > 0)
{
this._col.RemoveAt(index);
}
else if ((index < 0) && (this._col.get_Count() >= this.UpperBound))
{
this._col.RemoveAt(this._col.get_Count() - 1);
}
this._col.Insert(0, item);
this._hasProposedValue = true;
}
}
public void Clear()
{
this._col.Clear();
this._hasProposedValue = true;
}
public bool Contains(string item)
{
return this._col.Contains(item);
}
public void CopyTo(string[] array, int arrayIndex)
{
this._col.CopyTo(array, arrayIndex);
}
public IEnumerator<string> GetEnumerator()
{
return this._col.GetEnumerator();
}
public bool HasProposedProperty()
{
return this._hasProposedValue;
}
public void LoadXml(XmlNode xmlNode)
{
this._col.Clear();
foreach (XmlNode node in xmlNode.ChildNodes)
{
this._col.Add(node.InnerText);
}
}
public bool Remove(string item)
{
if (this._col.Contains(item))
{
this._hasProposedValue = true;
return this.Remove(item);
}
return false;
}
public void RemoveProposedValue()
{
this._hasProposedValue = false;
}
IEnumerator IEnumerable.GetEnumerator()
{
return this._col.GetEnumerator();
}
public override string ToString()
{
StringWriter w = new StringWriter();
XmlTextWriter writer2 = new XmlTextWriter(w);
writer2.WriteStartElement("MoodPhrases");
for (int i = 0; i < this._col.get_Count(); i++)
{
writer2.WriteStartElement("string");
writer2.WriteString(this._col.get_Item(i));
writer2.WriteEndElement();
}
writer2.WriteEndElement();
writer2.Flush();
writer2.Close();
return w.ToString();
}
public int Count
{
get
{
return this._col.get_Count();
}
}
public bool HasProposedValue
{
get
{
return this._hasProposedValue;
}
}
public bool IsReadOnly
{
get
{
return this._col.get_IsReadOnly();
}
}
public string this[int index]
{
get
{
return this._col.get_Item(index);
}
}
public object ProposedValue
{
get
{
return this.ToString();
}
}
public int UpperBound
{
get
{
return this._upperBound;
}
set
{
if (value <= 0)
{
throw new ArgumentOutOfRangeException("value");
}
if ((this._col != null) && (this._col.get_Count() > value))
{
this._col.RemoveRange(value, this._col.get_Count() - value);
}
this._upperBound = value;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -