奇怪,接口问题,微软怎么做的?????????
大家都知道 DataTable 实现了 IListSource
参见msdn
[C#]
[Serializable]
public class DataTable : MarshalByValueComponent, IListSource,
ISupportInitialize, ISerializable
IListSource 有个方法GetList(); 返回 Ilist 接口
可是
我找遍DataTable的方法也没有GetList();这是如何实现的
问题点数:200、回复次数:18Top
1 楼hdt(倦怠)回复于 2005-05-30 19:44:42 得分 0
upTop
2 楼hjf1223(阿不)回复于 2005-05-30 19:49:11 得分 10
星星问问题很难得,我也UPTop
3 楼hdt(倦怠)回复于 2005-05-30 19:56:34 得分 0
星星也不一定是高手,只是专家分比较高
:)
谢谢捧场Top
4 楼hjf1223(阿不)回复于 2005-05-30 20:01:44 得分 0
那也不错呀!能得这么多专家分说明你很强啊。不管哪方面Top
5 楼CMIC(大象)回复于 2005-05-30 20:14:55 得分 60
http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/cpref/html/frlrfsystemcomponentmodelilistsourceclasstopic.asp
DataTable的GetList实现是
IList IListSource.GetList()
{
return DefaultView;
}
DefaultView实现了IListTop
6 楼fancyf(凡瑞)回复于 2005-05-30 20:15:35 得分 40
有这个方法,搂主再仔细找找
ILDasm 的结果:
.method private hidebysig newslot virtual final
instance class [mscorlib]System.Collections.IList
System.ComponentModel.IListSource.GetList() cil managed
{
.override [System]System.ComponentModel.IListSource::GetList
// 代码大小 7 (0x7)
.maxstack 2
IL_0000: ldarg.0
IL_0001: call instance class System.Data.DataView System.Data.DataTable::get_DefaultView()
IL_0006: ret
} // end of method DataTable::System.ComponentModel.IListSource.GetList
Reflector 的结果:
IList IListSource.GetList()
{
return this.DefaultView;
}
Top
7 楼fancyf(凡瑞)回复于 2005-05-30 20:17:58 得分 0
GetList是个私有方法
列表中不是以G开头的,找以S开头的,全称是
System.Data.DataTable.System.ComponentModel.IListSource.GetList() : IListTop
8 楼mba9001(两年不见,csdn变肥了)回复于 2005-05-30 20:33:18 得分 10
星星大哥也有大意的时候,但想不到有人钻研到这种地步了,这些问题都研究,两个字,佩服!
GetList(),Supported by the .NET "Compact" FrameworkTop
9 楼mba9001(两年不见,csdn变肥了)回复于 2005-05-30 20:36:19 得分 0
System.Data.DataTable.System.ComponentModel.IListSource.GetList()
??还有这样的?我开眼界了Top
10 楼zeusvenus()回复于 2005-05-30 20:39:09 得分 40
对于实现IListSource接口的对象,像DataTable,服务器控件总是会读取其IListSource的GetList返回的数据作为数据源
DataTable的GetList实现是
IList IListSource.GetList()
{
return DefaultView;
}
Top
11 楼fancyf(凡瑞)回复于 2005-05-30 20:39:53 得分 0
晕,我从Reflector中点右键复制的这个方法,结果Reflector给了这么个东东,Reflector的Bug!
System.Data.DataTable.System.ComponentModel.IListSource.GetList() : IList
应该是
System.ComponentModel.IListSource.GetList() : IList
Top
12 楼hdt(倦怠)回复于 2005-05-30 20:43:03 得分 0
看来是自己才疏学浅:
不过这个方法到底是public, private , protected ??
我做个实验:
public interface imy{
void test();
}
public class myclass:imy{
void imy.test();//这个方法无论用什么修饰符,读编译错误
}Top
13 楼zeusvenus()回复于 2005-05-30 20:46:14 得分 0
Sample 1:
Here is a code snippet provide by NoiseEHC on the microsoft.public.dotnet.framework.windowsforms.controls newsgroup that you can use to see exactly what mappingname is required for your datasource.
[C#]
//usage
ShowMappingName(dataGrid1.DataSource);
//implementation
void ShowMappingName(object src)
{
IList list = null;
Type type = null;
if(src is Array)
{
type = src.GetType();
list = src as IList;
}
else
{
if(src is IListSource)
src = (src as IListSource).GetList();
if(src is IList)
{
type = src.GetType();
list = src as IList;
}
else
{
MessageBox.Show("error");
return;
}
}
if(list is ITypedList)
MessageBox.Show((list as ITypedList).GetListName(null));
else
MessageBox.Show(type.Name);
}
Sample2:
Added a property, ContainsListCollection, to System.ComponentModel.IlistSource
The updated IListSource would be:
interface IListSource {
bool ContainsListCollection { get; }
IList GetList();
}
This change should not require code changes.Only DataSet and DataTable currently implement this interface.
Sample3:
internal static IEnumerable GetResolvedDataSource(object dataSource, string dataMember)
{
if (dataSource != null)
{
IListSource source1 = dataSource as IListSource;
if (source1 != null)
{
IList list1 = source1.GetList();
if (!source1.ContainsListCollection)
{
return list1;
}
if ((list1 != null) && (list1 is ITypedList))
{
ITypedList list2 = (ITypedList) list1;
PropertyDescriptorCollection collection1 = list2.GetItemProperties(new PropertyDescriptor[0]);
if ((collection1 == null) || (collection1.Count == 0))
{
throw new HttpException(HttpRuntime.FormatResourceString("ListSource_Without_DataMembers"));
}
PropertyDescriptor descriptor1 = null;
if ((dataMember == null) || (dataMember.Length == 0))
{
descriptor1 = collection1[0];
}
else
{
descriptor1 = collection1.Find(dataMember, true);
}
if (descriptor1 != null)
{
object obj1 = list1[0];
object obj2 = descriptor1.GetValue(obj1);
if ((obj2 != null) && (obj2 is IEnumerable))
{
return (IEnumerable) obj2;
}
}
throw new HttpException(HttpRuntime.FormatResourceString("ListSource_Missing_DataMember", dataMember));
}
}
if (dataSource is IEnumerable)
{
return (IEnumerable) dataSource;
}
}
return null;
}
Top
14 楼hdt(倦怠)回复于 2005-05-30 20:52:08 得分 0
晕发现自己对c#语法还有没了解的地方,
看了显示接口实现就明白了谢谢大家,一会接贴
ms-help://MS.MSDNQTR.2003FEB.2052/csspec/html/vclrfcsharpspec_13_4_1.htmTop
15 楼sunjian_qi(sonne)回复于 2005-05-30 20:55:07 得分 40
IList IListSource.GetList()
{
return this.DefaultView;
}
从Reflector查到的Top
16 楼fancyf(凡瑞)回复于 2005-05-30 20:57:24 得分 0
GetList没有修饰符,是个私有方法
定义接口根定义其他的函数一样
别跟Reflector学,不要加上接口的名字
void test()
{}
Top
17 楼zeusvenus()回复于 2005-05-30 21:03:23 得分 0
是啊,Reflector和部分MS自己的技术文档也不一定对,看来MS没有仔细反复测试过每个类库.Top
18 楼mba9001(两年不见,csdn变肥了)回复于 2005-05-30 21:51:02 得分 0
楼主,你真的很强!!你要多点张一些这么深入的贴!Top




