public abstract class SeDataSource : IEnumerable, IEnumerator
{
//不知道怎么实现
}=====================================
public class DataSource : SeDataSource
{
public DataSource(ISearchResult result) : base(result)
{
} public string Subject
{
get { return this.HighlightValue("subject", 30); }
} public string Content
{
get { return this.HighlightValue("content", 200); }
} public string Author
{
get { return this.Value("author"); }
}
}===================================
Repeater1.DataSource = new DataSource(Result);
Repeater1.DataBind();//绑定数据
===================================
ISearchResult //接口 ,具体定义 可根据能实现这样效果定义
{
//不知道怎么实现
}=====================================
public class DataSource : SeDataSource
{
public DataSource(ISearchResult result) : base(result)
{
} public string Subject
{
get { return this.HighlightValue("subject", 30); }
} public string Content
{
get { return this.HighlightValue("content", 200); }
} public string Author
{
get { return this.Value("author"); }
}
}===================================
Repeater1.DataSource = new DataSource(Result);
Repeater1.DataBind();//绑定数据
===================================
ISearchResult //接口 ,具体定义 可根据能实现这样效果定义
http://groups.google.com/group/cn.bbs.comp.dotnet/browse_thread/thread/9b9b089f5589e1d7/94407a473a6f44fd?lnk=st&q=c%23+%E5%AE%9E%E7%8E%B0+IEnumerable%2C+IEnumerator&rnum=1&hl=zh-CN#94407a473a6f44fdhttp://www.aspxboy.com/private/351/default.aspx
using System.Collections;public class Person
{
public Person(string fName, string lName)
{
this.firstName = fName;
this.lastName = lName;
} public string firstName;
public string lastName;
}public class People : IEnumerable
{
private Person[] _people;
public People(Person[] pArray)
{
_people = new Person[pArray.Length]; for (int i = 0; i < pArray.Length; i++)
{
_people[i] = pArray[i];
}
} public IEnumerator GetEnumerator()
{
return new PeopleEnum(_people);
}
}public class PeopleEnum : IEnumerator
{
public Person[] _people; // Enumerators are positioned before the first element
// until the first MoveNext() call.
int position = -1; public PeopleEnum(Person[] list)
{
_people = list;
} public bool MoveNext()
{
position++;
return (position < _people.Length);
} public void Reset()
{
position = -1;
} public object Current
{
get
{
try
{
return _people[position];
}
catch (IndexOutOfRangeException)
{
throw new InvalidOperationException();
}
}
}
}class App
{
static void Main()
{
Person[] peopleArray = new Person[3]
{
new Person("John", "Smith"),
new Person("Jim", "Johnson"),
new Person("Sue", "Rabon"),
}; People peopleList = new People(peopleArray);
foreach (Person p in peopleList)
Console.WriteLine(p.firstName + " " + p.lastName); }
}
{
public DataSource(ISearchResult result) : base(result)
{
} public string Subject
{
get { return this.HighlightValue("subject", 30); }
} public string Content
{
get { return this.HighlightValue("content", 200); }
} public string Author
{
get { return this.Value("author"); }
}
}
注意这个 没有:象 Author的值是调用父类的 value方法得到的,这点实现不明白。
{
public DataSource(ISearchResult result) : base(result)
{
} public string Subject
{
get { return this.HighlightValue("subject", 30); }
}
}
====
这样 不要 传个 已知的 Person[] 对象进去。