Exemple #1
0
        private object EmptyClone(IReplicationProviderInside sourceProvider, object obj)
        {
            if (obj == null)
            {
                return(null);
            }
            IReflectClass claxx = ReflectClass(obj);

            if (_reflector.IsValueType(claxx))
            {
                throw new Exception("IllegalState");
            }
            //		if (claxx.isArray()) return arrayClone(obj, claxx, sourceProvider); //Copy arrayClone() from GenericReplicationSession if necessary.
            if (claxx.IsArray())
            {
                throw new Exception("IllegalState");
            }
            //Copy arrayClone() from GenericReplicationSession if necessary.
            if (_collectionHandler.CanHandleClass(claxx))
            {
                return(CollectionClone(sourceProvider, obj, claxx));
            }
            object result = claxx.NewInstance();

            if (result == null)
            {
                throw new Exception("Unable to create a new instance of " + obj.GetType());
            }
            //FIXME Use db4o's standard for throwing exceptions.
            return(result);
        }
        public ITypeHandler4 TypeHandlerForClass(IReflectClass clazz)
        {
            if (clazz == null)
            {
                return(null);
            }
            if (clazz.IsArray())
            {
                if (IsNDimensional(clazz))
                {
                    return(_openMultiDimensionalArrayHandler);
                }
                return(_openArrayHandler);
            }
            ITypeHandler4 cachedTypeHandler = (ITypeHandler4)_mapReflectorToTypeHandler.Get(clazz
                                                                                            );

            if (cachedTypeHandler != null)
            {
                return(cachedTypeHandler);
            }
            ITypeHandler4 configuredTypeHandler = ConfiguredTypeHandler(clazz);

            if (Handlers4.IsValueType(configuredTypeHandler))
            {
                return(configuredTypeHandler);
            }
            return(null);
        }
Exemple #3
0
        public virtual int[] Dimensions(object arr)
        {
            int           count = 0;
            IReflectClass claxx = _reflector.ForObject(arr);

            while (claxx.IsArray())
            {
                count++;
                claxx = claxx.GetComponentType();
            }
            int[] dim = new int[count];
            for (int i = 0; i < count; i++)
            {
                try
                {
                    dim[i] = GetLength(arr);
                    arr    = Get(arr, 0);
                }
                catch (Exception)
                {
                    return(dim);
                }
            }
            return(dim);
        }
Exemple #4
0
 public virtual IReflectClass GetComponentType(IReflectClass a_class)
 {
     while (a_class.IsArray())
     {
         a_class = a_class.GetComponentType();
     }
     return(a_class);
 }
 public virtual bool IsArray()
 {
     if (_delegate != null)
     {
         return(_delegate.IsArray());
     }
     return(false);
 }
		public virtual IReflectClass GetComponentType(IReflectClass a_class)
		{
			while (a_class.IsArray())
			{
				a_class = a_class.GetComponentType();
			}
			return a_class;
		}
Exemple #7
0
 protected virtual bool IsValueTypeOrArrayOfValueType(IReflectClass claxx)
 {
     //      TODO Optimization: Compute this lazily in ReflectClass;
     if (_reflector.IsValueType(claxx))
     {
         return(true);
     }
     return(claxx.IsArray() && _reflector.IsValueType(claxx.GetComponentType()));
 }
Exemple #8
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());
        }
Exemple #9
0
 private static TypeName NameOf(IReflectClass typeToFind)
 {
     var name = TypeNameParser.ParseString(typeToFind.GetName());
     if (typeToFind.IsArray() && !name.ArrayOf.HasValue)
     {
         return TypeName.CreateArrayOf(name, 1);
     }
     return name;
 }
Exemple #10
0
        private static TypeName NameOf(IReflectClass typeToFind)
        {
            var name = TypeNameParser.ParseString(typeToFind.GetName());

            if (typeToFind.IsArray() && !name.ArrayOf.HasValue)
            {
                return(TypeName.CreateArrayOf(name, 1));
            }
            return(name);
        }
