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 virtual object NewInstance()
 {
     if (_delegate != null)
     {
         return(_delegate.NewInstance());
     }
     return(new GenericObject(this));
 }
Exemple #3
0
 public Prototype(Prototypes _enclosing, IReflectClass claxx)
 {
     this._enclosing = _enclosing;
     this._object    = (object)claxx.NewInstance();
     if (this._object == null)
     {
         throw new PrototypesException("Prototype could not be created for class " + claxx
                                       .GetName());
     }
     this.Analyze(this._object, claxx, this._enclosing._recursionDepth, null);
 }
        private object NewInstance(Type clazz)
        {
            IReflectClass classReflector = Reflector().ForClass(clazz);
            object        obj            = classReflector.NewInstance();

            if (obj == null)
            {
                throw new ArgumentException("No usable constructor for Class " + clazz);
            }
            return(obj);
        }
Exemple #5
0
                public void Apply(object field)
                {
                    if (((IReflectField)field).IsStatic())
                    {
                        return;
                    }
                    if (this._enclosing._enclosing._ignoreTransient && ((IReflectField)field).IsTransient
                            ())
                    {
                        return;
                    }
                    IReflectClass fieldType = ((IReflectField)field).GetFieldType();
                    List4         path      = new List4(parentPath, ((IReflectField)field));

                    Prototypes.IntegerConverter converter = Prototypes.IntegerConverterforClassName(claxx
                                                                                                    .Reflector(), fieldType.GetName());
                    if (converter != null)
                    {
                        int    id = ++this._enclosing.intIdGenerator;
                        object integerRepresentation = converter.FromInteger(id);
                        if (!Prototypes.TrySetField(((IReflectField)field), @object, integerRepresentation
                                                    ))
                        {
                            return;
                        }
                        this._enclosing._fieldsByIntId.Put(id, new Pair(integerRepresentation, path));
                        return;
                    }
                    if (!fieldType.IsPrimitive())
                    {
                        object identityInstance = fieldType.NewInstance();
                        if (identityInstance == null)
                        {
                            return;
                        }
                        if (!Prototypes.TrySetField(((IReflectField)field), @object, identityInstance))
                        {
                            return;
                        }
                        this._enclosing._fieldsByIdentity.Put(identityInstance, path);
                        this._enclosing.Analyze(identityInstance, claxx, depth - 1, path);
                    }
                }
Exemple #6
0
			public Prototype(Prototypes _enclosing, IReflectClass claxx)
			{
				this._enclosing = _enclosing;
				this._object = (object)claxx.NewInstance();
				if (this._object == null)
				{
					throw new PrototypesException("Prototype could not be created for class " + claxx
						.GetName());
				}
				this.Analyze(this._object, claxx, this._enclosing._recursionDepth, null);
			}