public void VisitProperty <TDstElementProperty, TDstElementValue>(
                    TDstElementProperty dstElementProperty,
                    ref TDstContainer dstContainer,
                    ref ChangeTracker changeTracker)
                    where TDstElementProperty : ICollectionElementProperty <TDstContainer, TDstElementValue>
                {
                    if (!dstElementProperty.IsContainer)
                    {
                        return;
                    }

                    if (!RuntimeTypeInfoCache <TSrcElementValue> .IsValueType() && null == SrcElementValue)
                    {
                        dstElementProperty.SetValue(ref dstContainer, default);
                        return;
                    }

                    var dstValue = dstElementProperty.GetValue(ref dstContainer);

                    if (!RuntimeTypeInfoCache <TDstElementValue> .IsValueType() && null == dstValue || SrcElementValue is TDstElementValue && dstValue.GetType() != SrcElementValue.GetType())
                    {
                        if (!TypeConstructionUtility.TryConstructFromData(ref SrcElementValue, Options.TypeIdentifierKey, Result, out dstValue))
                        {
                            return;
                        }
                    }

                    PropertyContainer.Construct(ref dstValue, ref SrcElementValue, Result, Options);

                    dstElementProperty.SetValue(ref dstContainer, dstValue);
                }
Beispiel #2
0
                    public void VisitProperty <TDstElementProperty, TDstElementValue>(
                        TDstElementProperty dstElementProperty,
                        ref TDstContainer dstContainer,
                        ref ChangeTracker changeTracker)
                        where TDstElementProperty : ICollectionElementProperty <TDstContainer, TDstElementValue>
                    {
                        if (dstElementProperty.IsReadOnly)
                        {
                            return;
                        }

                        if (!RuntimeTypeInfoCache <TSrcElementValue> .IsValueType() && null == SrcElementValue)
                        {
                            dstElementProperty.SetValue(ref dstContainer, default);
                        }
                        else if (TypeConversion.TryConvert <TSrcElementValue, TDstElementValue>(SrcElementValue, out var dstElementValue))
                        {
                            dstElementProperty.SetValue(ref dstContainer, dstElementValue);
                        }
                        else if (dstElementProperty.IsContainer)
                        {
                            dstElementValue = dstElementProperty.GetValue(ref dstContainer);

                            if (RuntimeTypeInfoCache <TDstElementValue> .IsValueType() || null != dstElementValue)
                            {
                                Transfer(ref dstElementValue, ref SrcElementValue, Result);
                            }

                            dstElementProperty.SetValue(ref dstContainer, dstElementValue);
                        }
                        else
                        {
                            Result.AddLog($"PropertyContainer.Transfer ContainerType=[{typeof(TDstContainer)}] PropertyName=[{dstElementProperty.GetName()}] could not be transferred.");
                        }
                    }
            public void VisitCollectionProperty <TDstProperty, TDstValue>(
                TDstProperty dstProperty,
                ref TDstContainer dstContainer,
                ref ChangeTracker changeTracker)
                where TDstProperty : ICollectionProperty <TDstContainer, TDstValue>
            {
                if (!RuntimeTypeInfoCache <TSrcValue> .IsValueType() && null == SrcValue)
                {
                    dstProperty.SetValue(ref dstContainer, default);
                    return;
                }

                var dstValue = dstProperty.GetValue(ref dstContainer);

                if (!RuntimeTypeInfoCache <TDstValue> .IsValueType() && null == dstValue)
                {
                    if (typeof(UnityEngine.Object).IsAssignableFrom(typeof(TDstValue)))
                    {
                        return;
                    }

                    if (TypeConstruction.TryConstruct(SrcValue.GetType(), out dstValue))
                    {
                        dstProperty.SetValue(ref dstContainer, dstValue);
                    }
                    else if (TypeConstruction.TryConstruct(out dstValue))
                    {
                        dstProperty.SetValue(ref dstContainer, dstValue);
                    }
                    else if (typeof(TDstValue).IsArray)
                    {
                        dstValue = (TDstValue)Activator.CreateInstance(typeof(TDstValue), SrcProperty.GetCount(ref SrcContainer));
                        dstProperty.SetValue(ref dstContainer, dstValue);
                    }
                }

                var srcCount = SrcProperty.GetCount(ref SrcContainer);
                var dstCount = dstProperty.GetCount(ref dstContainer);

                if (srcCount != dstCount)
                {
                    dstProperty.SetCount(ref dstContainer, srcCount);
                }

                for (var i = 0; i < srcCount; i++)
                {
                    var action = new SrcCollectionElementGetter <TDstProperty, TDstValue>
                    {
                        Options      = Options,
                        Result       = Result,
                        DstProperty  = dstProperty,
                        DstContainer = dstContainer,
                        Index        = i
                    };

                    SrcProperty.GetPropertyAtIndex(ref SrcContainer, i, ref changeTracker, ref action);

                    dstContainer = action.DstContainer;
                }
            }
 public void VisitCollectionProperty <TDstElementProperty, TDstElementValue>(
     TDstElementProperty dstElementProperty,
     ref TDstContainer dstContainer,
     ref ChangeTracker changeTracker)
     where TDstElementProperty : ICollectionProperty <TDstContainer, TDstElementValue>, ICollectionElementProperty <TDstContainer, TDstElementValue>
 {
     Result.AddException(new InvalidOperationException($"PropertyContainer.Construct ContainerType=[{typeof(TDstContainer)}] PropertyName=[{dstElementProperty.GetName()}] expected collection type but was container type."));
 }
Beispiel #5
0
                public void VisitCollectionProperty <TDstProperty, TDstValue>(
                    TDstProperty dstProperty,
                    ref TDstContainer dstContainer,
                    ref ChangeTracker changeTracker)
                    where TDstProperty : ICollectionProperty <TDstContainer, TDstValue>
                {
                    if (dstProperty.IsReadOnly)
                    {
                        return;
                    }

                    var dstValue = dstProperty.GetValue(ref dstContainer);

                    if (!RuntimeTypeInfoCache <TSrcValue> .IsValueType() && null == SrcValue)
                    {
                        dstProperty.SetValue(ref dstContainer, default);
                    }
                    else if (RuntimeTypeInfoCache <TSrcValue> .IsValueType() || null != dstValue)
                    {
                        var srcCount = SrcProperty.GetCount(ref SrcContainer);
                        var dstCount = dstProperty.GetCount(ref dstContainer);

                        if (srcCount != dstCount)
                        {
                            dstProperty.SetCount(ref dstContainer, srcCount);
                        }

                        for (var i = 0; i < srcCount; i++)
                        {
                            var action = new SrcCollectionElementGetter <TDstProperty, TDstValue>
                            {
                                Result       = Result,
                                DstProperty  = dstProperty,
                                DstContainer = dstContainer,
                                Index        = i
                            };

                            SrcProperty.GetPropertyAtIndex(ref SrcContainer, i, ref changeTracker, ref action);

                            dstContainer = action.DstContainer;
                        }
                    }
                    else
                    {
                        Result.AddLog($"PropertyContainer.Transfer ContainerType=[{typeof(TDstContainer)}] PropertyName=[{dstProperty.GetName()}] could not be transferred.");
                    }
                }