//
// Copyright © Nick Lowe 2009
//
// Nick Lowe
// nick@int-r.net
// http://processprivileges.codeplex.com/
namespace ProcessPrivileges
{
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
/// Read-only collection of privilege and attributes.
[Serializable]
public sealed class PrivilegeAndAttributesCollection : ReadOnlyCollection
{
internal PrivilegeAndAttributesCollection(IList list)
: base(list)
{
}
/// Returns a representation of the collection.
/// representation of the collection.
public override string ToString()
{
StringBuilder stringBuilder = new StringBuilder();
int maxPrivilegeLength = this.Max(privilegeAndAttributes => privilegeAndAttributes.Privilege.ToString().Length);
foreach (PrivilegeAndAttributes privilegeAndAttributes in this)
{
stringBuilder.Append(privilegeAndAttributes.Privilege);
int paddingLength = maxPrivilegeLength - privilegeAndAttributes.Privilege.ToString().Length;
char[] padding = new char[paddingLength];
for (int i = 0; i < paddingLength; i++)
{
padding[i] = ' ';
}
stringBuilder.Append(padding);
stringBuilder.Append(" => ");
stringBuilder.AppendLine(privilegeAndAttributes.PrivilegeAttributes.ToString());
}
return stringBuilder.ToString();
}
}
}