Пример #1
0
        private static void AssignPropertyFrom(CElement view, Dictionary <string, object> objectsMap, PropertyPrototype property)
        {
            var propName = property.Name;
            var propInfo = view.GetType().GetMember(propName, BindingFlags.Public | BindingFlags.Instance).FirstOrDefault();

            if (propInfo == null)
            {
                Log.Error($"Unable to resolve node {propName} for object {view}");
                return;
            }

            if (!propInfo.CanWrite())
            {
                Log.Error($"Unable to assign property {propName} of object {view}");
                return;
            }

            var valueType = property.TypeHint ?? propInfo.MemberType();

            valueType = Nullable.GetUnderlyingType(valueType) ?? valueType;

            var value = PropertyWriter.ReadObject(property.Path, objectsMap);

            propInfo.SetValue(view, value);

            $"Assigned {value} to {propName}".Log();
        }
Пример #2
0
 private void ApplyAssignments(Dictionary <string, object> objectsMap, BindingPrototype[] assignments)
 {
     foreach (var assignment in assignments)
     {
         try
         {
             PropertyWriter.Assign(assignment, objectsMap);
         }
         catch (Exception e)
         {
             LogHelper.LogException("exception during binding", e);
         }
     }
 }