gpt4 book ai didi

linq - 更正 LINQ to SharePoint 查询中的多选值

转载 作者:行者123 更新时间:2023-12-01 23:26:07 25 4
gpt4 key购买 nike

我正在使用 LINQ to SharePoint 查询从 SharePoint 列表返回项目。

var myOpenTasksQuery = from myTasks in tasks
where myTasks.TaskStatus != TaskStatus.Completed
select myTasks

但是,我查询的列表,一个OOTB Tasks列表,里面有多个多选字段(Status,Priority),翻译成枚举。在我的查询结果中,任务项状态返回为“_2Normal”,而不是我预期的“(2) Normal”。我在 SPMetal.exe 生成的代理文件中看到,任务状态枚举有一个 ChoiceAttribute,其中包含我需要的值:

public enum Priority : int {

None = 0,

Invalid = 1,

[Microsoft.SharePoint.Linq.ChoiceAttribute(Value="(1) High")]
_1High = 2,

[Microsoft.SharePoint.Linq.ChoiceAttribute(Value="(2) Normal")]
_2Normal = 4,

[Microsoft.SharePoint.Linq.ChoiceAttribute(Value="(3) Low")]
_3Low = 8,
}

如何修改上面的查询以返回正确的值?

谢谢,MagicAndi。

最佳答案

尝试使用此扩展方法获取枚举的实际字符串值。

foreach (var o in  myOpenTasksQuery)
{
Console.WriteLine(o.Priority.StringValueOf());
}



public static class Extensions
{
public static string StringValueOf(this Enum value)
{
FieldInfo fi = value.GetType().GetField(value.ToString());
Microsoft.SharePoint.Linq.ChoiceAttribute[] attributes =
(Microsoft.SharePoint.Linq.ChoiceAttribute[])fi.GetCustomAttributes(
typeof(Microsoft.SharePoint.Linq.ChoiceAttribute), false);
if (attributes.Length > 0)
{
return attributes[0].Value;
}
else
{
return value.ToString();
}
}
}

关于linq - 更正 LINQ to SharePoint 查询中的多选值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3771747/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com