[NUI] Adjust directory (#903)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / XamlBinding / Internals / NameScope.cs
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Xml;
5 using Tizen.NUI.Binding;
6 using Tizen.NUI.Xaml;
7
8 namespace Tizen.NUI.Binding.Internals
9 {
10     /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
11     [EditorBrowsable(EditorBrowsableState.Never)]
12     public class NameScope : INameScope
13     {
14         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
15         [EditorBrowsable(EditorBrowsableState.Never)]
16         public static readonly BindableProperty NameScopeProperty = BindableProperty.CreateAttached("NameScope", typeof(INameScope), typeof(NameScope), default(INameScope));
17
18         readonly Dictionary<string, object> _names = new Dictionary<string, object>();
19
20         object INameScope.FindByName(string name)
21         {
22             if (_names.ContainsKey(name))
23                 return _names[name];
24             return null;
25         }
26
27         void INameScope.RegisterName(string name, object scopedElement)
28         {
29             if (_names.ContainsKey(name))
30                 throw new ArgumentException("An element with the same key already exists in NameScope", "name");
31
32             _names[name] = scopedElement;
33         }
34
35         [Obsolete]
36         void INameScope.RegisterName(string name, object scopedElement, IXmlLineInfo xmlLineInfo)
37         {
38             try
39             {
40                 ((INameScope)this).RegisterName(name, scopedElement);
41             }
42             catch (ArgumentException)
43             {
44                 throw new XamlParseException(string.Format("An element with the name \"{0}\" already exists in this NameScope", name), xmlLineInfo);
45             }
46         }
47
48         void INameScope.UnregisterName(string name)
49         {
50             _names.Remove(name);
51         }
52
53         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
54         [EditorBrowsable(EditorBrowsableState.Never)]
55         public static INameScope GetNameScope(BindableObject bindable)
56         {
57             return (INameScope)bindable.GetValue(NameScopeProperty);
58         }
59
60         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
61         [EditorBrowsable(EditorBrowsableState.Never)]
62         public static void SetNameScope(BindableObject bindable, INameScope value)
63         {
64             bindable.SetValue(NameScopeProperty, value);
65         }
66     }
67 }