WeekDayCollection Class

Represents a collection of WeekDay objects.
Inheritance Hierarchy
SystemObject
  Aspose.TasksWeekDayCollection

Namespace:  Aspose.Tasks
Assembly:  Aspose.Tasks (in Aspose.Tasks.dll) Version: 21.10
Syntax
public class WeekDayCollection : IList<WeekDay>, 
	ICollection<WeekDay>, IEnumerable<WeekDay>, IEnumerable

The WeekDayCollection type exposes the following members.

Properties
  NameDescription
Public propertyCode exampleCount
Gets the number of objects contained in this WeekDayCollection object.
Public propertyCode exampleItem
Gets or sets the item value at specified index.
Methods
  NameDescription
Public methodCode exampleAdd
Adds a WeekDay instance to this object.
Public methodCode exampleClear
Clear the WeekDayCollection object.
Public methodCode exampleContains
Checks if collection contains WeekDay.specified.
Public methodCode exampleCopyTo
Copies collection content to an array at specified index.
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodCode exampleGetEnumerator
Returns an enumerator for this collection.
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodCode exampleIndexOf
Returns index of WeekDay specified.
Public methodCode exampleInsert
Inserts WeekDay at specified index.
Protected methodMemberwiseClone (Inherited from Object.)
Public methodCode exampleRemove
Removes WeekDay specified, if any.
Public methodCode exampleRemoveAt
Removes an item at specified index.
Public methodCode exampleToList
Converts the WeekDayCollection object to a list of WeekDay objects.
Public methodToString (Inherited from Object.)
Examples
Shows how to work week day collections.
var project = new Project();
var calendar = project.Calendars.GetByName("Standard");

// clear week days
calendar.WeekDays.Clear();

calendar.WeekDays.Add(WeekDay.CreateDefaultWorkingDay(DayType.Monday));
calendar.WeekDays.Add(WeekDay.CreateDefaultWorkingDay(DayType.Tuesday));
calendar.WeekDays.Add(WeekDay.CreateDefaultWorkingDay(DayType.Wednesday));
calendar.WeekDays.Add(WeekDay.CreateDefaultWorkingDay(DayType.Thursday));
calendar.WeekDays.Add(WeekDay.CreateDefaultWorkingDay(DayType.Friday));
var saturday = WeekDay.CreateDefaultWorkingDay(DayType.Saturday);
var sunday = WeekDay.CreateDefaultWorkingDay(DayType.Sunday);

calendar.WeekDays.Add(saturday);
calendar.WeekDays.Add(sunday);

var fridayWorkingTimes = new List<WorkingTime> { new WorkingTime(new DateTime(2020, 4, 13, 8, 0, 0), new DateTime(2020, 4, 13, 12, 0, 0)) };

var friday = new WeekDay(DayType.Friday, fridayWorkingTimes);
if (calendar.WeekDays.Contains(friday))
{
    calendar.WeekDays.Insert(4, friday);
}

Console.WriteLine("Calendar: " + calendar.Name);
Console.WriteLine("Week days count: " + calendar.WeekDays.Count);
foreach (var day in calendar.WeekDays)
{
    Console.WriteLine(day.DayType);
    foreach (var workingTime in day.WorkingTimes)
    {
        Console.WriteLine("From: " + workingTime.FromTime);
        Console.WriteLine("To: " + workingTime.ToTime);
        Console.WriteLine();
    }
}

// remove saturday week day
calendar.WeekDays.RemoveAt(5);

// remove sunday week day
if (calendar.WeekDays.IndexOf(saturday) > 0)
{
    calendar.WeekDays.Remove(sunday);
}

Console.WriteLine("Working times after weekend was removed: ");
List<WeekDay> weekDays = calendar.WeekDays.ToList();
foreach (var day in weekDays)
{
    Console.WriteLine(day.DayType);
    foreach (var workingTime in day.WorkingTimes)
    {
        Console.WriteLine("From: " + workingTime.FromTime);
        Console.WriteLine("To: " + workingTime.ToTime);
        Console.WriteLine();
    }
}

var hour24Calendar = project.Calendars.Add("24 Hours");
Calendar.Make24HourCalendar(hour24Calendar);

// copy week days
var weekDaysArray = new WeekDay[calendar.WeekDays.Count];
calendar.WeekDays.CopyTo(weekDaysArray, 0);

foreach (var weekDay in weekDaysArray)
{
    hour24Calendar.WeekDays.Add(weekDay);
}
See Also