5
// Lluis Sanchez Gual <lluis@novell.com>
7
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
using System.Collections.Generic;
30
namespace MonoDevelop.Projects.Policies
32
internal struct PolicyKey : IEquatable<PolicyKey>
34
public Type PolicyType { get; private set; }
35
public string Scope { get; private set; }
37
public PolicyKey (Type policyType, string scope): this ()
39
this.PolicyType = policyType;
43
public override bool Equals (object obj)
45
return obj is PolicyKey && Equals ((PolicyKey)obj);
48
public bool Equals (PolicyKey other)
50
return other.PolicyType.AssemblyQualifiedName == PolicyType.AssemblyQualifiedName && other.Scope == Scope;
53
public override int GetHashCode ()
55
int code = PolicyType.AssemblyQualifiedName.GetHashCode ();
58
code += Scope.GetHashCode ();
63
public override string ToString ()
66
return string.Format("[Policy: Type={0}, scope={1}]", PolicyType, Scope);
68
return string.Format("[Policy: Type={0}]", PolicyType);
72
internal class PolicyDictionary : Dictionary<PolicyKey, object>
74
public PolicyDictionary ()
78
public object this [Type policyType] {
79
get { return this [new PolicyKey (policyType, null)]; }
80
set { this [new PolicyKey (policyType, null)] = value; }
83
public object this [Type policyType, string scope] {
84
get { return this [new PolicyKey (policyType, scope)]; }
85
set { this [new PolicyKey (policyType, scope)] = value; }
88
public bool TryGetValue (Type policyTypeKey, string scopeKey, out object value)
90
return TryGetValue (new PolicyKey (policyTypeKey, scopeKey), out value);
93
public bool TryGetValue (Type policyTypeKey, out object value)
95
return TryGetValue (new PolicyKey (policyTypeKey, null), out value);
98
public void Add (ScopedPolicy scopedPolicy)
100
Add (new PolicyKey (scopedPolicy.PolicyType, scopedPolicy.Scope), scopedPolicy.Policy);
103
public bool ContainsKey (Type policyType, string scope)
105
return ContainsKey (new PolicyKey (policyType, scope));