Exemplo n.º 1
0
        public override void SetValue(MemberInfo memberInfo, object instance, object value, ILogPrinter inLogger)
        {
            Action <object, object> setter;

            if (memberInfo is PropertyInfo)
            {
                var propertyInfo = memberInfo as PropertyInfo;
                var key          = propertyInfo.GetSetMethod(true).MethodHandle.Value;
                if (!setterCache.TryGetValue(key, out setter))
                {
                    setterCache.Add(key, setter = EmitHelper.CreatePropertySetterHandler(propertyInfo));
                }
            }
            else if (memberInfo is FieldInfo)
            {
                var fieldInfo = memberInfo as FieldInfo;
                if (!setterCache.TryGetValue(fieldInfo.FieldHandle.Value, out setter))
                {
                    setterCache.Add(fieldInfo.FieldHandle.Value, setter = EmitHelper.CreateFieldSetterHandler(fieldInfo));
                }
            }
            else
            {
                throw new NotImplementedException();
            }

            try
            {
                setter(instance, value);
            }
            catch (Exception ex)
            {
                inLogger.LogError($"Exception for {memberInfo.Name}: {ex.Message}");
            }
        }
Exemplo n.º 2
0
 public override void SetValue(MemberInfo member, object instance, object value, ILogPrinter inLogger)
 {
     if (member is PropertyInfo)
     {
         EmitHelper.CreatePropertySetterHandler(member as PropertyInfo)(instance, value);
     }
     else if (member is FieldInfo)
     {
         EmitHelper.CreateFieldSetterHandler(member as FieldInfo)(instance, value);
     }
     else
     {
         throw new NotImplementedException();
     }
 }