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.
19 using System.Collections.Generic;
21 using System.Reflection;
23 using Tizen.NUI.Binding;
24 using Tizen.NUI.EXaml.Build.Tasks;
26 using Tizen.NUI.Xaml.Build.Tasks;
28 namespace Tizen.NUI.EXaml
31 internal class EXamlSetProperty : EXamlOperation
33 internal override string Write()
35 if (false == instance.IsValid)
40 string ret = String.Format("({0} ({1} {2} {3}))\n",
41 eXamlContext.GetValueString((int)EXamlOperationType.SetProperty),
42 eXamlContext.GetValueString(instance.Index),
43 eXamlContext.GetValueString(eXamlContext.definedProperties.GetIndex(property.DeclaringType, property)),
44 eXamlContext.GetValueString(value));
49 public EXamlSetProperty(EXamlContext context, EXamlCreateObject instance, string propertyName, object value)
52 var property = instance.Type.GetProperty(fi=>fi.Name==propertyName, out declareTypeRef);
55 this.instance = instance;
56 this.property = property;
59 if (null != this.instance.Instance)
61 var propertyInfo = this.instance.Instance.GetType().GetProperty(property.Name);
63 if (value is EXamlCreateObject eXamlCreateObject && null != eXamlCreateObject.Instance)
65 if (this.instance.Instance is BindingExtension bindingExtension
67 eXamlCreateObject.Type.FullName == typeof(BindingMode).FullName)
69 bindingExtension.ModeInEXaml = eXamlCreateObject;
71 else if (eXamlCreateObject.Type.ResolveCached().IsEnum)
73 if (eXamlCreateObject.Type.FullName == typeof(BindingMode).FullName)
75 var realValue = Enum.Parse(typeof(BindingMode), eXamlCreateObject.Instance as string);
76 propertyInfo.SetMethod.Invoke(this.instance.Instance, new object[] { realValue });
81 if (instance.GetType().FullName == typeof(Xaml.Build.Tasks.ArrayExtension).FullName
83 "Type" == propertyName)
85 eXamlCreateObject.IsValid = false;
88 propertyInfo.SetMethod.Invoke(this.instance.Instance, new object[] { eXamlCreateObject.Instance });
93 propertyInfo.SetMethod.Invoke(this.instance.Instance, new object[] { value });
97 this.instance.AddProperty(declareTypeRef, property);
99 eXamlContext.eXamlOperations.Add(this);
103 throw new Exception("Property is not element");
107 private EXamlCreateObject instance;
108 private TypeReference declareTypeRef;
109 private PropertyDefinition property;
110 private object value;