이름으로 리소스를 정렬합니다

이름으로 리소스 분류

aspose.tasks for .net은 이름을 포함한 다양한 필드를 기반으로 프로젝트 리소스를 정렬 할 수 있습니다. 이 안내서는 사용자 정의 비교를 사용하여 이름별로 리소스를 정렬하는 방법을 보여줍니다.

사용자 정의 비교를 구현합니다

이름으로 리소스를 정렬하려면icomparer <resource>인터페이스를 구현하는 클래스를 만듭니다.

 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}

Loading and Sorting Resources

Once the comparer is defined, you can load a project and sort its resources:

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}

This approach ensures that resources are listed in alphabetical order by their names, while handling cases where the name field is missing or empty.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.