Сортировать ресурсы по имени
Contents
[
Hide
Show
]Сортировка ресурсов
При работе с проектом с использованием Aspose.Tasks ресурсы проекта могут быть отсортированы по любой из областей. Эта статья показывает, как реализовать Icomplable Interface для сортировки ресурсов по имени. Чтобы сделать это, сначала определите класс, который реализует Icomplable интерфейс, как показано ниже. Затем пройдите ресурсы в проекте и сортируйте их по имени.
Реализация Icomplable Interface
1int32_t SortResourcesByName::RscNameComparer::Compare(System::SharedPtr<Resource> const &x, System::SharedPtr<Resource> const &y) ASPOSE_CONST
2{
3 if (System::String::IsNullOrEmpty(x->Get<System::String>(Rsc::Name())))
4 {
5 return 1;
6 }
7 if (System::String::IsNullOrEmpty(y->Get<System::String>(Rsc::Name())))
8 {
9 return -1;
10 }
11 return x->Get<System::String>(Rsc::Name()).CompareTo(y->Get<System::String>(Rsc::Name()));
12}
Sorting Resources by Name
1System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"project-sort.mpp");
2
3System::SharedPtr<System::Collections::Generic::List<System::SharedPtr<Resource>>> resources = project->get_Resources()->ToList();
4resources->Sort(System::MakeObject<SortResourcesByName::RscNameComparer>());
5
6
7{
8 auto rsc_enumerator = (resources)->GetEnumerator();
9 decltype(rsc_enumerator->get_Current()) rsc;
10 while (rsc_enumerator->MoveNext() && (rsc = rsc_enumerator->get_Current(), true))
11 {
12 System::Console::WriteLine(rsc);
13 }
14}