Сортування ресурсів за іменем

Сортування ресурсів

Працюючи з проектом, що використовує Aspope.tasks, ресурси проекту можна сортувати за будь -якими полями. У цій статті показано, як реалізувати інтерфейс ICOMARABLE для сортування ресурсів за іменем. Для цього, спочатку, визначте клас, який реалізує інтерфейс, що містить IcomPrace, як показано нижче. Потім пройдіть ресурси в проекті та сортуйте їх по імені.

Впровадження інтерфейсу ICOMARABLE

 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}
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.