--- /dev/null
+/*
+ * Copyright(c) 2022 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 Mono.Cecil;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Reflection;
+using System.Text;
+using Tizen.NUI.Binding;
+using Tizen.NUI.EXaml.Build.Tasks;
+
+namespace Tizen.NUI.EXaml
+{
+ //use ^^
+ internal class EXamlAddToDictionary : EXamlOperation
+ {
+ internal override string Write()
+ {
+ if (false == Parent.IsValid ||
+ false == (Key as EXamlCreateObject)?.IsValid ||
+ false == (Value as EXamlCreateObject)?.IsValid)
+ {
+ return "";
+ }
+
+ string ret = String.Format("({0} ({1} {2} {3}))\n",
+ eXamlContext.GetValueString((int)EXamlOperationType.AddToDictionary),
+ eXamlContext.GetValueString(Parent.Index),
+ eXamlContext.GetValueString(Key),
+ eXamlContext.GetValueString(Value));
+ return ret;
+ }
+
+ public EXamlAddToDictionary(EXamlContext context, EXamlCreateObject parent, object key, object value)
+ : base(context)
+ {
+ Parent = parent;
+ Key = key;
+ Value = value;
+
+ eXamlContext.eXamlOperations.Add(this);
+ }
+
+ public EXamlCreateObject Parent
+ {
+ get;
+ }
+
+ public object Key
+ {
+ get;
+ }
+
+ public object Value
+ {
+ get;
+ }
+ }
+}
+
ret = 0;
break;
case "System.UInt16":
- if (hasValue && short.TryParse(valueString, NumberStyles.Number, CultureInfo.InvariantCulture, out short outushort))
+ if (hasValue && ushort.TryParse(valueString, NumberStyles.Number, CultureInfo.InvariantCulture, out ushort outushort))
ret = outushort;
else
ret = 0;
ret = 0;
break;
case "System.UInt64":
- if (hasValue && long.TryParse(valueString, NumberStyles.Number, CultureInfo.InvariantCulture, out long outulong))
+ if (hasValue && ulong.TryParse(valueString, NumberStyles.Number, CultureInfo.InvariantCulture, out ulong outulong))
ret = outulong;
else
ret = 0;
new EXamlAddToResourceDictionary(Context, parentVar, keyName, Context.Values[node]);
isAdded = true;
}
+
+ if (!isAdded && CanAddToDictionary(parentVar, parentVar.GetType(), node, node, Context))
+ {
+ var key = (node.Properties[XmlName.xKey] as ValueNode).Value as string;
+ new EXamlAddToDictionary(Context, parentVar, key, Context.Values[node]);
+ isAdded = true;
+ }
// Collection element, implicit content, or implicit collection element.
if (!isAdded && parentVar.GetType().GetMethods(md => md.Name == "Add" && md.Parameters.Count == 1, Module).Any())
throw new XamlParseException("resources in ResourceDictionary require a x:Key attribute", lineInfo);
}
+ static bool CanAddToDictionary(EXamlCreateObject parent, TypeReference collectionType, IElementNode node, IXmlLineInfo lineInfo, EXamlContext context)
+ {
+ var typeOfDictionary = collectionType.GetRealTypeOfDictionary();
+
+ if (null != typeOfDictionary)
+ {
+ if ("System.String" == typeOfDictionary.GenericArguments[0].FullName)
+ {
+ if (node.Properties.ContainsKey(XmlName.xKey))
+ {
+ var valueType = node.XmlType.GetTypeReference(XmlTypeExtensions.ModeOfGetType.OnlyGetType, parent.GetType().Module, lineInfo);
+
+ if ("System.Object" == typeOfDictionary.GenericArguments[1].FullName
+ ||
+ valueType.InheritsFromOrImplements(typeOfDictionary.GenericArguments[1]))
+ {
+ return true;
+ }
+ }
+ }
+ }
+
+ return false;
+ }
+
static void Add(EXamlCreateObject parent, string propertyName, INode node, IXmlLineInfo iXmlLineInfo, EXamlContext context)
{
//Fang: Need to deal
RegisterXName,
GetLongString,
CreateDPObject,
+ AddToDictionary,
CreateResourceDictionary,
MAX
}
Context.Body.Variables.Add(vardef);
ValueNode vnode = null;
- if (node.CollectionItems.Count == 1 && (vnode = node.CollectionItems.First() as ValueNode) != null &&
+ if (node.CollectionItems.Count == 1 &&
+ (vnode = node.CollectionItems.First() as ValueNode) != null &&
vardef.VariableType.IsValueType)
{
//<Color>Purple</Color>
{
Context.IL.Emit(OpCodes.Newobj, ctor);
}
+
Context.IL.Emit(OpCodes.Stloc, vardef);
}
else if (ctorInfo != null && node.Properties.ContainsKey(XmlName.xArguments) &&