ExtendedAttributeDefinitionCreateResourceDefinition Method (CustomFieldType, ExtendedAttributeResource, String)

Factory method which creates a simple extended attribute definition, which Microsoft Project shows as "None". It has CalculationType equals to None and can be used in Resource only. You are required to specify customFieldType, fieldId and alias when call this method.

Namespace:  Aspose.Tasks
Assembly:  Aspose.Tasks (in Aspose.Tasks.dll) Version: 21.5
Syntax
public static ExtendedAttributeDefinition CreateResourceDefinition(
	CustomFieldType customFieldType,
	ExtendedAttributeResource fieldId,
	string alias
)

Parameters

customFieldType
Type: Aspose.TasksCustomFieldType
The specified CustomFieldType type.
fieldId
Type: Aspose.TasksExtendedAttributeResource
The specified ExtendedAttributeResource field ID.
alias
Type: SystemString
The specified String alias.

Return Value

Type: ExtendedAttributeDefinition
Created instance of the ExtendedAttributeDefinition class with specified customFieldType, fieldId and alias.
Examples
Use this example to create a custom text field definition:
var resourceTextAttr = ExtendedAttributeDefinition.CreateResourceDefinition(CustomFieldType.Text, ExtendedAttributeResource.Text27, "My custom field");
project.ExtendedAttributes.Add(resourceTextAttr);
Examples
Shows how to add extended attribute to a resource assignment.
var project = new Project(DataDir + "Blank2010.mpp");

// Add new task and resource
var task = project.RootTask.Children.Add("Task");
var resource = project.Resources.Add("Rsc");
var assignment = project.ResourceAssignments.Add(task, resource);
{
    // Custom attributes which is visible in "Resource Usage" view can be created with ExtendedAttributeDefinition.CreateResourceDefinition method.
    var resCostAttributeDefinition = ExtendedAttributeDefinition.CreateResourceDefinition(
        CustomFieldType.Cost,
        ExtendedAttributeResource.Cost5,
        "My cost");

    project.ExtendedAttributes.Add(resCostAttributeDefinition);

    var value = resCostAttributeDefinition.CreateExtendedAttribute();

    // The type of the attribute is "Cost", so we need to use "NumericValue" property.
    value.NumericValue = 1500;

    assignment.ExtendedAttributes.Add(value);
}

{
    // Custom attributes which is visible in "Task Usage" view can be created with ExtendedAttributeDefinition.CreateTaskDefinition method
    var taskCostAttributeDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(
        CustomFieldType.Cost,
        ExtendedAttributeTask.Cost5,
        "My cost for task");

    project.ExtendedAttributes.Add(taskCostAttributeDefinition);

    var value = taskCostAttributeDefinition.CreateExtendedAttribute();

    // The type of the attribute is "Cost", so we need to use "NumericValue" property.
    value.NumericValue = 2300;

    assignment.ExtendedAttributes.Add(value);
}

project.Save(OutDir + "AddExtendedAttributesToResourceAssignment_out.mpp", SaveFileFormat.MPP);
See Also