/// <inheritdoc /> public override void VisitValue(object owner, ValueReflection reflection) { if (Loader.OnValue(reflection, out object value)) { reflection.SetMember(owner, value, true); } }
/// <inheritdoc /> public override void VisitValue(object owner, ValueReflection reflection) { if (Saver.OnValue(reflection.GetMember(owner), reflection, out object newValue)) { reflection.SetMember(owner, newValue, true); } }
/// <summary> /// Copy constructor that will rebind to a provided MemberInfo if not null /// </summary> /// <param name="other">Value to copy from</param> /// <param name="mi">If provided, bind getter and setter to it</param> protected ValueReflection(ValueReflection other, MemberInfo mi = null) { // simple copy is enough Name = other.Name; ValueType = other.ValueType; DeclaringType = mi?.DeclaringType ?? other.DeclaringType; // if MemberInfo is provided use it to setup the correct getter and setter, otherwise just copy // this is useful for when the same type is reused with different declaring types Info = mi == null ? other.Info : SetupInfo(mi); }
private void SetupType(MemberInfo mi, Type memberType) { // if ignored, nothing to do if (mi?.GetCustomAttribute <ConfigValueIgnoreAttribute>() != null) { return; } // check if the type is a node and contains ConfigValueAttribute ConfigNodeAttribute node = memberType.GetCustomAttribute <ConfigNodeAttribute>(); ConfigValueAttribute value = mi?.GetCustomAttribute <ConfigValueAttribute>(); // try to get the list value type Type listValueType = ReflectionUtils.ListType(ReflectionUtils.ConfigValueType(memberType) ?? memberType); if (listValueType != null) { // is a list var reflection = ListValueReflection.Create(mi, value, listValueType); ListValues.Add(reflection); FARLogger.TraceFormat("Added list value '{1} -> <{0}, {2}>'", reflection.Name ?? "{null}", reflection.NodeId ?? "{null}", reflection.ValueType); } else if (node == null) { // not a node or a list -> simple value ValueReflection reflection = Create(mi, value); Values.Add(reflection); FARLogger.TraceFormat("Added value '{0} -> {1}'", reflection.Name, reflection.ValueType); } else { // ConfigValue name string name = value?.Name; // get clone or create new reflection for the type NodeReflection nodeReflection = GetReflection(memberType, true, name, mi); Nodes.Add(nodeReflection); FARLogger.TraceFormat("Added node '{1} -> <{0}, {2}>'", name ?? "{null}", nodeReflection.Id, nodeReflection.ValueType); } }
public abstract void VisitValue(object owner, ValueReflection reflection);