Exemple #11
0
        public virtual void TestIsNDimensional()
        {
            IReflectClass arrayOfArrayOfString = ReflectClass(typeof(string[][]));

            Assert.IsTrue(arrayOfArrayOfString.IsArray());
            IReflectClass arrayOfString = ReflectClass(typeof(string[]));

            Assert.AreSame(arrayOfString, arrayOfArrayOfString.GetComponentType());
            Assert.IsTrue(ArrayReflector().IsNDimensional(arrayOfArrayOfString));
            Assert.IsFalse(ArrayReflector().IsNDimensional(arrayOfString));
        }
 public ITypeHandler4 OpenArrayHandler(IReflectClass clazz)
 {
     if (clazz.IsArray())
     {
         if (IsNDimensional(clazz))
         {
             return(_openMultiDimensionalArrayHandler);
         }
         return(_openArrayHandler);
     }
     return(null);
 }
 internal ClassMetadata ClassMetadataForClass(IReflectClass clazz)
 {
     if (clazz == null)
     {
         return(null);
     }
     if (clazz.IsArray())
     {
         return(IsNDimensional(clazz) ? _untypedMultiDimensionalMetadata : _untypedArrayMetadata);
     }
     return((ClassMetadata)_mapReflectorToClassMetadata.Get(clazz));
 }
Exemple #14
0
 public static IReflectClass BaseType(IReflectClass clazz)
 {
     if (clazz == null)
     {
         return(null);
     }
     if (clazz.IsArray())
     {
         return(BaseType(clazz.GetComponentType()));
     }
     return(clazz);
 }
        /// <summary>
        /// This is to ensure that reflector.forObject(GenericArray) returns an instance of GenericArrayClass instead of GenericClass
        /// http://tracker.db4o.com/jira/browse/COR-376
        /// </summary>
        public virtual void TestGenericArrayClass()
        {
            IExtObjectContainer oc = Fixture().Db();

            InitGenericObjects();
            IReflectClass elementType = oc.Reflector().ForName(PersonClassname);
            object        array       = Reflector().Array().NewInstance(elementType, 5);
            IReflectClass arrayClass  = oc.Reflector().ForObject(array);

            Assert.IsTrue(arrayClass.IsArray());
            Assert.IsTrue(arrayClass is GenericArrayClass);
            arrayClass = oc.Reflector().ForName(array.GetType().FullName);
            Assert.IsTrue(arrayClass.IsArray());
            Assert.IsTrue(arrayClass is GenericArrayClass);
            arrayClass = oc.Reflector().ForClass(array.GetType());
            Assert.IsTrue(arrayClass.IsArray());
            Assert.IsTrue(arrayClass is GenericArrayClass);
            Assert.AreEqual(arrayClass.GetName(), ReflectPlatform.FullyQualifiedName(array.GetType
                                                                                         ()));
            Assert.AreEqual("(GA) " + elementType.GetName(), array.ToString());
        }
Exemple #16
0
        public virtual bool IsCollection(IReflectClass candidate)
        {
            if (candidate.IsArray())
            {
                return(false);
            }
            NetClass netClass = candidate as NetClass;

            if (null == netClass)
            {
                return(false);
            }
            return(typeof(System.Collections.ICollection).IsAssignableFrom(netClass.GetNetType()));
        }
        internal Db4objects.Db4o.Internal.ArrayType ArrayType(object obj)
        {
            IReflectClass claxx = Reflector().ForObject(obj);

            if (!claxx.IsArray())
            {
                return(Db4objects.Db4o.Internal.ArrayType.None);
            }
            if (IsNDimensional(claxx))
            {
                return(Db4objects.Db4o.Internal.ArrayType.MultidimensionalArray);
            }
            return(Db4objects.Db4o.Internal.ArrayType.PlainArray);
        }
 internal virtual void Configure(IReflectClass clazz, bool isPrimitive)
 {
     _isArray = clazz.IsArray();
     if (_isArray)
     {
         IReflectArray reflectArray = Reflector().Array();
         _isNArray    = reflectArray.IsNDimensional(clazz);
         _isPrimitive = reflectArray.GetComponentType(clazz).IsPrimitive();
     }
     else
     {
         _isPrimitive = isPrimitive | clazz.IsPrimitive();
     }
 }
Exemple #19
0
 private void CollectKnownClass(Collection4 classes, IReflectClass clazz)
 {
     if (IsInternalClass(clazz))
     {
         return;
     }
     if (!HasIdentity(clazz))
     {
         return;
     }
     if (clazz.IsArray())
     {
         return;
     }
     classes.Add(clazz);
 }
 private void CollectKnownClass(Collection4 classes, IReflectClass clazz)
 {
     if (IsInternalClass(clazz))
     {
         return;
     }
     if (!HasIdentity(clazz))
     {
         return;
     }
     if (clazz.IsArray())
     {
         return;
     }
     classes.Add(clazz);
 }
