C# 如何将此表达式转换为LINQ
您好,我有这个FilterAlerts函数,我认为可以使用LINQ实现。我对C#相当陌生,需要帮助转换它。还有没有更好的方法可以最终为表达式指定错误C# 如何将此表达式转换为LINQ,c#,asp.net,.net,entity-framework,linq,C#,Asp.net,.net,Entity Framework,Linq,您好,我有这个FilterAlerts函数,我认为可以使用LINQ实现。我对C#相当陌生,需要帮助转换它。还有没有更好的方法可以最终为表达式指定错误 new public BusinessProfileStateModel Create(BusinessProfileViewModel profileViewModel) { var businessProfileState = base.Create(profileViewModel); if (pro
new public BusinessProfileStateModel Create(BusinessProfileViewModel profileViewModel)
{
var businessProfileState = base.Create(profileViewModel);
if (profileViewModel != null)
{
businessProfileState.DialogLocations = profileViewModel.DialogLocations;
businessProfileState.IsCommunityMember = profileViewModel.IsCommunityMember;
businessProfileState.IsLocalReport = profileViewModel.IsLocalReport;
businessProfileState.IsMultiLocation = profileViewModel.IsMultiLocation;
}
return FilterAlerts(businessProfileState);
}
private BusinessProfileStateModel FilterAlerts(BusinessProfileStateModel businessProfileStateModel)
{
var errors = new List<BPAlert>();
foreach (BPAlert alert in businessProfileStateModel.Display.Alerts.AllAlerts)
{
if (AlertFinderUtil.IsValidAlertTypeId(alert))
{
errors.Add(alert);
}
}
businessProfileStateModel.Display.Alerts.AllAlerts = errors;
return businessProfileStateModel;
}
}
新建公共BusinessProfileStateModel创建(BusinessProfileViewModel profileViewModel)
{
var businessProfileState=base.Create(profileViewModel);
如果(profileViewModel!=null)
{
businessProfileState.DialogLocations=profileViewModel.DialogLocations;
businessProfileState.IsCommunityMember=profileViewModel.IsCommunityMember;
businessProfileState.IsLocalReport=profileViewModel.IsLocalReport;
businessProfileState.IsMultiLocation=profileViewModel.IsMultiLocation;
}
返回FilterAlerts(businessProfileState);
}
私有BusinessProfileStateModel筛选器(BusinessProfileStateModel BusinessProfileStateModel)
{
var errors=新列表();
foreach(businessProfileStateModel.Display.Alerts.AllAllAlerts中的BPAlert警报)
{
if(AlertFinderUtil.IsValidAlertTypeId(alert))
{
错误。添加(警报);
}
}
businessProfileStateModel.Display.Alerts.AllAlerts=错误;
回归模型;
}
}
您可以试试这个
businessProfileStateModel.Display.Alerts.AllAlerts =
businessProfileState.Display.Alerts.AllAlerts.Where(alert => AlertFinderUtil.IsValidAlertTypeId(alert)).ToList();
希望有帮助 您缺少
AlertFinderUtil
,它可以是Where(AlertFinderUtil.IsValidAlertTypeId)
,因为该方法与委托匹配。如果通过引用传递,则添加到anwserYou,您的签名中可能应该包含关键字ref。