System.Security.Policy.FileCodeGroup Class

Assembly: Mscorlib.dll
Namespace: System.Security.Policy
Summary
Grants permission to manipulate files located in the code assemblies to code assemblies that match the membership condition. This class cannot be inherited.
C# Syntax:
[Serializable]
public sealed class FileCodeGroup : CodeGroup
Remarks
Code groups are the building blocks of code access security policy. Each policy level consists of a root code group that can have child code groups. Each child code group can have their own child code groups; this behavior extends to any number of levels, forming a tree. Each code group has a membership condition that determines if a given assembly belongs to it based on the evidence for that assembly. Only code groups whose membership conditions match a given assembly and their child code groups apply policy.

FileCodeGroup has the same child matching semantics as UnionCodeGroup. However, FileCodeGroup returns a permission set containing a dynamically-calculated FileIOPermission that grants file access to the directory from which the code is run; UnionCodeGroup only returns a static permission set. The type of file access granted is passed as a parameter to the constructor.

This code group only matches assemblies run over a file protocol, that is, assemblies that have URLs that point to a file or UNC path.

See also:
System.Security.Policy Namespace See also:
MSDN: codegroups

System.Security.Policy.FileCodeGroup Member List:

Public Constructors
ctor #1 Initializes a new instance of the FileCodeGroup class.
Public Properties
AttributeString Read-only

Overridden:
Gets a string representation of the attributes of the policy statement for the code group.
Children
(inherited from System.Security.Policy.CodeGroup)
Read-write

See base class member description: System.Security.Policy.CodeGroup.Children


Gets or sets an ordered list of the child code groups of a code group.
Description
(inherited from System.Security.Policy.CodeGroup)
Read-write

See base class member description: System.Security.Policy.CodeGroup.Description


Gets or sets the description of the code group.
MembershipCondition
(inherited from System.Security.Policy.CodeGroup)
Read-write

See base class member description: System.Security.Policy.CodeGroup.MembershipCondition


Gets or sets the code group's membership condition.
MergeLogic Read-only

Overridden:
Gets the merge logic.
Name
(inherited from System.Security.Policy.CodeGroup)
Read-write

See base class member description: System.Security.Policy.CodeGroup.Name


Gets or sets the name of the code group.
PermissionSetName Read-only

Overridden:
Gets the name of the named permission set for the code group.
PolicyStatement
(inherited from System.Security.Policy.CodeGroup)
Read-write

See base class member description: System.Security.Policy.CodeGroup.PolicyStatement


Gets or sets the policy statement associated with the code group.
Public Methods
AddChild
(inherited from System.Security.Policy.CodeGroup)
See base class member description: System.Security.Policy.CodeGroup.AddChild


Adds a child code group to the current code group.
Copy Overridden:
Makes a deep copy of the current code group.
Equals Overloaded:
Equals(object o)

Overridden:
Determines whether the specified code group is equivalent to the current code group.
Equals
(inherited from System.Security.Policy.CodeGroup)
Overloaded:
Equals(CodeGroup cg, bool compareChildren)

See base class member description: System.Security.Policy.CodeGroup.Equals


Determines whether the specified code group is equivalent to the current code group, checking the child code groups as well, if specified.
FromXml
(inherited from System.Security.Policy.CodeGroup)
Overloaded:
FromXml(SecurityElement e)

See base class member description: System.Security.Policy.CodeGroup.FromXml


Reconstructs a security object with a given state from an XML encoding.
FromXml
(inherited from System.Security.Policy.CodeGroup)
Overloaded:
FromXml(SecurityElement e, PolicyLevel level)

See base class member description: System.Security.Policy.CodeGroup.FromXml


Reconstructs a security object with a given state and policy level from an XML encoding.
GetHashCode Overridden:
Gets the hash code of the current code group.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
RemoveChild
(inherited from System.Security.Policy.CodeGroup)
See base class member description: System.Security.Policy.CodeGroup.RemoveChild


Removes the specified child code group.
Resolve Overridden:
Resolves policy for the code group and its descendants for a set of evidence.
ResolveMatchingCodeGroups Overridden:
Resolves matching code groups.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
ToXml
(inherited from System.Security.Policy.CodeGroup)
Overloaded:
ToXml()

