奇怪,接口问题,微软怎么做的?????????

真相重于对错 2005-05-30 07:35:41
大家都知道 DataTable 实现了 IListSource
参见msdn
[C#]
[Serializable]
public class DataTable : MarshalByValueComponent, IListSource,
ISupportInitialize, ISerializable
IListSource 有个方法GetList(); 返回 Ilist 接口
可是
我找遍DataTable的方法也没有GetList();这是如何实现的

...全文
193 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
mba9001 2005-05-30
  • 打赏
  • 举报
回复
楼主,你真的很强!!你要多点张一些这么深入的贴!
zeusvenus 2005-05-30
  • 打赏
  • 举报
回复
是啊,Reflector和部分MS自己的技术文档也不一定对,看来MS没有仔细反复测试过每个类库.
fanruinet 2005-05-30
  • 打赏
  • 举报
回复
GetList没有修饰符,是个私有方法

定义接口根定义其他的函数一样
别跟Reflector学,不要加上接口的名字
void test()
{}
凨叔 2005-05-30
  • 打赏
  • 举报
回复
IList IListSource.GetList()
{
return this.DefaultView;
}
从Reflector查到的
真相重于对错 2005-05-30
  • 打赏
  • 举报
回复
晕发现自己对c#语法还有没了解的地方,
看了显示接口实现就明白了谢谢大家,一会接贴
ms-help://MS.MSDNQTR.2003FEB.2052/csspec/html/vclrfcsharpspec_13_4_1.htm
zeusvenus 2005-05-30
  • 打赏
  • 举报
回复
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;
}


真相重于对错 2005-05-30
  • 打赏
  • 举报
回复
看来是自己才疏学浅:
不过这个方法到底是public, private , protected ??
我做个实验:
public interface imy{
void test();
}
public class myclass:imy{
void imy.test();//这个方法无论用什么修饰符,读编译错误
}
fanruinet 2005-05-30
  • 打赏
  • 举报
回复
晕,我从Reflector中点右键复制的这个方法,结果Reflector给了这么个东东,Reflector的Bug!
System.Data.DataTable.System.ComponentModel.IListSource.GetList() : IList
应该是
System.ComponentModel.IListSource.GetList() : IList
zeusvenus 2005-05-30
  • 打赏
  • 举报
回复
对于实现IListSource接口的对象,像DataTable,服务器控件总是会读取其IListSource的GetList返回的数据作为数据源
DataTable的GetList实现是
IList IListSource.GetList()
{
return DefaultView;
}
mba9001 2005-05-30
  • 打赏
  • 举报
回复
System.Data.DataTable.System.ComponentModel.IListSource.GetList()

??还有这样的?我开眼界了
mba9001 2005-05-30
  • 打赏
  • 举报
回复
星星大哥也有大意的时候,但想不到有人钻研到这种地步了,这些问题都研究,两个字,佩服!
GetList(),Supported by the .NET "Compact" Framework
fanruinet 2005-05-30
  • 打赏
  • 举报
回复
GetList是个私有方法
列表中不是以G开头的,找以S开头的,全称是
System.Data.DataTable.System.ComponentModel.IListSource.GetList() : IList
fanruinet 2005-05-30
  • 打赏
  • 举报
回复
有这个方法,搂主再仔细找找
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;
}

CMIC 2005-05-30
  • 打赏
  • 举报
回复
http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/cpref/html/frlrfsystemcomponentmodelilistsourceclasstopic.asp

DataTable的GetList实现是

IList IListSource.GetList()
{
return DefaultView;
}
DefaultView实现了IList
hjf1223 2005-05-30
  • 打赏
  • 举报
回复
那也不错呀!能得这么多专家分说明你很强啊。不管哪方面
真相重于对错 2005-05-30
  • 打赏
  • 举报
回复
星星也不一定是高手,只是专家分比较高
:)
谢谢捧场
hjf1223 2005-05-30
  • 打赏
  • 举报
回复
星星问问题很难得,我也UP
真相重于对错 2005-05-30
  • 打赏
  • 举报
回复
up

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