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 CreateInstance : Operation
30 public CreateInstance(GlobalDataList globalDataList, int typeIndex, int xFactoryMethodIndex, List<object> paramList = null)
32 this.typeIndex = typeIndex;
33 this.paramList = paramList;
34 this.globalDataList = globalDataList;
35 this.xFactoryMethodIndex = xFactoryMethodIndex;
38 private GlobalDataList globalDataList;
39 private int xFactoryMethodIndex;
43 if (0 == globalDataList.GatheredInstances.Count && null != Root)
45 globalDataList.GatheredInstances.Add(Root);
49 var type = globalDataList.GatheredTypes[typeIndex];
51 var xFactoryMethod = (0 <= xFactoryMethodIndex) ? globalDataList.GatheredMethods[xFactoryMethodIndex] : null;
53 if (null == paramList)
55 if (null == xFactoryMethod)
57 globalDataList.GatheredInstances.Add(Activator.CreateInstance(type));
61 globalDataList.GatheredInstances.Add(xFactoryMethod.Invoke(null, Array.Empty<object>()));
66 for (int i = 0; i < paramList.Count; i++)
68 if (paramList[i] is Instance instance)
70 paramList[i] = globalDataList.GatheredInstances[instance.Index];
73 if (paramList[i] is ApplicationResourcePathExtension applicationResourcePath)
75 paramList[i] = applicationResourcePath.ProvideValue(null);
79 if (null == xFactoryMethod)
81 globalDataList.GatheredInstances.Add(Activator.CreateInstance(type, paramList.ToArray()));
85 globalDataList.GatheredInstances.Add(xFactoryMethod.Invoke(null, paramList.ToArray()));
90 if (1 == globalDataList.GatheredInstances.Count)
92 var rootObject = globalDataList.GatheredInstances[0] as BindableObject;
93 if (null != rootObject)
95 rootObject.IsCreateByXaml = true;
96 NameScope nameScope = new NameScope();
97 NameScope.SetNameScope(rootObject, nameScope);
102 private int typeIndex;
104 internal static object Root;
106 private List<object> paramList;