ApplicationTrustsCollection Class

Namespace: System.Net.Security

Assembly: System.dll

Represents a collection of ApplicationTrust objects.

Inheritance

System.Object
System.Collections.CollectionBase
System.Net.Security.ApplicationTrustsCollection

Constructors

Name Description
ApplicationTrustsCollection() Initializes a new instance of the ApplicationTrustsCollection class.

Properties

Name Description
Item[Int32] Gets or sets the ApplicationTrust object at the specified index.
Item[Object] Gets or sets the ApplicationTrust object with the specified key.

Methods

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

Remarks

The ApplicationTrustsCollection class is used to store and manage a list of ApplicationTrust objects. Each ApplicationTrust object represents the trust policy for an application. This is useful in scenarios where you need to grant specific permissions or control the execution of applications based on their trust level.

You can add, remove, or check for the existence of ApplicationTrust objects within this collection.

Examples

Example Usage

The following code example demonstrates how to create an ApplicationTrustsCollection, add an ApplicationTrust to it, and then check if it contains the trust.


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

public class Example
{
    public static void Main()
    {
        // Create a new ApplicationTrust object (simplified for example)
        ApplicationTrust myTrust = new ApplicationTrust();
        myTrust.ApplicationIdentity = new ApplicationIdentity("MyApp.exe");
        myTrust.IsApplicationTrusted = true;

        // Create a new ApplicationTrustsCollection
        ApplicationTrustsCollection trustCollection = new ApplicationTrustsCollection();

        // Add the trust to the collection
        trustCollection.Add(myTrust);

        // Check if the collection contains the trust
        if (trustCollection.Contains(myTrust))
        {
            Console.WriteLine("The trust was successfully added and is in the collection.");
        }

        // Access an item by index
        ApplicationTrust retrievedTrust = trustCollection[0];
        Console.WriteLine($"Retrieved trust for application: {retrievedTrust.ApplicationIdentity.CodeBase}");
    }
}
            

Requirements

Namespace
System.Net.Security
Assembly
System.dll