📄 contactmatchhelper.cs
字号:
namespace Imps.Client.Core
{
using System;
using System.Collections.Generic;
public class ContactMatchHelper
{
private string _lastKeyWord;
private ContactCollection _lastResult;
private User _user;
public ContactMatchHelper(User user)
{
this._user = user;
this._lastResult = new ContactCollection();
}
public void Clear()
{
this.ClearKeyWord();
this.ClearResult();
}
internal void ClearKeyWord()
{
this._lastKeyWord = string.Empty;
}
internal void ClearResult()
{
this._lastResult = new ContactCollection();
}
public ContactCollection GetMatchContacts(string keyWord)
{
keyWord = keyWord.ToLower();
if (((this._lastResult.Count != 0) && !string.IsNullOrEmpty(this._lastKeyWord)) && keyWord.StartsWith(this._lastKeyWord))
{
return this.GetMatchContacts(this._lastResult, keyWord);
}
return this.GetMatchContacts(this._user.ContactList.Contacts, keyWord);
}
public ContactCollection GetMatchContacts(ContactCollection contacts, string keyWord)
{
ContactCollection matchContacts = new ContactCollection();
if ((contacts == null) || (contacts.Count == 0))
{
return matchContacts;
}
if (string.IsNullOrEmpty(keyWord))
{
return contacts;
}
keyWord = keyWord.ToLower();
if (((this._lastResult.Count != 0) && !string.IsNullOrEmpty(this._lastKeyWord)) && keyWord.StartsWith(this._lastKeyWord))
{
if (this._lastKeyWord.CompareTo(keyWord) == 0)
{
this._lastKeyWord = string.Empty;
using (IEnumerator<Contact> enumerator = contacts.GetEnumerator())
{
while (enumerator.MoveNext())
{
Contact item = enumerator.get_Current();
if (!matchContacts.Contains(item) && item.MatchSearch(keyWord))
{
matchContacts.Add(item);
}
}
goto Label_00FF;
}
}
this._lastKeyWord = keyWord;
matchContacts = this.GetMatchContacts(this._lastResult, keyWord);
}
else
{
using (IEnumerator<Contact> enumerator2 = contacts.GetEnumerator())
{
while (enumerator2.MoveNext())
{
Contact contact2 = enumerator2.get_Current();
if (!matchContacts.Contains(contact2) && contact2.MatchSearch(keyWord))
{
matchContacts.Add(contact2);
}
}
}
}
Label_00FF:
this._lastKeyWord = keyWord;
this._lastResult = matchContacts;
matchContacts.Sorted = true;
return matchContacts;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -