Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ShadowContainer.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Collections.Generic;
5 using System.Linq;
6 
7 namespace SiliconStudio.Core.Reflection
8 {
9  internal sealed class ShadowContainer
10  {
11  private static readonly IEnumerable<ShadowAttributes> EmptyAttributes = Enumerable.Empty<ShadowAttributes>();
12  private Dictionary<object, ShadowAttributes> attachedAttributesPerKey;
13 
14  public ShadowContainer()
15  {
16  }
17 
18  public IEnumerable<ShadowAttributes> Members
19  {
20  get
21  {
22  if (attachedAttributesPerKey == null)
23  return EmptyAttributes;
24 
25  return attachedAttributesPerKey.Values;
26  }
27  }
28 
29  public bool Contains(object memberKey)
30  {
31  if (memberKey == null) throw new ArgumentNullException("memberKey");
32  if (attachedAttributesPerKey == null)
33  return false;
34  return attachedAttributesPerKey.ContainsKey(memberKey);
35  }
36 
37  public bool TryGetAttributes(object memberKey, out ShadowAttributes shadowAttributes)
38  {
39  if (memberKey == null) throw new ArgumentNullException("memberKey");
40  shadowAttributes = null;
41  if (attachedAttributesPerKey == null)
42  return false;
43 
44  return attachedAttributesPerKey.TryGetValue(memberKey, out shadowAttributes);
45  }
46 
47  public ShadowAttributes GetAttributes(object memberKey)
48  {
49  if (memberKey == null) throw new ArgumentNullException("memberKey");
50  if (attachedAttributesPerKey == null)
51  attachedAttributesPerKey = new Dictionary<object, ShadowAttributes>();
52 
53  ShadowAttributes shadowAttributes;
54  if (!attachedAttributesPerKey.TryGetValue(memberKey, out shadowAttributes))
55  {
56  shadowAttributes = new ShadowAttributes(this, memberKey);
57  attachedAttributesPerKey.Add(memberKey, shadowAttributes);
58  }
59  return shadowAttributes;
60  }
61 
62  public ShadowAttributes this[object memberKey]
63  {
64  get
65  {
66  return GetAttributes(memberKey);
67  }
68  }
69  }
70 }
One bounding volume completely contains another.