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

CopyValue() public method

public CopyValue ( object from ) : object
from object
return object
        public object CopyValue(object from)
        {
            if (IsListType)
            {
                // If list is null, nothing to copy
                var value = GetValue(from);
                if (value == null)
                    return null;

                // create new list instance and copy values one by one
                object list = createListCtor.Invoke(paramlessArgs);
                var addValueToListParams = new object[1];
                foreach (object item in (IEnumerable)value)
                {
                    if (IsPrimitiveType)
                    {
                        addValueToListParams[0] = item;
                    }
                    else
                    {
                        addValueToListParams[0] = ((Field)item).CopyField();
                    }
                    addValueToListMethod.Invoke(list, addValueToListParams);
                }
                return list;
            }
            else if (IsPrimitiveType)
            {
                // Simpy copy value of primitive types by assignement
                return GetValue(from);
            }
            else
            {
                // Let complex properies copy themselves, unless they are null
                if (GetValue(from) == null)
                    return null;
                else
                    return ((Field)GetValue(from)).CopyField();
            }
        }