Namespace: System.Net.Security.CAS

ApplicationTrustCollection Class

Class
Inheritance: Object > ApplicationTrustCollection

Description

Represents a collection of ApplicationTrust objects.

The ApplicationTrustCollection class is used to manage a list of code groups that are granted to applications. Each ApplicationTrust object in the collection represents a specific application and the permissions granted to it.

Syntax

public sealed class ApplicationTrustCollection : CollectionBase

Remarks

Inheritance

  • Object
  • CollectionBase
  • ApplicationTrustCollection

Implements

  • IList
  • ICollection
  • IEnumerable

Constructors

Constructor Description
ApplicationTrustCollection() Initializes a new instance of the ApplicationTrustCollection class.

Properties

Property Description
Count get: int Gets the number of elements contained in the CollectionBase instance.
Item get, set: ApplicationTrust Gets or sets the element at the specified index.

Methods

Method Description
Add(ApplicationTrust applicationTrust) Adds an ApplicationTrust object to the collection.
Clear() Removes all elements from the CollectionBase instance.
Contains(ApplicationTrust applicationTrust) Determines whether the collection contains the specified ApplicationTrust object.
CopyTo(ApplicationTrust[] array, int index) Copies the entire ApplicationTrustCollection to a compatible one-dimensional Array, starting at the specified index of the target array.
IndexOf(ApplicationTrust applicationTrust) Gets the zero-based index of the first occurrence of the specified ApplicationTrust object in the CollectionBase instance.
Remove(ApplicationTrust applicationTrust) Removes the first occurrence of the specified ApplicationTrust object from the CollectionBase instance.

Examples

The following example shows how to retrieve and iterate through the user's application trust list.

using System;
using System.Net.Security.CAS;
using System.Security.Policy;

public class Example
{
    public static void Main()
    {
        // Retrieve the application trust manager
        ApplicationTrustManager atm = SecurityManager.GetApplicationTrustManager();

        // Get the collection of user-defined application trusts
        ApplicationTrustCollection userTrusts = atm.UserApplicationTrusts;

        if (userTrusts.Count == 0)
        {
            Console.WriteLine("No user-defined application trusts found.");
            return;
        }

        Console.WriteLine("User Application Trusts:");
        foreach (ApplicationTrust trust in userTrusts)
        {
            Console.WriteLine($"- Application Identity: {trust.ApplicationIdentity.CodeBase}");
            Console.WriteLine($"  Is Approved: {trust.IsApproved}");
        }
    }
}