See base class member description: System.Security.Policy.CodeGroup.ToXml


Creates an XML encoding of the security object and its current state.
ToXml
(inherited from System.Security.Policy.CodeGroup)
Overloaded:
ToXml(PolicyLevel level)

See base class member description: System.Security.Policy.CodeGroup.ToXml


Creates an XML encoding of the security object, its current state, and the policy level within which the code exists.
Protected Methods
CreateXml Overridden:
Creates an XML encoding of the security object, its current state, and the policy level within which the code exists.
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.
ParseXml Overridden:
Reconstructs a security object with a given state and policy level from an XML encoding.

Hierarchy:


System.Security.Policy.FileCodeGroup Member Details

ctor #1
Summary
Initializes a new instance of the FileCodeGroup class.
C# Syntax:
public FileCodeGroup(
   IMembershipCondition membershipCondition,
   FileIOPermissionAccess access
);
Parameters:

membershipCondition

A membership condition that tests evidence to determine whether this code group applies policy.

access

One of the FileIOPermissionAccess values. This value is used to construct the FileIOPermission that is granted.

Exceptions
Exception Type Condition
ArgumentNullException The membershipCondition parameter is null.
ArgumentException The type of the membershipCondition parameter is not valid.

-or-

The type of the access parameter is not valid.

Remarks
This constructor creates a basic code group. Child code groups can be added with the CodeGroup.AddChild method.

FileCodeGroup returns a permission set containing a dynamically-calculated FileIOPermission that grants file access to the directory from which the code is run. The type of access granted is determined by the access parameter.

Return to top


Overridden Property: AttributeString (read-only)
Summary
Gets a string representation of the attributes of the policy statement for the code group.
C# Syntax:
public override string AttributeString {get;}
Remarks
FileCodeGroup does not use FileCodeGroup.AttributeString, so this property is always null.

Return to top


Property: Children (read-write)
Inherited
See base class member description: System.Security.Policy.CodeGroup.Children

Summary
Gets or sets an ordered list of the child code groups of a code group.
C# Syntax:
public IList Children {get; set;}
Exceptions
Exception Type Condition
ArgumentException An attempt is made to set this property to null.
Remarks
The order of child code groups is significant for certain code groups.

Return to top


Property: Description (read-write)
Inherited
See base class member description: System.Security.Policy.CodeGroup.Description

Summary
Gets or sets the description of the code group.
C# Syntax:
public string Description {get; set;}

Return to top


Property: MembershipCondition (read-write)
Inherited
See base class member description: System.Security.Policy.CodeGroup.MembershipCondition

Summary
Gets or sets the code group's membership condition.
C# Syntax:
public IMembershipCondition MembershipCondition {get; set;}
Exceptions
Exception Type Condition
ArgumentException An attempt is made to set this parameter to null.
Remarks
A membership condition tests evidence and returns a Boolean value that tells whether there is a match.

Return to top


Overridden Property: MergeLogic (read-only)
Summary
Gets the merge logic.
C# Syntax:
public override string MergeLogic {get;}

Return to top


Property: Name (read-write)
Inherited
See base class member description: System.Security.Policy.CodeGroup.Name

Summary
Gets or sets the name of the code group.
C# Syntax:
public string Name {get; set;}

Return to top


Overridden Property: PermissionSetName (read-only)
Summary
Gets the name of the named permission set for the code group.
C# Syntax:
public override string PermissionSetName {get;}

Return to top


Property: PolicyStatement (read-write)
Inherited
See base class member description: System.Security.Policy.CodeGroup.PolicyStatement

Summary
Gets or sets the policy statement associated with the code group.
C# Syntax:
public PolicyStatement PolicyStatement {get; set;}
Remarks
The policy statement applies to code in assemblies when evidence matches the membership condition.

This property can also be set by passing a policy statement to the constructor.

Example
The following example sets the PolicyStatement for a code group.
        codeGroup.PolicyStatement = new PolicyStatement(new NamedPermissionSet("MyPermissionSet"));

    

Return to top


