名前でリソースを並べ替えます

リソースのソート

Aspose.Tasksを使用してプロジェクトを操作する場合、プロジェクトリソースはどのフィールドでもソートできます。この記事は、名前でリソースをソートするために、icomparableインターフェイスを実装する方法を示しています。これを達成するために、まず、以下に示すように、比類のないインターフェイスを実装するクラスを定義します。次に、プロジェクトのリソースを横断し、名前で並べ替えます。

icomparableインターフェイスの実装

 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.