Managing Resource Extended Attributes
Contents
[
Hide
Show
]The ExtendedAttribute property exposed by the Resource class can be used to manage the extended attributes of a resource. This property reads and writes an ArrayList of the ExtendedAttribute objects to deal with a resource’s extended attributes. The ExtendedAttribute object further exposes the relevant properties.
Setting Extended Resource Attributes with Aspose.Tasks
The following code example demonstrates how to set a resource’s extended attributes.
1// Create project instance
2System::SharedPtr<Project> project1 = System::MakeObject<Project>(dataDir + u"ResourceExtendedAttributes.mpp");
3
4// Define extended attribute
5System::SharedPtr<ExtendedAttributeDefinition> myNumber1 = project1->get_ExtendedAttributes()->GetById((int32_t)Aspose::Tasks::ExtendedAttributeTask::Number1);
6if (myNumber1 == nullptr)
7{
8 myNumber1 = ExtendedAttributeDefinition::CreateResourceDefinition(Aspose::Tasks::ExtendedAttributeResource::Number1, u"Age");
9 project1->get_ExtendedAttributes()->Add(myNumber1);
10}
11
12// Create extended attribute and set its value
13System::SharedPtr<ExtendedAttribute> number1Resource = myNumber1->CreateExtendedAttribute();
14number1Resource->set_NumericValue(System::Decimal("30.5345"));
15
16// Add a new resource and its extended attribute
17System::SharedPtr<Resource> rsc = project1->get_Resources()->Add(u"R1");
18rsc->get_ExtendedAttributes()->Add(number1Resource);
19
20// Save project as MPP
21project1->Save(dataDir + u"ResourceExtendedAttributes_out.mpp", Aspose::Tasks::Saving::SaveFileFormat::MPP);