1 // System.Security.Policy.FirstMatchCodeGroup
4 // Jackson Harper (Jackson@LatitudeGeo.com)
6 // (C) 2002 Jackson Harper, All rights reserved.
10 namespace System.Security.Policy {
13 public sealed class FirstMatchCodeGroup : CodeGroup {
15 public FirstMatchCodeGroup (IMembershipCondition membershipCondition, PolicyStatement policy) :
16 base (membershipCondition, policy) {}
18 // for PolicyLevel (to avoid validation duplication)
19 internal FirstMatchCodeGroup (SecurityElement e) : base (e) {}
25 public override string MergeLogic
27 get { return "First Match"; }
34 public override CodeGroup Copy()
36 FirstMatchCodeGroup copy = CopyNoChildren ();
37 foreach (CodeGroup child in Children) {
38 copy.AddChild (child.Copy ()); // deep copy
43 public override PolicyStatement Resolve(Evidence evidence)
45 PolicyStatement policy = null;
46 PolicyStatement child_policy;
49 throw new ArgumentNullException ();
51 if (MembershipCondition.Check (evidence)) {
52 if (null != PolicyStatement) {
53 policy = PolicyStatement;
55 // Loop through all children breaking on the first one that resolves
56 foreach (CodeGroup child in Children) {
57 if (null == (child_policy = child.Resolve (evidence)))
59 policy = child_policy;
68 public override CodeGroup ResolveMatchingCodeGroups(Evidence evidence)
70 CodeGroup group = null;
73 throw new ArgumentNullException ();
75 if (MembershipCondition.Check (evidence)) {
76 group = CopyNoChildren ();
78 // Add the first child that resolves
79 foreach (CodeGroup child in Children) {
80 if ( null == child.Resolve (evidence))
82 group.AddChild (child);
94 private FirstMatchCodeGroup CopyNoChildren()
96 FirstMatchCodeGroup copy = new FirstMatchCodeGroup (MembershipCondition, PolicyStatement);
99 copy.Description = Description;