55a4718eb7a3df2704b920ae5fcf09ec5b8a0c46
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / EXaml / Operation / CreateInstance.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Reflection;
4 using System.Text;
5 using Tizen.NUI.BaseComponents;
6 using Tizen.NUI.Binding;
7 using Tizen.NUI.Binding.Internals;
8
9 namespace Tizen.NUI.EXaml
10 {
11     internal class CreateInstance : Operation
12     {
13         public CreateInstance(int typeIndex, List<object> paramList = null)
14         {
15             this.typeIndex = typeIndex;
16             this.paramList = paramList;
17         }
18
19         public void Do()
20         {
21             if (0 == LoadEXaml.GatheredInstances.Count && null != Root)
22             {
23                 LoadEXaml.GatheredInstances.Add(Root);
24             }
25             else
26             {
27                 var type = GatherType.GatheredTypes[typeIndex];
28
29                 if (null == paramList)
30                 {
31                     LoadEXaml.GatheredInstances.Add(Activator.CreateInstance(type));
32                 }
33                 else
34                 {
35                     for (int i = 0; i < paramList.Count; i++)
36                     {
37                         if (paramList[i] is Instance)
38                         {
39                             paramList[i] = LoadEXaml.GatheredInstances[(paramList[i] as Instance).Index];
40                         }
41                     }
42                     LoadEXaml.GatheredInstances.Add(Activator.CreateInstance(type, paramList.ToArray()));
43                 }
44             }
45
46             if (1 == LoadEXaml.GatheredInstances.Count)
47             {
48                 var rootObject = LoadEXaml.GatheredInstances[0] as BindableObject;
49                 if (null != rootObject)
50                 {
51                     rootObject.IsCreateByXaml = true;
52                     NameScope nameScope = new NameScope();
53                     NameScope.SetNameScope(rootObject, nameScope);
54                 }
55             }
56         }
57
58         private int typeIndex;
59
60         internal static object Root;
61
62         private List<object> paramList;
63     }
64 }