[英]get a particular property value using Linq to C#
I created a class with properties like this 我创建了一个具有这样的属性的类
public class Dependencies
{
public string issueID { get; set; }
public string status { get; set; }
public int dependencyCheck { get; set; }
}
Now I created a method where i can use these properties. 现在我创建了一个方法,我可以使用这些属性。
private static void prepareIssuesList(string IssueKey, string JIRAtoken)
{
Dependencies dpObj = new Dependencies();
List<Dependencies> listObj = new List<Dependencies>();
dpObj.issueID = IssueKey;
dpObj.status = "open";
dpObj.dependencyCheck = 0;
listObj.Add(dpObj);
}
Now my question is, how to change the dependencyCheck
property value. 现在我的问题是,如何更改
dependencyCheck
属性值。 The prepareIssuesList()
can called for multiple times. prepareIssuesList()
可以多次调用。 So i am adding multiple objects to Dependencies class. 所以我在Dependencies类中添加了多个对象。 At certain point of time i want to change the dependencyCheck property value.
在某些时间点我想更改dependencyCheck属性值。 How to do this.
这个怎么做。 I think need to use the Linq to C#.
我认为需要使用Linq来C#。 ICan any one have any solution for this one?
ICan任何人都有这个解决方案吗?
I would do something along these lines: 我会沿着这些方向做点什么:
public class Dependency
{
public string IssueId { get; set; }
public string Status { get; set; }
public int DependencyCheck { get; set; }
}
public class DependencyManager
{
public DependencyManager()
{
this.Dependencies = new List<Dependency>();
}
public List<Dependency> Dependencies { get; private set; }
public void AddDependency(string issueId)
{
var dep = new Dependency();
dep.IssueId = issueId;
dep.Status = "open";
dep.DependencyCheck = 0;
this.Dependencies.Add(dep);
}
public void SetDependencyCheck(string issueId, int value)
{
var dep = this.FindDependencyByIssueId(issueId);
dep.DependencyCheck = value;
}
public Dependency FindDependencyByIssueId(string issueId)
{
var dep = this.Dependencies.FirstOrDefault(d => d.IssueId.Equals(issueId));
if(dep == null) throw new ArgumentException("Dependency not found", "issueId");
return dep;
}
}
Then somewhere in your code you could do: 然后在你的代码中的某个地方你可以做到:
var mgr = new DependencyManager();
mgr.AddDependency("ABC123");
mgr.AddDependency("ABC456");
//... some other stuff that makes sense
mgr.SetDependecyCheck("ABC123", 42);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.