62,243
社区成员




@model IEnumerable<hengcms_mvc.Models.mf_ModuleClass>
public string strclass(int ClassID,IEnumerable<mf_ModuleClass> list)
{
//code
}
ClassHelper category = new ClassHelper();
category.strclass(3,Model);
@{
ClassHelper category = new ClassHelper();
IList<Category> List = new List<Category>();
foreach(var p in Model)
{
List.Add(new Category(){
ClassID = p.ClassID,
ClassName = p.ClassName,
ParentID = p.ParentID,
Depth = p.Depth,
Child = p.Child,
OrderID = p.OrderID,
Title = p.Title,
KeyWords = p.KeyWords,
Description = p.Description,
Content = p.Content,
ShowType = p.ShowType,
LinkUrl = p.LinkUrl,
Intro = p.Intro,
ClassPic = p.ClassPic,
ItemPic = p.ItemPic,
LanType = p.LanType,
IsHome = p.IsHome
});
}
category.strclass(3,List); //调用
}
public string strclass(int ClassID,IList<Category> list)
{
return list.Count().ToString();
}
public string strclass<T>(int ClassID,IEnumerable<T> list)
{
dynamic c = list.First();
return c.ClassName;
}
目前为止,我认为这应该是一种最佳的解决方案。[/quote]
mf_ModuleClass 如果你的model都有类似属性 那么你可以加个泛型限定 比如他们都继承自ICommon接口 你的className是一个公有属性
public string strclass<T>(int ClassID,IEnumerable<T> list)
where T:ICommon
{
T c = list.First();
return c.ClassName;
}
dynamic我的感觉是尽量少用 我目前在项目组仅仅用dynamic实现LDAP返回回来的信息的封装public string strclass<T>(int ClassID,IEnumerable<T> list)
{
dynamic c = list.First();
return c.ClassName;
}
目前为止,我认为这应该是一种最佳的解决方案。