ExtendedAttributeDefinition.CreateExtendedAttribute
CreateExtendedAttribute()
Creates a new extended attribute with the field ID which equals to this object’s field ID value.
public ExtendedAttribute CreateExtendedAttribute()
Return Value
returns created instance of the ExtendedAttribute
class with the fieldID which equals to this object’s fieldID value.
Examples
Shows how to create extended attributes.
var project = new Project(DataDir + "Blank2010.mpp");
var definition = project.ExtendedAttributes.GetById((int)ExtendedAttributeTask.Text1);
// If the Custom field doesn't exist in Project, create it
if (definition == null)
{
definition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Text1, "My text field");
project.ExtendedAttributes.Add(definition);
}
// Generate Extended Attribute from definition
var attribute = definition.CreateExtendedAttribute();
attribute.TextValue = "Text attribute value";
// Add extended attribute to task
var task = project.RootTask.Children.Add("Task 1");
task.ExtendedAttributes.Add(attribute);
project.Save(OutDir + "CreateExtendedAttributes_out.mpp", SaveFileFormat.Mpp);
See Also
- class ExtendedAttribute
- class ExtendedAttributeDefinition
- namespace Aspose.Tasks
- assembly Aspose.Tasks
CreateExtendedAttribute(string)
Creates a new extended attribute with the field ID which equals to this object’s field ID value and the specified text value.
public ExtendedAttribute CreateExtendedAttribute(string textValue)
Parameter | Type | Description |
---|---|---|
textValue | String | The specified text value. |
Return Value
returns created instance of the ExtendedAttribute
class with the fieldID which equals to this object’s fieldID value.
Exceptions
exception | condition |
---|---|
InvalidOperationException | If current CfType is not ‘Text’ |
Examples
Shows how to create extended attribute definition and set a string value of the attribute while its constructing.
var project = new Project(DataDir + "Project2.mpp");
var definition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Text1, "My Text");
project.ExtendedAttributes.Add(definition);
var task = project.RootTask.Children.Add("Task");
task.Set(Tsk.Start, new DateTime(2020, 4, 22, 8, 0, 0));
task.Set(Tsk.Duration, project.GetDuration(1, TimeUnitType.Day));
// create extended attribute with a value equals to the 'Common Info'
var extendedAttribute = definition.CreateExtendedAttribute("Common Info");
// add extended attribute initialized by value the 'Common Info'
task.ExtendedAttributes.Add(extendedAttribute);
See Also
- class ExtendedAttribute
- class ExtendedAttributeDefinition
- namespace Aspose.Tasks
- assembly Aspose.Tasks
CreateExtendedAttribute(decimal)
Creates a new extended attribute with the field ID which equals to this object’s field ID value and the specified numeric value.
public ExtendedAttribute CreateExtendedAttribute(decimal numericValue)
Parameter | Type | Description |
---|---|---|
numericValue | Decimal | The specified numeric value. |
Return Value
returns created instance of the ExtendedAttribute
class with the fieldID which equals to this object’s fieldID value.
Exceptions
exception | condition |
---|---|
InvalidOperationException | If current CfType is not ‘Number’ or ‘Cost’ |
Examples
Shows how to create extended attribute definition and set a decimal value of the attribute while its constructing.
var project = new Project(DataDir + "Project2.mpp");
var definition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Cost1, "My Cost");
project.ExtendedAttributes.Add(definition);
var task = project.RootTask.Children.Add("Task");
task.Set(Tsk.Start, new DateTime(2020, 4, 22, 8, 0, 0));
task.Set(Tsk.Duration, project.GetDuration(1, TimeUnitType.Day));
// create extended attribute with a value equals to 999m
var extendedAttribute = definition.CreateExtendedAttribute(999m);
// add extended attribute initialized by value 999m
task.ExtendedAttributes.Add(extendedAttribute);
See Also
- class ExtendedAttribute
- class ExtendedAttributeDefinition
- namespace Aspose.Tasks
- assembly Aspose.Tasks
CreateExtendedAttribute(DateTime)
Creates a new extended attribute with the field ID which equals to this object’s field ID value and the specified date value.
public ExtendedAttribute CreateExtendedAttribute(DateTime dateTimeValue)
Parameter | Type | Description |
---|---|---|
dateTimeValue | DateTime | The specified date time value. |
Return Value
returns created instance of the ExtendedAttribute
class with the fieldID which equals to this object’s fieldID value.
Exceptions
exception | condition |
---|---|
InvalidOperationException | If current CfType is not ‘Date’, ‘Start’ or ‘Finish’ |
Examples
Shows how to create extended attribute definition and set a datetime value of the attribute while its constructing.
var project = new Project(DataDir + "Project2.mpp");
var definitionWithDate = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Date1, "My Date");
project.ExtendedAttributes.Add(definitionWithDate);
var task = project.RootTask.Children.Add("Task");
task.Set(Tsk.Start, new DateTime(2020, 4, 22, 8, 0, 0));
task.Set(Tsk.Duration, project.GetDuration(1, TimeUnitType.Day));
// create extended attribute with a value equals to DateTime.Now
var extendedAttribute = definitionWithDate.CreateExtendedAttribute(DateTime.Now);
// add extended attribute
task.ExtendedAttributes.Add(extendedAttribute);
See Also
- class ExtendedAttribute
- class ExtendedAttributeDefinition
- namespace Aspose.Tasks
- assembly Aspose.Tasks
CreateExtendedAttribute(Duration)
Creates a new extended attribute with the field ID which equals to this object’s field ID value and the specified duration value.
public ExtendedAttribute CreateExtendedAttribute(Duration durationValue)
Parameter | Type | Description |
---|---|---|
durationValue | Duration | The specified duration value. |
Return Value
returns created instance of the ExtendedAttribute
class with the fieldID which equals to this object’s fieldID value.
Exceptions
exception | condition |
---|---|
InvalidOperationException | If current CfType is not ‘Duration’ |
Examples
Shows how to create extended attribute definition and set a duration while its constructing.
var project = new Project(DataDir + "Project2.mpp");
var task = project.RootTask.Children.Add("Test");
task.Set(Tsk.Start, new DateTime(2020, 4, 22, 8, 0, 0));
task.Set(Tsk.Duration, project.GetDuration(1, TimeUnitType.Day));
var definition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Duration1, "Custom Duration");
project.ExtendedAttributes.Add(definition);
// extended attribute Duration1 = 2 days
var extendedAttribute = definition.CreateExtendedAttribute(project.GetDuration(2, TimeUnitType.Day));
// add extended attribute to the task
task.ExtendedAttributes.Add(extendedAttribute);
See Also
- class ExtendedAttribute
- struct Duration
- class ExtendedAttributeDefinition
- namespace Aspose.Tasks
- assembly Aspose.Tasks
CreateExtendedAttribute(bool)
Creates a new extended attribute with the field ID which equals to this object’s field ID value and the specified flag value.
public ExtendedAttribute CreateExtendedAttribute(bool flagValue)
Parameter | Type | Description |
---|---|---|
flagValue | Boolean | The specified flag value. |
Return Value
returns created instance of the ExtendedAttribute
class with the fieldID which equals to this object’s fieldID value.
Exceptions
exception | condition |
---|---|
InvalidOperationException | If current CfType is not ‘Flag’ |
Examples
Shows how to create extended attribute definition and set a value of a flag while its constructing.
var project = new Project(DataDir + "Project2.mpp");
var resource = project.Resources.Add("Resource 1");
resource.Set(Rsc.Type, ResourceType.Cost);
// create a definition for a boolean custom field
var definition = ExtendedAttributeDefinition.CreateResourceDefinition(ExtendedAttributeResource.Flag7, "My Custom Flag");
// create an attribute and set the initial value to 'true'
var attribute = definition.CreateExtendedAttribute(true);
resource.ExtendedAttributes.Add(attribute);
See Also
- class ExtendedAttribute
- class ExtendedAttributeDefinition
- namespace Aspose.Tasks
- assembly Aspose.Tasks
CreateExtendedAttribute(Value)
Creates new extended attribute linked with specified Value
item.
public ExtendedAttribute CreateExtendedAttribute(Value lookupValue)
Parameter | Type | Description |
---|---|---|
lookupValue | Value | The specified Value item. |
Return Value
returns created instance of the ExtendedAttribute
class linked with specified Value
item.
Remarks
lookupValue should be previously added to the ExtendedAttributeDefinition
using AddLookupValue
method.
Examples
Use this code to create new ExtendedAttribute
using specific value:
taskTextAttr.AddLookupValue(value1);
taskTextAttr.AddLookupValue(value2);
var extendedAttribute = taskTextAttr.CreateExtendedAttribute(value2);
Shows how to create extended attribute definition and set a value while its constructing.
var project = new Project(DataDir + "Project2.mpp");
// Create a custom field definition based on the lookup table, which was declared above.
var customFieldDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(CustomFieldType.Number, ExtendedAttributeTask.Number10, "Status");
var value1 = new Value { Id = 1, Val = "25", Description = "Active" };
var value2 = new Value { Id = 2, Val = "12", Description = "Inactive" };
customFieldDefinition.AddLookupValue(value1);
customFieldDefinition.AddLookupValue(value2);
project.ExtendedAttributes.Add(customFieldDefinition);
var task = project.RootTask.Children.Add("Task");
// create extended attribute for a value
var extendedAttribute = customFieldDefinition.CreateExtendedAttribute(value2);
// add extended attribute to the task
task.ExtendedAttributes.Add(extendedAttribute);
See Also
- class ExtendedAttribute
- class Value
- class ExtendedAttributeDefinition
- namespace Aspose.Tasks
- assembly Aspose.Tasks