2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Collections.Generic;
19 using System.Reflection;
21 using Tizen.NUI.BaseComponents;
22 using Tizen.NUI.Binding;
23 using Tizen.NUI.Binding.Internals;
26 namespace Tizen.NUI.EXaml
28 internal class GetStaticObject : Operation
30 public GetStaticObject(GlobalDataList globalDataList, List<object> operationInfo)
32 typeIndex = (int)operationInfo[0];
33 propertyName = operationInfo[1] as string;
34 fieldName = operationInfo[2] as string;
35 this.globalDataList = globalDataList;
38 private string propertyName;
39 private string fieldName;
41 private GlobalDataList globalDataList;
47 if (0 == globalDataList.GatheredInstances.Count && null != globalDataList.Root)
49 obj = globalDataList.Root;
53 var type = globalDataList.GatheredTypes[typeIndex];
55 if (null != fieldName)
57 obj = type.GetField(fieldName, BindingFlags.Static | BindingFlags.Public)?.GetValue(null);
61 obj = type.GetProperty(propertyName, BindingFlags.Static | BindingFlags.Public)?.GetValue(null);
67 globalDataList.GatheredInstances.Add(obj);
69 if (obj is BindableObject bindableObject)
71 bindableObject.IsCreateByXaml = true;
73 if (1 == globalDataList.GatheredInstances.Count)
75 NameScope nameScope = new NameScope();
76 NameScope.SetNameScope(bindableObject, nameScope);
83 if (null != fieldName)
92 throw new Exception($"Can't gather static instance typeIndex:{typeIndex}, name:{name}");
96 private int typeIndex;