public void Init()
{
+ getValueListOp = null;
}
public void OnActive()
public void Init()
{
+ getTypeIndexOp = null;
+ getXFactoryMethodIndexOp = null;
+ getParamListOp = null;
+ getStaticInstanceOp = null;
}
public void OnActive()
public void Init()
{
+ childOp = null;
}
public void OnActive()
public void Init()
{
+ getValueList = null;
valueString = "";
}
public void Init()
{
+ getValues = null;
}
public void OnActive()
get;
} = new List<Operation>();
+ internal List<Operation> RemoveEventOperations
+ {
+ get;
+ } = new List<Operation>();
+
internal List<object> GatheredInstances
{
get;
return globalDataList;
}
- internal static void Load(object view, string xaml)
+ internal static void Load(object view, string xaml, out object xamlData)
{
var globalDataList = GatherDataList(xaml);
{
op.Do();
}
+
+ xamlData = globalDataList;
}
internal static void Load(object view, object preloadData)
op.Do();
}
}
+
+ internal static void RemoveEventsInXaml(object eXamlData)
+ {
+ if (eXamlData is GlobalDataList globalDataList)
+ {
+ foreach (var op in globalDataList.RemoveEventOperations)
+ {
+ op.Do();
+ }
+ }
+ }
}
}
try
{
var methodInfo = globalDataList.GatheredMethods[valueIndex];
- eventInfo.AddEventHandler(instance, methodInfo.CreateDelegate(eventInfo.EventHandlerType, element));
+ Delegate eventDelegate = null;
+
+ if (methodInfo.IsStatic)
+ {
+ eventDelegate = methodInfo.CreateDelegate(eventInfo.EventHandlerType);
+ }
+ else
+ {
+ eventDelegate = methodInfo.CreateDelegate(eventInfo.EventHandlerType, element);
+ }
+
+ if (null != eventDelegate)
+ {
+ eventInfo.AddEventHandler(instance, eventDelegate);
+ globalDataList.RemoveEventOperations.Add(new RemoveEvent(eventDelegate, instance, eventInfo));
+ }
+ else
+ {
+ throw new Exception($"Can't create delegate for method {methodInfo.DeclaringType.FullName}.{methodInfo.Name}");
+ }
}
catch (ArgumentException ae)
{
public void Do()
{
+ object obj = null;
+
if (0 == globalDataList.GatheredInstances.Count && null != globalDataList.Root)
{
- globalDataList.GatheredInstances.Add(globalDataList.Root);
+ obj = globalDataList.Root;
}
else
{
{
if (null == xFactoryMethod)
{
- globalDataList.GatheredInstances.Add(Activator.CreateInstance(type));
+ obj = Activator.CreateInstance(type);
}
else
{
- globalDataList.GatheredInstances.Add(xFactoryMethod.Invoke(null, Array.Empty<object>()));
+ obj = xFactoryMethod.Invoke(null, Array.Empty<object>());
}
}
else
if (null == xFactoryMethod)
{
- globalDataList.GatheredInstances.Add(Activator.CreateInstance(type, paramList.ToArray()));
+ obj = Activator.CreateInstance(type, paramList.ToArray());
}
else
{
- globalDataList.GatheredInstances.Add(xFactoryMethod.Invoke(null, paramList.ToArray()));
+ obj = xFactoryMethod.Invoke(null, paramList.ToArray());
}
}
}
- if (1 == globalDataList.GatheredInstances.Count)
+ if (null != obj)
{
- var rootObject = globalDataList.GatheredInstances[0] as BindableObject;
- if (null != rootObject)
+ globalDataList.GatheredInstances.Add(obj);
+
+ if (obj is BindableObject bindableObject)
{
- rootObject.IsCreateByXaml = true;
- NameScope nameScope = new NameScope();
- NameScope.SetNameScope(rootObject, nameScope);
+ bindableObject.IsCreateByXaml = true;
+
+ if (1 == globalDataList.GatheredInstances.Count)
+ {
+ NameScope nameScope = new NameScope();
+ NameScope.SetNameScope(bindableObject, nameScope);
+ }
}
}
+ else
+ {
+ throw new Exception($"Can't create instance typeIndex:{typeIndex}");
+ }
}
private int typeIndex;
public void Do()
{
var type = globalDataList.GatheredTypes[typeIndex];
+ if (null == type)
+ {
+ throw new Exception($"Type of index {typeIndex} is null");
+ }
+
var field = type.GetField(fi => fi.Name == propertyName && fi.IsStatic && fi.IsPublic);
if (null == field)
{
public void Do()
{
+ object obj = null;
+
if (0 == globalDataList.GatheredInstances.Count && null != globalDataList.Root)
{
- globalDataList.GatheredInstances.Add(globalDataList.Root);
+ obj = globalDataList.Root;
}
else
{
if (null != fieldName)
{
- var instance = type.GetField(fieldName, BindingFlags.Static | BindingFlags.Public).GetValue(null);
- globalDataList.GatheredInstances.Add(instance);
+ obj = type.GetField(fieldName, BindingFlags.Static | BindingFlags.Public).GetValue(null);
}
else
{
- var instance = type.GetProperty(propertyName, BindingFlags.Static | BindingFlags.Public).GetValue(null);
- globalDataList.GatheredInstances.Add(instance);
+ obj = type.GetProperty(propertyName, BindingFlags.Static | BindingFlags.Public).GetValue(null);
}
}
- if (1 == globalDataList.GatheredInstances.Count)
+ if (null != obj)
{
- var rootObject = globalDataList.GatheredInstances[0] as BindableObject;
- if (null != rootObject)
+ globalDataList.GatheredInstances.Add(obj);
+
+ if (obj is BindableObject bindableObject)
{
- rootObject.IsCreateByXaml = true;
- NameScope nameScope = new NameScope();
- NameScope.SetNameScope(rootObject, nameScope);
+ bindableObject.IsCreateByXaml = true;
+
+ if (1 == globalDataList.GatheredInstances.Count)
+ {
+ NameScope nameScope = new NameScope();
+ NameScope.SetNameScope(bindableObject, nameScope);
+ }
}
}
+ else
+ {
+ string name = null;
+ if (null != fieldName)
+ {
+ name = fieldName;
+ }
+ else
+ {
+ name = propertyName;
+ }
+
+ throw new Exception($"Can't gather static instance typeIndex:{typeIndex}, name:{name}");
+ }
}
private int typeIndex;
--- /dev/null
+/*
+ * Copyright(c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+using System.Text;
+using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Binding;
+using Tizen.NUI.Binding.Internals;
+
+namespace Tizen.NUI.EXaml
+{
+ internal class RemoveEvent : Operation
+ {
+ public RemoveEvent(Delegate eventDelegate, object instance, EventInfo eventInfo)
+ {
+ this.instance = instance;
+ this.eventInfo = eventInfo;
+ this.eventDelegate = eventDelegate;
+ }
+
+ public void Do()
+ {
+ try
+ {
+ eventInfo.RemoveEventHandler(instance, eventDelegate);
+ }
+ catch (ArgumentException ae)
+ {
+ Tizen.Log.Fatal("EXaml", ae.ToString());
+ }
+ }
+
+ private object instance;
+ private EventInfo eventInfo;
+ private Delegate eventDelegate;
+ }
+}
using System.IO;
using System.Reflection;
using System.Text;
+using Tizen.NUI.BaseComponents;
namespace Tizen.NUI.EXaml
{
return view;
}
+ /// Internal used, will never be opened.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static void RemoveEventsInXaml(object eXamlData)
+ {
+ LoadEXaml.RemoveEventsInXaml(eXamlData);
+ }
+
+ /// Internal used, will never be opened.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static void DisposeXamlElements(object view)
+ {
+ if (view is Container container)
+ {
+ for (int i = (int)container.ChildCount - 1; i >= 0; i--)
+ {
+ var child = container.Children[i];
+
+ if (child.IsCreateByXaml)
+ {
+ child.Unparent();
+ DisposeXamlElements(child);
+ child.Dispose();
+ }
+ }
+ }
+ }
+
/// Internal used, will never be opened.
[EditorBrowsable(EditorBrowsableState.Never)]
public static T LoadFromEXamlPath<T>(this T view, Type callingType)
/// Internal used, will never be opened.
[EditorBrowsable(EditorBrowsableState.Never)]
- public static T LoadFromEXamlByRelativePath<T>(this T view, string eXamlPath)
+ public static object LoadFromEXamlByRelativePath<T>(this T view, string eXamlPath)
{
+ object eXamlData = null;
+
if (null == eXamlPath)
{
- return view;
+ return eXamlData;
}
MainAssembly = view.GetType().Assembly;
reader.Close();
reader.Dispose();
- LoadEXaml.Load(view, xaml);
+ LoadEXaml.Load(view, xaml, out eXamlData);
}
else
{
- throw new Exception($"Can't find examl file {eXamlPath}");
+ throw new Exception($"Can't find examl file {likelyResourcePath}");
}
- return view;
+ return eXamlData;
}
/// Used for TCT and TC coverage, will never be opened.