Exemple #21
0
 public static bool IsArray(object expandedObj)
 {
     try
     {
         if (expandedObj != null)
         {
             IReflectClass refClass = ReflectClassFor(expandedObj);
             if (refClass != null)
             {
                 return(refClass.IsArray());
             }
         }
         return(false);
     }
     catch (Exception oEx)
     {
         LoggingHelper.HandleException(oEx);
         return(false);
     }
 }
Exemple #22
0
        protected virtual void QueueUpForTraversing(object @object)
        {
            if (@object == null)
            {
                return;
            }
            IReflectClass claxx = _reflector.ForObject(@object);

            if (IsValueTypeOrArrayOfValueType(claxx) || Platform4.IsTransient(claxx))
            {
                return;
            }
            if (_collectionHandler.CanHandleClass(claxx))
            {
                TraverseCollection(@object);
                return;
            }
            if (claxx.IsArray())
            {
                TraverseArray(claxx, @object);
                return;
            }
            QueueAdd(@object);
        }
Exemple #23
0
		protected virtual bool IsValueTypeOrArrayOfValueType(IReflectClass claxx)
		{
			//      TODO Optimization: Compute this lazily in ReflectClass;
			if (_reflector.IsValueType(claxx))
			{
				return true;
			}
			return claxx.IsArray() && _reflector.IsValueType(claxx.GetComponentType());
		}
Exemple #24
0
		public static IReflectClass BaseType(IReflectClass clazz)
		{
			if (clazz == null)
			{
				return null;
			}
			if (clazz.IsArray())
			{
				return BaseType(clazz.GetComponentType());
			}
			return clazz;
		}
		internal virtual void Configure(IReflectClass clazz, bool isPrimitive)
		{
			_isArray = clazz.IsArray();
			if (_isArray)
			{
				IReflectArray reflectArray = Reflector().Array();
				_isNArray = reflectArray.IsNDimensional(clazz);
				_isPrimitive = reflectArray.GetComponentType(clazz).IsPrimitive();
			}
			else
			{
				_isPrimitive = isPrimitive | clazz.IsPrimitive();
			}
		}
Exemple #26
0
		public virtual bool IsCollection(IReflectClass candidate)
		{
			if (candidate.IsArray())
			{
				return false;
			}
		    NetClass netClass = candidate as NetClass;
            if (null == netClass)
            {
                return false;
            }
		    return typeof(System.Collections.ICollection).IsAssignableFrom(netClass.GetNetType());
		}
Exemple #27
0
		public ITypeHandler4 TypeHandlerForClass(IReflectClass clazz)
		{
			if (clazz == null)
			{
				return null;
			}
			if (clazz.IsArray())
			{
				if (IsNDimensional(clazz))
				{
					return _openMultiDimensionalArrayHandler;
				}
				return _openArrayHandler;
			}
			ITypeHandler4 cachedTypeHandler = (ITypeHandler4)_mapReflectorToTypeHandler.Get(clazz
				);
			if (cachedTypeHandler != null)
			{
				return cachedTypeHandler;
			}
			ITypeHandler4 configuredTypeHandler = ConfiguredTypeHandler(clazz);
			if (Handlers4.IsValueType(configuredTypeHandler))
			{
				return configuredTypeHandler;
			}
			return null;
		}
Exemple #28
0
		public ITypeHandler4 OpenArrayHandler(IReflectClass clazz)
		{
			if (clazz.IsArray())
			{
				if (IsNDimensional(clazz))
				{
					return _openMultiDimensionalArrayHandler;
				}
				return _openArrayHandler;
			}
			return null;
		}
Exemple #29
0
		internal ClassMetadata ClassMetadataForClass(IReflectClass clazz)
		{
			if (clazz == null)
			{
				return null;
			}
			if (clazz.IsArray())
			{
				return IsNDimensional(clazz) ? _untypedMultiDimensionalMetadata : _untypedArrayMetadata;
			}
			return (ClassMetadata)_mapReflectorToClassMetadata.Get(clazz);
		}