Files
Dec2017-Script-Dump/mscorlib/System/Security/Policy/ApplicationDirectoryMembershipCondition.cs
T
2026-06-04 11:42:34 +02:00

128 lines
5.8 KiB
C#

using System;
using System.Collections;
using System.Globalization;
using System.Reflection;
using System.Runtime.InteropServices;
using Mono.Security;
namespace System.Security.Policy
{
/// <summary>Determines whether an assembly belongs to a code group by testing its application directory. This class cannot be inherited.</summary>
// Token: 0x0200057B RID: 1403
[ComVisible(true)]
[Serializable]
public sealed class ApplicationDirectoryMembershipCondition : IConstantMembershipCondition, IMembershipCondition, ISecurityEncodable, ISecurityPolicyEncodable
{
/// <summary>Determines whether the membership condition is satisfied by the specified evidence.</summary>
/// <returns>true if the specified evidence satisfies the membership condition; otherwise, false.</returns>
/// <param name="evidence">The evidence set against which to make the test. </param>
// Token: 0x06003347 RID: 13127 RVA: 0x000B054C File Offset: 0x000AE74C
public bool Check(Evidence evidence)
{
if (evidence == null)
{
return false;
}
string codeBase = Assembly.GetCallingAssembly().CodeBase;
Uri uri = new Uri(codeBase);
Url url = new Url(codeBase);
bool flag = false;
bool flag2 = false;
IEnumerator hostEnumerator = evidence.GetHostEnumerator();
while (hostEnumerator.MoveNext())
{
object obj = hostEnumerator.Current;
if (!flag && obj is ApplicationDirectory)
{
ApplicationDirectory applicationDirectory = obj as ApplicationDirectory;
string directory = applicationDirectory.Directory;
flag = string.Compare(directory, 0, uri.ToString(), 0, directory.Length, true, CultureInfo.InvariantCulture) == 0;
}
else if (!flag2 && obj is Url)
{
flag2 = url.Equals(obj);
}
if (flag && flag2)
{
return true;
}
}
return false;
}
/// <summary>Creates an equivalent copy of the membership condition.</summary>
/// <returns>A new, identical copy of the current membership condition.</returns>
// Token: 0x06003348 RID: 13128 RVA: 0x000B0618 File Offset: 0x000AE818
public IMembershipCondition Copy()
{
return new ApplicationDirectoryMembershipCondition();
}
/// <summary>Determines whether the specified membership condition is an <see cref="T:System.Security.Policy.ApplicationDirectoryMembershipCondition" />.</summary>
/// <returns>true if the specified membership condition is an <see cref="T:System.Security.Policy.ApplicationDirectoryMembershipCondition" />; otherwise, false.</returns>
/// <param name="o">The object to compare to <see cref="T:System.Security.Policy.ApplicationDirectoryMembershipCondition" />. </param>
// Token: 0x06003349 RID: 13129 RVA: 0x000B0620 File Offset: 0x000AE820
public override bool Equals(object o)
{
return o is ApplicationDirectoryMembershipCondition;
}
/// <summary>Reconstructs a security object with a specified state from an XML encoding.</summary>
/// <param name="e">The XML encoding to use to reconstruct the security object. </param>
/// <exception cref="T:System.ArgumentNullException">The <paramref name="e" /> parameter is null. </exception>
/// <exception cref="T:System.ArgumentException">The <paramref name="e" /> parameter is not a valid application directory membership condition element. </exception>
// Token: 0x0600334A RID: 13130 RVA: 0x000B062C File Offset: 0x000AE82C
public void FromXml(SecurityElement e)
{
this.FromXml(e, null);
}
/// <summary>Reconstructs a security object with a specified state from an XML encoding.</summary>
/// <param name="e">The XML encoding to use to reconstruct the security object. </param>
/// <param name="level">The policy level context, used to resolve named permission set references. </param>
/// <exception cref="T:System.ArgumentNullException">The <paramref name="e" /> parameter is null. </exception>
/// <exception cref="T:System.ArgumentException">The <paramref name="e" /> parameter is not a valid application directory membership condition element. </exception>
// Token: 0x0600334B RID: 13131 RVA: 0x000B0638 File Offset: 0x000AE838
public void FromXml(SecurityElement e, PolicyLevel level)
{
MembershipConditionHelper.CheckSecurityElement(e, "e", this.version, this.version);
}
/// <summary>Gets the hash code for the current membership condition.</summary>
/// <returns>The hash code for the current membership condition.</returns>
// Token: 0x0600334C RID: 13132 RVA: 0x000B0654 File Offset: 0x000AE854
public override int GetHashCode()
{
return typeof(ApplicationDirectoryMembershipCondition).GetHashCode();
}
/// <summary>Creates and returns a string representation of the membership condition.</summary>
/// <returns>A string representation of the state of the membership condition.</returns>
// Token: 0x0600334D RID: 13133 RVA: 0x000B0668 File Offset: 0x000AE868
public override string ToString()
{
return "ApplicationDirectory";
}
/// <summary>Creates an XML encoding of the security object and its current state.</summary>
/// <returns>An XML encoding of the security object, including any state information.</returns>
// Token: 0x0600334E RID: 13134 RVA: 0x000B0670 File Offset: 0x000AE870
public SecurityElement ToXml()
{
return this.ToXml(null);
}
/// <summary>Creates an XML encoding of the security object and its current state with the specified <see cref="T:System.Security.Policy.PolicyLevel" />.</summary>
/// <returns>An XML encoding of the security object, including any state information.</returns>
/// <param name="level">The policy level context for resolving named permission set references. </param>
// Token: 0x0600334F RID: 13135 RVA: 0x000B067C File Offset: 0x000AE87C
public SecurityElement ToXml(PolicyLevel level)
{
return MembershipConditionHelper.Element(typeof(ApplicationDirectoryMembershipCondition), this.version);
}
// Token: 0x04001503 RID: 5379
private readonly int version = 1;
}
}