예제 #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);
        }
예제 #2
0
 public virtual object NewInstance()
 {
     if (_delegate != null)
     {
         return(_delegate.NewInstance());
     }
     return(new GenericObject(this));
 }
예제 #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);
        }
예제 #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);
                    }
                }
예제 #6
0
파일: Prototypes.cs 프로젝트: erdincay/db4o
			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);
			}