Method: AddChild(
   CodeGroup group
)
Inherited
See base class member description: System.Security.Policy.CodeGroup.AddChild

Summary
Adds a child code group to the current code group.
C# Syntax:
public void AddChild(
   CodeGroup group
);
Parameters:

group

The code group to be added as a child. This new child code group is added to the end of the list.

Exceptions
Exception Type Condition
ArgumentNullException The group parameter is null.
ArgumentException The group parameter is not a valid code group.

Return to top


Overridden Method: Copy()
Summary
Makes a deep copy of the current code group.
C# Syntax:
public override CodeGroup Copy();
Return Value:
An equivalent copy of the current code group, including its membership conditions and child code groups.
Remarks
This method makes a deep copy of the code group, so that copies of all objects the code group contains are also made.

Return to top


Overridden Method: CreateXml(
   SecurityElement element,
   PolicyLevel level
)
Summary
Creates an XML encoding of the security object, its current state, and the policy level within which the code exists.
C# Syntax:
protected override void CreateXml(
   SecurityElement element,
   PolicyLevel level
);
Parameters:

element

The XML encoding to use to create the security object.

level

The policy level within which the code group exists.

Remarks
This method is for use by the security system, and is not typically called by application code.

Return to top


Overloaded Method: Equals(
   object o
)
Summary
Determines whether the specified code group is equivalent to the current code group.
C# Syntax:
public override bool Equals(
   object o
);
Parameters:

o

The code group to compare with the current code group.

Return Value:
true if the specified code group is equivalent to the current code group; otherwise, false.

Return to top


Overloaded Method: Equals(
   CodeGroup cg,
   bool compareChildren
)
Inherited
See base class member description: System.Security.Policy.CodeGroup.Equals

Summary
Determines whether the specified code group is equivalent to the current code group, checking the child code groups as well, if specified.
C# Syntax:
public bool Equals(
   CodeGroup cg,
   bool compareChildren
);
Parameters:

cg

The code group to compare with the current code group.

compareChildren

true to compare child code groups, as well; otherwise, false.

Return Value:
true if the specified code group is equivalent to the current code group; otherwise, false.
Remarks
Two code groups are equivalent if they have the same CodeGroup.Name, CodeGroup.Description, and CodeGroup.MembershipCondition.

If the compareChildren parameter is true, this method will only return true if the current code group and all its child code groups are equivalent to the specified code group and all its child code groups.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~FileCodeGroup();

For more information on members inherited from System.Object click on the link above.

Return to top


Overloaded Method: FromXml(
   SecurityElement e
)
Inherited
See base class member description: System.Security.Policy.CodeGroup.FromXml

Summary
Reconstructs a security object with a given state from an XML encoding.
C# Syntax:
public void FromXml(
   SecurityElement e
);
Parameters:

e

The XML encoding to use to reconstruct the security object.

Exceptions
Exception Type Condition
ArgumentNullException The e parameter is null.
Remarks


Notes to inheritors: CodeGroup.FromXml and CodeGroup.ToXml cannot be overridden. If you need to change the way in which your code group implementation handles XML, override the CodeGroup.ParseXml and CodeGroup.CreateXml methods.

Return to top


Overloaded Method: FromXml(
   SecurityElement e,
   PolicyLevel level
)
Inherited
See base class member description: System.Security.Policy.CodeGroup.FromXml

Summary
Reconstructs a security object with a given state and policy level from an XML encoding.
C# Syntax:
public void FromXml(
   SecurityElement e,
   PolicyLevel level
);
Parameters:

e

The XML encoding to use to reconstruct the security object.

level

The policy level within which the code group exists.

Exceptions
Exception Type Condition
ArgumentNullException The e parameter is null.
Remarks
The policy level context is provided for resolution of named permission sets.

Notes to inheritors: CodeGroup.FromXml and CodeGroup.ToXml cannot be overridden. If you need to change the way in which your code group implementation handles XML, override the CodeGroup.ParseXml and CodeGroup.CreateXml methods.

Return to top


