我脑子里死了; 我根据特定的类(c1,c2,c3 ......)定义了几个List'.我有一个方法来处理这些列表上的信息.我想要做的是传递特定列表,但让方法接受通用列表,然后通过typeof确定要执行的具体工作.我知道它可能,但我似乎无法在方法方面获得正确的语法.所以,例如:
List<c1> c1var;
List<c2> c2var;
List<c3> c3var;
some_method(c1var);
some_method(c2var);
some_method(c3var);
class some_thing
some_method(List<> somevar)
if typeof(somevar).name = x then
esle if typeof(somevar).name = y then....
Run Code Online (Sandbox Code Playgroud)
如何设置方法的参数列表?
谢谢R.桑德斯
就像标题所说,我有以下例外:
描述:事件代码:3005事件消息:发生了未处理的异常.异常信息:异常类型:NotSupportedException异常消息:不允许在查询中显式构造实体类型"Company.Project.Core.Domain.Friend".
我正在使用LINQ to SQL并在我的datacontext中使用以下代码:
var friends2 = (
from f in dc.Friends
where f.MyFriendsAccountId == accountId
where f.AccountId != accountId
select new
{
f.FriendId,
AccountId = f.MyFriendsAccountId,
MyFriendsAccountId = f.AccountId,
f.CreateDate,
f.Timestamp
}).Distinct();
result.AddRange(
from o in friends2
select new Friend()
{
FriendId = o.FriendId,
AccountId = o.AccountId,
CreateDate = o.CreateDate,
MyFriendsAccountId = o.MyFriendsAccountId,
Timestamp = o.Timestamp
});
Run Code Online (Sandbox Code Playgroud)
最后的代码块抛出错误,我很确定这个声明是罪魁祸首:
.Select( o => **new Friend**
Run Code Online (Sandbox Code Playgroud)
我应该如何重新编写代码以避免此错误?