ResourceCollection class

Represents a collection of Resource objects.

public class ResourceCollection : IList<Resource>


Count { get; }Gets the number of elements contained in the ResourceCollection. Read-only Int32.
Item { get; set; }Returns the element at the specified index.
ParentProject { get; }Gets the parent project of the ResourceCollection object.


Add()Adds new resource at the last position of a project resources collection.
Add(string)Adds new resource at the last position of a project resources collection.
Add(string, int)Adds new resource at the specified position of a project resources collection.
Clear()Direct clearing is not supported, this method just throw NotSupportedException.
GetById(int)Returns a resource with the specified id.
GetByUid(int)Returns a resource with the specified Uid.
GetEnumerator()Returns an enumerator for this collection.
Remove(Resource)This is the stub implementation of ICollection’s Remove method, that only throws NotSupportedException
ToList()Converts the ResourceCollection object to a list of Resource objects.


Shows how to work with resource collections.

var project = new Project(DataDir + "SampleProject.mpp");

// add empty resource
var resource = project.Resources.Add();
resource.Set(Rsc.Type, ResourceType.Work);

// add resource with a name
var developer = project.Resources.Add("Developer");
developer.Set(Rsc.Type, ResourceType.Work);

// add resource before the resource with specified ID
var manager = project.Resources.Add("Manager", developer.Get(Rsc.Id));
manager.Set(Rsc.Type, ResourceType.Work);

var devResource = project.Resources.GetById(4);
devResource.Set(Rsc.Code, "12345");

var manResource = project.Resources.GetByUid(4);
manResource.Set(Rsc.Code, "54321");

// get resource by id

Console.WriteLine("Print the resources of " + project.Resources.ParentProject.Get(Prj.Name) + " project.");
Console.WriteLine("Count of resources: " + project.Resources.Count);
foreach (var rsc in project.Resources)
    Console.WriteLine("Resource Name: " + rsc.Get(Rsc.Name));


// resource collections does not support Clear operation
// project.Resources.Clear();
// use next code sample instead
List<Resource> list = project.Resources.ToList();
foreach (var rsc in list)

See Also