Overridden Method: GetHashCode()
Summary
Gets the hash code of the current code group.
C# Syntax:
public override int GetHashCode();
Return Value:
The hash code of the current code group.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Overridden Method: ParseXml(
   SecurityElement e,
   PolicyLevel level
)
Summary
Reconstructs a security object with a given state and policy level from an XML encoding.
C# Syntax:
protected override void ParseXml(
   SecurityElement e,
   PolicyLevel level
);
Parameters:

e

The XML encoding to use to reconstruct the security object.

level

The policy level within which the code group exists.

Remarks
This method is for use by the security system, and is not typically called by application code.

Return to top


Method: RemoveChild(
   CodeGroup group
)
Inherited
See base class member description: System.Security.Policy.CodeGroup.RemoveChild

Summary
Removes the specified child code group.
C# Syntax:
public void RemoveChild(
   CodeGroup group
);
Parameters:

group

The code group to be removed as a child.

Exceptions
Exception Type Condition
ArgumentException The group parameter is not an immediate child code group of the current code group.
Remarks
Only immediate child code groups can be removed with this method.

Return to top


Overridden Method: Resolve(
   Evidence evidence
)
Summary
Resolves policy for the code group and its descendants for a set of evidence.
C# Syntax:
public override PolicyStatement Resolve(
   Evidence evidence
);
Parameters:

evidence

The evidence for the assembly.

Return Value:
A policy statement consisting of the permissions granted by the code group with optional attributes, or null if the code group does not apply (the membership condition does not match the specified evidence).
Exceptions
Exception Type Condition
ArgumentNullException The evidence parameter is null.
PolicyException The current policy is null.

-or-

More than one code group (including the parent code group and all child code groups) is marked PolicyStatementAttribute.Exclusive.

Remarks
Given evidence for an assembly to be loaded, this method evaluates the code group by first checking the membership condition against the specified evidence. If there is a match, this method returns a policy statement for the code group, including evaluation of child code groups.

The .NET Framework security system uses FileCodeGroup.Resolve on the policy levels to determine which permissions to grant to loaded code from the resulting policy statements and the code request on the assembly.

FileCodeGroup uses union semantics and forms a permission set based on the Url specified by evidence.

Return to top


Overridden Method: ResolveMatchingCodeGroups(
   Evidence evidence
)
Summary
Resolves matching code groups.
C# Syntax:
public override CodeGroup ResolveMatchingCodeGroups(
   Evidence evidence
);
Parameters:

evidence

The evidence for the assembly.

Return Value:
A CodeGroup that is the root of the tree of matching code groups.
Exceptions
Exception Type Condition
ArgumentNullException The evidence parameter is null.
Remarks
Given evidence for an assembly to be loaded, this method evaluates the code group by first checking the membership condition against the specified evidence. If there is a match, this method returns a root code group. The code group that is returned contains child code groups, which in turn can have child code groups as necessary to reflect the complete set of code groups that were matched by the evidence provided.

FileCodeGroup uses union semantics and forms a permission set based on the Url specified by evidence.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Overloaded Method: ToXml()
Inherited
See base class member description: System.Security.Policy.CodeGroup.ToXml

Summary
Creates an XML encoding of the security object and its current state.
C# Syntax:
public SecurityElement ToXml();
Return Value:
An XML encoding of the security object, including any state information.
Remarks


Notes to inheritors: CodeGroup.FromXml and CodeGroup.ToXml cannot be overridden. If you need to change the way in which your code group implementation handles XML, override the CodeGroup.ParseXml and CodeGroup.CreateXml methods.

Return to top


Overloaded Method: ToXml(
   PolicyLevel level
)
Inherited
See base class member description: System.Security.Policy.CodeGroup.ToXml

Summary
Creates an XML encoding of the security object, its current state, and the policy level within which the code exists.
C# Syntax:
public SecurityElement ToXml(
   PolicyLevel level
);
Parameters:

level

The policy level within which the code group exists.

Return Value:
An XML encoding of the security object, including any state information.
Remarks
The policy level context is provided for resolution of named permission sets.

Notes to inheritors: CodeGroup.FromXml and CodeGroup.ToXml cannot be overridden. If you need to change the way in which your code group implementation handles XML, override the CodeGroup.ParseXml and CodeGroup.CreateXml methods.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.