ExtendedAttributeDefinition

ExtendedAttributeDefinition class

Represents an extended attribute definition associated with a project.

public class ExtendedAttributeDefinition

Properties

NameDescription
Alias { get; set; }Gets or sets the alias of a custom field.
AppendNewValues { get; set; }Gets or sets a value indicating whether new values added to a project are automatically added to the list.
AutoRollDown { get; set; }Gets or sets a value indicating whether an automatic roll down to assignments is enabled.
CalculationType { get; set; }Gets or sets the type of calculation of the custom attribute’s value.
CfType { get; }Gets the type of a custom field.
Default { get; set; }Gets or sets the default value in the list.
DefaultGuid { get; set; }Gets or sets the Guid of the default lookup table entry.
ElementType { get; set; }Gets or sets the extended attribute is associated with a task, a resource or an assignment.
FieldId { get; set; }Gets or sets corresponds to the project id of a custom field. Use string representation of a constant from ExtendedAttributeTask class to specify FieldId property.
FieldName { get; }Gets the name of a custom field.
Formula { get; set; }Gets or sets the formula that Microsoft Project uses to populate a custom task field.
Guid { get; set; }Gets or sets the Guid of a custom field.
LookupUid { get; }Gets a Guid of the lookup table associated with a custom field.
MaxMultiValues { get; set; }Gets or sets the maximum number of values you can set in a pick list.
ParentProject { get; }Gets the parent project for the ExtendedAttributeDefinition instance.
PhoneticsAlias { get; set; }Gets or sets the phonetic pronunciation of the alias of a custom field.
RestrictValues { get; set; }Gets or sets a value indicating whether the custom field values are restricted to values in the ValueList.
RollupType { get; set; }Gets or sets the way rollups are calculated.
SecondaryGuid { get; set; }Gets or sets the secondary guid of extended attribute.
SecondaryPid { get; set; }Gets or sets the secondary PID of a custom field.
SummaryRowsCalculationType { get; set; }Gets or sets the type of calculation of the custom attribute’s value for summary rows.
UserDef { get; set; }Gets or sets a value indicating whether a custom field is user defined.
ValueList { get; }Gets the List<Value> ValueList.
ValuelistSortOrder { get; set; }Gets or sets the way value lists are sorted. Values are: 0=Descending, 1=Ascending.

Methods

NameDescription
static CreateLookupResourceDefinition(ExtendedAttributeResource, string)Factory method which creates an extended attribute definition with lookup. It has CalculationType equals to Lookup and can be used in Resources only. You are required to specify fieldId and alias when call this method. The field type is inferred from field id.
static CreateLookupResourceDefinition(CustomFieldType, ExtendedAttributeResource, string)Factory method which creates an extended attribute definition with lookup. It has CalculationType equals to Lookup and can be used in Resources only. You are required to specify customFieldType, fieldId and alias when call this method.
static CreateLookupTaskDefinition(ExtendedAttributeTask, string)Factory method which creates an extended attribute definition with lookup. It has CalculationType equals to Lookup and can be used in Tasks only. You are required to specify fieldId and alias when call this method. The field type is inferred from field id.
static CreateLookupTaskDefinition(CustomFieldType, ExtendedAttributeTask, string)Factory method which creates an extended attribute definition with lookup. It has CalculationType equals to Lookup and can be used in Tasks only. You are required to specify customFieldType, fieldId and alias when call this method.
static CreateResourceDefinition(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 fieldId and alias when call this method. The field type is inferred from field id.
static CreateResourceDefinition(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.
static CreateTaskDefinition(ExtendedAttributeTask, 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 Tasks only. You are required to specify fieldId and alias when calling this method. The field type is inferred from field id.
static CreateTaskDefinition(CustomFieldType, ExtendedAttributeTask, 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 Tasks only. You are required to specify customFieldType, fieldId and alias when calling this method.
AddLookupValue(Value)Adds a value to the internal lookup list. This is a preferable way for manipulations with the ValueList.
CreateExtendedAttribute()Creates a new extended attribute with the field ID which equals to this object’s field ID value.
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.
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.
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.
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.
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.
CreateExtendedAttribute(Value)Creates new extended attribute linked with specified Value item.
override Equals(object)Returns a flag indicating whether this instance is equal to the specified object.
override GetHashCode()Returns a hash code for the instance of the ExtendedAttributeDefinition class.
RemoveLookupValue(Value)Removes a value from the internal lookup list. This is a preferable way for manipulations with the ValueList.

Examples

Shows how to use common math functions with extended attributes.

public static void EvaluateChoose()
{
    var project = CreateTestProjectWithCustomField();

    // Set Formula
    project.ExtendedAttributes[0].Formula = "Choose(3, \"This is a\", \"right\", \"choice\")";

    // Print extended attribute value
    var task = project.RootTask.Children.GetById(1);
    Console.WriteLine(task.ExtendedAttributes[0].TextValue);
}

public static void EvaluateIsNumeric()
{
    string[] numericFormulas =
        {
            "IsNumeric('AAA')", @"IsNUmeric(1)", "IsNumeric(1<0)", "IsNumeric(\"1.1\")", "IsNumeric(Choose((2 + Sgn(2^-3)), 123, \"one two three\"))"
        };

    var project = CreateTestProjectWithCustomField();

    foreach (var numericFormula in numericFormulas)
    {
        // Set Formula
        project.ExtendedAttributes[0].Formula = numericFormula;

        // Print extended attribute value
        var task = project.RootTask.Children.GetById(1);
        Console.WriteLine(task.ExtendedAttributes[0].TextValue);
    }
}

public static void EvaluateSwitch()
{
    var project = CreateTestProjectWithCustomField();

    // Set Formula
    project.ExtendedAttributes[0].Formula = "Switch( 0 < 1, \"0 is lesser than 1\", 0 > 1, \"0 is greater than 1\")";

    // Print extended attribute value
    var task = project.RootTask.Children.GetById(1);
    Console.WriteLine(task.ExtendedAttributes[0].TextValue);
}

public static Project CreateTestProjectWithCustomField()
{
    var project = new Project();
    var definition = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Text, ExtendedAttributeTask.Text1, "Custom Field");
    project.ExtendedAttributes.Add(definition);

    var task = project.RootTask.Children.Add("Task");

    var attribute = definition.CreateExtendedAttribute();
    task.ExtendedAttributes.Add(attribute);
    return project;
}

See Also