switch (index)
{
case 0:
- int typeIndex = (int)getValues.ValueList[1];
- var items = getValues.ValueList[2] as List<object>;
- var createArrayInstanceOp = new CreateArrayInstance(globalDataList, typeIndex, items);
- globalDataList.Operations.Add(createArrayInstanceOp);
+ {
+ int typeIndex = (int)getValues.ValueList[1];
+ var items = getValues.ValueList[2] as List<object>;
+ var createArrayInstanceOp = new CreateArrayInstance(globalDataList, typeIndex, items);
+ globalDataList.Operations.Add(createArrayInstanceOp);
+ }
+ break;
+
+ case 1:
+ {
+ int typeIndex = (int)getValues.ValueList[1];
+ int startIndex = (int)getValues.ValueList[2];
+ int endIndex = (int)getValues.ValueList[3];
+ var createDataTemplateOp = new CreateDataTemplate(globalDataList, typeIndex, (startIndex, endIndex));
+ globalDataList.Operations.Add(createDataTemplateOp);
+ }
+ break;
+
+ case 2:
+ {
+ int instanceIndex = (getValues.ValueList[1] as Instance).Index;
+ var value = getValues.ValueList[2];
+ globalDataList.Operations.Add(new AddToCollectionInstance(globalDataList, instanceIndex, value));
+ }
break;
default:
--- /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;
+
+namespace Tizen.NUI.EXaml
+{
+ internal class GatherLongStringsBlock : Action
+ {
+ public GatherLongStringsBlock(GlobalDataList globalDataList, Action parent)
+ {
+ this.parent = parent;
+ this.globalDataList = globalDataList;
+ }
+
+ private Action parent;
+ private GlobalDataList globalDataList;
+
+ public Action DealChar(char c)
+ {
+ switch (c)
+ {
+ case '>':
+ blockStartCount--;
+ break;
+
+ case '<':
+ blockStartCount++;
+ break;
+ }
+
+ if (0 == blockStartCount)
+ {
+ parent?.OnActive();
+ return parent;
+ }
+ else
+ {
+ globalDataList.LongStrings += c;
+ return this;
+ }
+ }
+
+ private int blockStartCount = 1;
+
+ public void Init()
+ {
+ }
+
+ public void OnActive()
+ {
+ }
+ }
+}
}
internal List<Assembly> GatheredAssemblies = new List<Assembly>();
+
+ internal string LongStrings
+ {
+ get;
+ set;
+ }
}
}
Action currentOp = null;
+ Action[] blockActions = new Action[]
+ {
+ new GatherAssembliesBlock(globalDataList, null),
+ new GatherTypesBlock(globalDataList, null),
+ new GatherPropertiesBlock(globalDataList, null),
+ new GatherEventsBlock(globalDataList, null),
+ new GatherMethodsBlock(globalDataList, null),
+ new GatherBindablePropertiesBlock(globalDataList, null),
+ new GatherLongStringsBlock(globalDataList, null)
+ };
+
foreach (char c in xaml)
{
if (null == currentOp)
switch (c)
{
case '<':
- if (0 == index)
- {
- currentOp = new GatherAssembliesBlock(globalDataList, null);
- currentOp.Init();
- index++;
- }
- else if (1 == index)
- {
- currentOp = new GatherTypesBlock(globalDataList, null);
- currentOp.Init();
- index++;
- }
- else if (2 == index)
- {
- currentOp = new GatherPropertiesBlock(globalDataList, null);
- currentOp.Init();
- index++;
- }
- else if (3 == index)
- {
- currentOp = new GatherEventsBlock(globalDataList, null);
- currentOp.Init();
- index++;
- }
- else if (4 == index)
- {
- currentOp = new GatherMethodsBlock(globalDataList, null);
- currentOp.Init();
- index++;
- }
- else if (5 == index)
- {
- currentOp = new GatherBindablePropertiesBlock(globalDataList, null);
- currentOp.Init();
- index++;
- }
+ currentOp = blockActions[index++];
+ currentOp.Init();
break;
case '{':
return globalDataList;
}
- internal static void Load(object view, string xaml, out object xamlData)
+ internal static void Load(object view, string xaml, out GlobalDataList xamlData)
{
var globalDataList = GatherDataList(xaml);
--- /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;
+using System.Collections.Generic;
+using System.Reflection;
+using System.Text;
+using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Binding;
+using Tizen.NUI.Binding.Internals;
+using Tizen.NUI.Xaml;
+
+namespace Tizen.NUI.EXaml
+{
+ internal class AddToCollectionInstance : Operation
+ {
+ public AddToCollectionInstance(GlobalDataList globalDataList, int instanceIndex, object value)
+ {
+ this.instanceIndex = instanceIndex;
+ this.value = value;
+ this.globalDataList = globalDataList;
+ }
+
+ private GlobalDataList globalDataList;
+
+ public void Do()
+ {
+ var collection = globalDataList.GatheredInstances[instanceIndex] as IList;
+
+ if (null != collection)
+ {
+ if (value is Instance)
+ {
+ int valueIndex = (value as Instance).Index;
+ value = globalDataList.GatheredInstances[valueIndex];
+ }
+
+ if (value is IMarkupExtension markupExtension)
+ {
+ value = markupExtension.ProvideValue(null);
+ }
+
+ collection.Add(value);
+ }
+ }
+
+ private int instanceIndex;
+ private object value;
+ }
+}
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Tizen.NUI.Binding;
+
+namespace Tizen.NUI.EXaml
+{
+ class CreateDataTemplate : Operation
+ {
+ public CreateDataTemplate(GlobalDataList globalDataList, int typeIndex, (int, int) indexRangeOfContent)
+ {
+ this.typeIndex = typeIndex;
+ this.indexRangeOfContent = indexRangeOfContent;
+ this.globalDataList = globalDataList;
+ }
+
+ private GlobalDataList globalDataList;
+ private int typeIndex;
+ private (int, int) indexRangeOfContent;
+
+ public void Do()
+ {
+ var content = globalDataList.LongStrings.Substring(indexRangeOfContent.Item1, indexRangeOfContent.Item2 - indexRangeOfContent.Item1 + 1);
+ var dataTemplate = new DataTemplate(() =>
+ {
+ object ret = EXamlExtensions.CreateObjectFromEXaml(content);
+ return ret;
+ });
+
+ globalDataList.GatheredInstances.Add(dataTemplate);
+
+ if (null == globalDataList.Root)
+ {
+ globalDataList.Root = dataTemplate;
+ }
+ }
+ }
+}
{
globalDataList.GatheredInstances.Add(obj);
+ if (globalDataList.Root == null)
+ {
+ globalDataList.Root = obj;
+ }
+
if (obj is BindableObject bindableObject)
{
bindableObject.IsCreateByXaml = true;
for (int i = 0; i < genericTypeIndexs.Count; i++)
{
- args[i] = globalDataList.GatheredTypes[genericTypeIndexs[i]];
+ int typeIndex = genericTypeIndexs[i];
+
+ if (typeIndex >= 0)
+ {
+ args[i] = globalDataList.GatheredTypes[typeIndex];
+ }
+ else
+ {
+ args[i] = GetBaseType.GetBaseTypeByIndex(typeIndex);
+ }
}
type = type.MakeGenericType(args);
[EditorBrowsable(EditorBrowsableState.Never)]
public static object LoadFromEXamlByRelativePath<T>(this T view, string eXamlPath)
{
- object eXamlData = null;
+ GlobalDataList eXamlData = null;
if (null == eXamlPath)
{
/// Internal used, will never be opened.
[EditorBrowsable(EditorBrowsableState.Never)]
+ public static object CreateObjectFromEXaml(string eXamlStr)
+ {
+ if (null == eXamlStr)
+ {
+ return null;
+ }
+
+ //MainAssembly = view.GetType().Assembly;
+ object temp = null;
+ GlobalDataList eXamlData = null;
+ LoadEXaml.Load(temp, eXamlStr, out eXamlData);
+ return eXamlData.Root;
+ }
+
+ /// Internal used, will never be opened.
+ [EditorBrowsable(EditorBrowsableState.Never)]
public static Assembly MainAssembly
{
get;