Patcher.Data.Plugins.Content.MemberInfo.SetOrAddValue C# (CSharp) Method

SetOrAddValue() public method

public SetOrAddValue ( object target, object value ) : void
target object
value object
return void
        public void SetOrAddValue(object target, object value)
        {
            if (IsListType)
            {
                EnsureListCreated(target);
                AddValue(target, value);
            }
            else
            {
                SetValue(target, value);
            }
        }

Usage Example

Example #1
0
        internal void ReadField(object target, string fieldName, MemberInfo memberInfo, int depth)
        {
            if (typeof(Compound).IsAssignableFrom(memberInfo.FieldType))
            {
                string firstProperty = memberInfo.FieldNames.First();

                // Create new compound property when
                // - no compound property was started
                // - OR when the property that is being read is the first property of new or current compound property
                if (compoundFields[depth] == null || firstProperty == fieldName)
                {
                    // Inform previous compound property it is complete
                    if (compoundFields[depth] != null)
                    {
                        compoundFields[depth].OnComplete(this, depth + 1);
                    }

                    compoundFields[depth] = (Compound)Context.CreateField(memberInfo.FieldType);
                    compoundFields[depth].OnCreate(this, depth + 1);

                    memberInfo.SetOrAddValue(target, compoundFields[depth]);
                }
                compoundFields[depth].ReadCompoundField(this, fieldName, depth + 1);
            }
            else
            {
                // Inform current compound property it is complete
                // and finish it
                // when non-compund property is being read
                if (compoundFields[depth] != null)
                {
                    compoundFields[depth].OnComplete(this, depth + 1);
                }

                memberInfo.SetOrAddValue(target, ReadPrimitiveFieldValue(memberInfo));
            }
        }