a83d1265cff2d0ada8062b2dad1d37a5803909cf
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / XamlBinding / NameScopeExtensions.cs
1 /*
2  * Copyright(c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 using System.Collections.Generic;
19 using System.ComponentModel;
20 using Tizen.NUI.Binding.Internals;
21
22 namespace Tizen.NUI.Binding
23 {
24     /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
25     [EditorBrowsable(EditorBrowsableState.Never)]
26     public static class NameScopeExtensions
27     {
28         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
29         [EditorBrowsable(EditorBrowsableState.Never)]
30         public static T FindByName<T>(this Element element, string name)
31         {
32             return ((INameScope)element).FindByName<T>(name);
33         }
34
35         internal static T FindByName<T>(this INameScope namescope, string name)
36         {
37             return (T)namescope?.FindByName(name);
38         }
39
40         private static Stack<Element> elementStack = new Stack<Element>();
41
42         internal static void PushElement(object element)
43         {
44             elementStack.Push((Element)element);
45         }
46
47         internal static void PopElement()
48         {
49             elementStack.Pop();
50         }
51
52         /// <summary>
53         /// Used to find the object defined in Xaml file.
54         /// </summary>
55         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
56         [EditorBrowsable(EditorBrowsableState.Never)]
57         public static T FindByNameInCurrentNameScope<T>(string name)
58         {
59             return FindByName<T>(elementStack.Peek(), name);
60         }
61     }
62 }