public static VisitResult Construct <TDstContainer, TSrcContainer>(ref TDstContainer dstContainer, ref TSrcContainer srcContainer, PropertyContainerConstructOptions options = default) { if (!RuntimeTypeInfoCache <TSrcContainer> .IsValueType() && srcContainer == null) { throw new ArgumentNullException(nameof(srcContainer)); } if (!RuntimeTypeInfoCache <TDstContainer> .IsValueType() && dstContainer == null) { if (typeof(UnityEngine.Object).IsAssignableFrom(typeof(TDstContainer))) { throw new ArgumentNullException(nameof(dstContainer)); } if (!TypeConstruction.TryConstruct(srcContainer.GetType(), out dstContainer)) { throw new ArgumentNullException(nameof(dstContainer)); } } var result = VisitResult.GetPooled(); Construct(ref dstContainer, ref srcContainer, result, options); return(result); }
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); }
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 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 static void Transfer <TDestination, TSource>(ref TDestination destination, ref TSource source, ref ChangeTracker changeTracker) { if (!RuntimeTypeInfoCache <TDestination> .IsValueType() && destination == null) { throw new ArgumentNullException(nameof(destination)); } DoTransfer(ref destination, ref source, ref changeTracker); }
public static VisitResult Transfer <TDstContainer, TSrcContainer>(ref TDstContainer dstContainer, ref TSrcContainer srcContainer) { if (!RuntimeTypeInfoCache <TDstContainer> .IsValueType() && dstContainer == null) { throw new ArgumentNullException(nameof(dstContainer)); } var result = VisitResult.GetPooled(); Transfer(ref dstContainer, ref srcContainer, result); return(result); }
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."); } }