예제 #1
0
        private object FindCounterpart(object value, IReplicationProviderInside sourceProvider
                                       , IReplicationProviderInside targetProvider)
        {
            if (value == null)
            {
                return(null);
            }
            value = sourceProvider.ReplaceIfSpecific(value);
            // TODO: need to clone and findCounterpart of each reference object in the
            // struct
            if (ReplicationPlatform.IsValueType(value))
            {
                return(value);
            }
            IReflectClass claxx = _reflector.ForObject(value);

            if (claxx.IsArray())
            {
                return(ArrayClone(value, claxx, sourceProvider, targetProvider));
            }
            if (Platform4.IsTransient(claxx))
            {
                return(null);
            }
            // TODO: make it a warning
            if (_reflector.IsValueType(claxx))
            {
                return(value);
            }
            if (_collectionHandler.CanHandle(value))
            {
                return(CollectionClone(value, claxx, sourceProvider, targetProvider));
            }
            //if value is a Collection, result should be found by passing in just the value
            IReplicationReference @ref = sourceProvider.ProduceReference(value, null, null);

            if (@ref == null)
            {
                throw new InvalidOperationException("unable to find the ref of " + value + " of class "
                                                    + value.GetType());
            }
            object result = @ref.Counterpart();

            if (result != null)
            {
                return(result);
            }
            IReplicationReference targetRef = targetProvider.ProduceReferenceByUUID(@ref.Uuid
                                                                                        (), value.GetType());

            if (targetRef == null)
            {
                throw new InvalidOperationException("unable to find the counterpart of " + value
                                                    + " of class " + value.GetType());
            }
            return(targetRef.Object());
        }
예제 #2
0
 private bool IsValueType(object o)
 {
     return(ReplicationPlatform.IsValueType(o));
 }