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

자원 분류

Aspose.Tasks를 사용하여 프로젝트를 사용하면 프로젝트 리소스를 모든 필드에서 정렬 할 수 있습니다. 이 기사에서는 자원을 이름별로 정렬하기 위해 ICompayable 인터페이스를 구현하는 방법을 보여줍니다. 이를 달성하기 위해 먼저, 아래와 같이 비교 가능한 인터페이스를 구현하는 클래스를 정의하십시오. 그런 다음 프로젝트의 리소스를 통과하고 이름으로 정렬하십시오.

icomparyable 인터페이스 구현

 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.