Sorting Resources by Name

Contents
[ Hide Show ]

Sorting Resources by Name

Aspose.Tasks allows sorting of project resources by any of the fields like name etc. This article shows how to implement the IComparable interface to sort resources by name. To accomplish this, first, define a class that implements the IComparable interface as shown below. Then traverse the resources in the project and sort them by name.

 1private class RscNameComparer : IComparer<Resource>
 2{
 3    public int Compare(Resource x, Resource y)
 4    {
 5        if (string.IsNullOrEmpty(x.Get(Rsc.Name)))
 6        {
 7            return 1;
 8        }
 9
10        if (string.IsNullOrEmpty(y.Get(Rsc.Name)))
11        {
12            return -1;
13        }
14
15        return x.Get(Rsc.Name).CompareTo(y.Get(Rsc.Name));
16    }
17}
1Project project = new Project("New Project.mpp");
2
3List<Resource> resources = project.Resources.ToList();
4resources.Sort(new RscNameComparer());
5
6foreach (Resource resource in resources)
7{
8    Console.WriteLine(resource);
9}
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.