System.Security.Policy.CodeGroup Class

Assembly: Mscorlib.dll
Namespace: System.Security.Policy
Summary
Represents the abstract base class from which all implementations of code groups must derive.
C# Syntax:
[Serializable]
public abstract class 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.
See also:
System.Security.Policy Namespace See also:
MSDN: codegroups

System.Security.Policy.CodeGroup Member List:

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

Gets a string representation of the attributes of the policy statement for the code group.
Children Read-write

Gets or sets an ordered list of the child code groups of a code group.
Description Read-write

Gets or sets the description of the code group.
MembershipCondition Read-write

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

When overridden in a derived class, gets the merge logic for the code group.
Name Read-write

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

Gets the name of the named permission set for the code group.
PolicyStatement Read-write

Gets or sets the policy statement associated with the code group.
Public Methods
AddChild Adds a child code group to the current code group.
Copy When overridden in a derived class, 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 Overloaded:
Equals(CodeGroup cg, bool compareChildren)

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

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

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 Removes the specified child code group.
Resolve When overridden in a derived class, resolves policy for the code group and its descendants for a set of evidence.
ResolveMatchingCodeGroups When overridden in a derived class, 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 Overloaded:
ToXml()

Creates an XML encoding of the security object and its current state.
ToXml Overloaded:
ToXml(PolicyLevel level)

Creates an XML encoding of the security object, its current state, and the policy level within which the code exists.
Protected Methods
CreateXml When overridden in a derived class, serializes properties and internal state specific to a derived code group and adds the serialization to the specified SecurityElement.
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 When overridden in a derived class, reconstructs properties and internal state specific to a derived code group from the specified SecurityElement.

Hierarchy:


System.Security.Policy.CodeGroup Member Details

ctor #1
Summary
Initializes a new instance of CodeGroup.
C# Syntax:
public CodeGroup(
   IMembershipCondition membershipCondition,
   PolicyStatement policy
);
Parameters:

membershipCondition

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

policy

The policy statement for the code group in the form of a permission set and attributes to grant code that matches the membership condition.

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 policy parameter is not valid.

Remarks
This constructor creates a basic code group and should be called from the constructors of custom code groups. You can add child code groups using the CodeGroup.AddChild method.

Return to top


Property: AttributeString (read-only)
Summary
Gets a string representation of the attributes of the policy statement for the code group.
C# Syntax:
public virtual string AttributeString {get;}
Remarks
The string representation is not localized.

Return to top


Property: Children (read-write)
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)
Summary
Gets or sets the description of the code group.
C# Syntax:
public string Description {get; set;}

Return to top


Property: MembershipCondition (read-write)
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


Property: MergeLogic (read-only)
Summary
When overridden in a derived class, gets the merge logic for the code group.
C# Syntax:
public abstract string MergeLogic {get;}
Remarks


Notes to inheritors: This property is a string description of the merge logic used by the code group to resolve the permissions granted by its child code groups. It is meant to aid administrators using the code group, but is not used by the policy system.

Return to top


Property: Name (read-write)
Summary
Gets or sets the name of the code group.
C# Syntax:
public string Name {get; set;}

Return to top


Property: PermissionSetName (read-only)
Summary
Gets the name of the named permission set for the code group.
C# Syntax:
public virtual string PermissionSetName {get;}
Remarks
This property can be null if the code group contains an unnamed permission set.

Return to top


Property: PolicyStatement (read-write)
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
)
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


Method: Copy()
Summary
When overridden in a derived class, makes a deep copy of the current code group.
C# Syntax:
public abstract 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


Method: CreateXml(
   SecurityElement element,
   PolicyLevel level
)
Summary
When overridden in a derived class, serializes properties and internal state specific to a derived code group and adds the serialization to the specified SecurityElement.
C# Syntax:
protected virtual void CreateXml(
   SecurityElement element,
   PolicyLevel level
);
Parameters:

element

The XML encoding to which to add the serialization.

level

The policy level within which the code group exists.

Remarks
CodeGroup.ToXml cannot be overridden. If you need to serialize members specific to a particular implementation of CodeGroup, you must override CodeGroup.CreateXml and serialize your members there. When the code group is serialized, CodeGroup.ToXml calls CodeGroup.CreateXml and adds your serialization to the SecurityElement created by CodeGroup.ToXml.

The XML created using this method is deserialized by the CodeGroup.ParseXml method.



Notes to inheritors: If you implement this method, you must implement the CodeGroup.ParseXml method as well.
See also:
CodeGroup.ParseXml

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.
Remarks
Two code groups are equivalent if they have the same CodeGroup.Name, CodeGroup.Description, and CodeGroup.MembershipCondition.

This method tests the top-level code group only, not its child code groups.

Return to top


Overloaded Method: Equals(
   CodeGroup cg,
   bool compareChildren
)
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:
~CodeGroup();

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

Return to top


Overloaded Method: FromXml(
   SecurityElement e
)
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
)
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


Method: ParseXml(
   SecurityElement e,
   PolicyLevel level
)
Summary
When overridden in a derived class, reconstructs properties and internal state specific to a derived code group from the specified SecurityElement.
C# Syntax:
protected virtual 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
CodeGroup.FromXml cannot be overridden. If you need to deserialize members specific to a particular implementation of CodeGroup, you must override CodeGroup.ParseXml and deserialize your members there. When the code group is deserialized, CodeGroup.FromXml calls CodeGroup.ParseXml and reconstructs your members from the SecurityElement.

This method deserializes XML created using CodeGroup.CreateXml.



Notes to inheritors: If you implement this method, you must implement the CodeGroup.CreateXml method as well.
See also:
CodeGroup.CreateXml

Return to top


Method: RemoveChild(
   CodeGroup group
)
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


Method: Resolve(
   Evidence evidence
)
Summary
When overridden in a derived class, resolves policy for the code group and its descendants for a set of evidence.
C# Syntax:
public abstract PolicyStatement Resolve(
   Evidence evidence
);
Parameters:

evidence

The evidence for the assembly.

Return Value:
A policy statement that consists 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).
Remarks
Given evidence for an assembly to be loaded, this method evaluates the code group by 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.

For a UnionCodeGroup, all child code groups whose membership condition match the specified evidence are also resolved, and all resulting policy statements are combined with the policy statement of the parent union code group. Each child code group type determines how all child groups under it are applied, depending on how the CodeGroup.Resolve methods of these child groups work.

The .NET Framework security system uses CodeGroup.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.

Return to top


Method: ResolveMatchingCodeGroups(
   Evidence evidence
)
Summary
When overridden in a derived class, resolves matching code groups.
C# Syntax:
public abstract 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.
Remarks
This method has the same evaluation characteristics as CodeGroup.Resolve. 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.

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()
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
)
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.