Пример #1
0
        private void SetFieldsToNull(object @object, IReflectClass claxx)
        {
            IReflectField[] fields;
            fields = claxx.GetDeclaredFields();
            for (int i = 0; i < fields.Length; i++)
            {
                IReflectField field = fields[i];
                if (field.IsStatic())
                {
                    continue;
                }
                if (field.IsTransient())
                {
                    continue;
                }
                field.Set(@object, null);
            }
            IReflectClass superclass = claxx.GetSuperclass();

            if (superclass == null)
            {
                return;
            }
            SetFieldsToNull(@object, superclass);
        }
Пример #2
0
        private static object SetField(string attribName, object subObject, object newValue)
        {
            try
            {
                IReflectClass rclass = DataLayerCommon.ReflectClassFor(subObject);
                if (rclass == null)
                {
                    return(null);
                }

                IReflectField rfield = DataLayerCommon.GetDeclaredFieldInHeirarchy(rclass, attribName);
                if (rfield == null)
                {
                    return(null);
                }

                if (rfield is GenericVirtualField || rfield.IsStatic())
                {
                    return(null);
                }



                IType fieldType = Db4oClient.TypeResolver.Resolve(rfield.GetFieldType());
                if (!fieldType.IsEditable)
                {
                    if (!fieldType.IsCollection && !fieldType.IsArray)
                    {
                        subObject = rfield.Get(subObject);
                        Db4oClient.Client.Ext().Activate(subObject, 2);
                        return(subObject);
                    }
                }
                else if (subObject != null)
                {
                    rfield.Set(subObject, fieldType.Cast(newValue));
                    return(subObject);
                }
                return(null);
            }
            catch (Exception oEx)
            {
                LoggingHelper.HandleException(oEx);
                return(null);
            }
        }
Пример #3
0
            public bool Match(object candidate)
            {
                IReflectField field = (IReflectField)candidate;

                if (field.IsStatic())
                {
                    return(false);
                }
                if (field.IsTransient())
                {
                    return(false);
                }
                if (Platform4.IsTransient(field.GetFieldType()))
                {
                    return(false);
                }
                return(true);
            }
Пример #4
0
        /// <exception cref="System.Exception"></exception>
        protected virtual void AssertNullItem(object obj)
        {
            IReflectClass claxx = Reflector().ForObject(obj);

            IReflectField[] fields = claxx.GetDeclaredFields();
            for (int i = 0; i < fields.Length; ++i)
            {
                IReflectField field = fields[i];
                if (field.IsStatic() || field.IsTransient())
                {
                    continue;
                }
                IReflectClass type = field.GetFieldType();
                if (Container().ClassMetadataForReflectClass(type).IsValueType())
                {
                    continue;
                }
                object value = field.Get(obj);
                Assert.IsNull(value);
            }
        }
Пример #5
0
 public static void SaveDictionary(object targetObject, string attribName, object newValue, object key)
 {
     try
     {
         IReflectClass rclass = DataLayerCommon.ReflectClassFor(targetObject);
         if (rclass != null)
         {
             IReflectField rfield = DataLayerCommon.GetDeclaredFieldInHeirarchy(rclass, attribName);
             if (rfield != null)
             {
                 if (!(rfield is GenericVirtualField || rfield.IsStatic()))
                 {
                     object      obj = rfield.Get(targetObject);
                     ICollection col = (ICollection)obj;
                     if (col is Hashtable)
                     {
                         Hashtable hash = (Hashtable)col;
                         hash.Remove(key);
                         hash.Add(key, newValue);
                         rfield.Set(targetObject, hash);
                     }
                     else if (col is IDictionary)
                     {
                         IDictionary dict = (IDictionary)col;
                         dict.Remove(key);
                         dict.Add(key, newValue);
                         rfield.Set(targetObject, dict);
                     }
                 }
             }
         }
     }
     catch (Exception oEx)
     {
         Db4oClient.Client.Rollback();
         LoggingHelper.HandleException(oEx);
     }
 }
Пример #6
0
        public static void SaveValues(long id, string attribName, object newValue, int offset)
        {
            try
            {
                object targetObject = Db4oClient.Client.Ext().GetByID(id);
                Db4oClient.Client.Ext().Activate(targetObject, 2);
                IReflectClass rclass = DataLayerCommon.ReflectClassFor(targetObject);
                IReflectField rfield = DataLayerCommon.GetDeclaredFieldInHeirarchy(rclass, attribName);
                IType         type   = new FieldDetails(rclass.GetName(), attribName).GetFieldType();
                object        obj    = rfield.Get(targetObject);

                if (obj is IDictionary)
                {
                    SaveDictionary(targetObject, attribName, newValue, KeyAtIndex((IDictionary)obj, offset / 2));
                }
                else
                {
                    if (rfield != null && !(rfield is GenericVirtualField || rfield.IsStatic()))
                    {
                        if (type.IsArray || type.IsCollection)
                        {
                            IList list = obj as IList;
                            if (null != list)
                            {
                                list[offset] = newValue;
                                rfield.Set(targetObject, list);
                            }
                        }
                    }
                }
            }
            catch (Exception oEx)
            {
                Db4oClient.Client.Rollback();
                LoggingHelper.HandleException(oEx);
            }
        }
Пример #7
0
            public bool Match(object candidate)
            {
                IReflectField field = (IReflectField)candidate;

                return(!field.IsTransient() && !field.IsStatic());
            }
Пример #8
0
 internal virtual bool StoreField(IReflectField field)
 {
     if (field.IsStatic())
     {
         return false;
     }
     if (IsTransient(field))
     {
         if (!ShouldStoreTransientFields())
         {
             return false;
         }
     }
     return Platform4.CanSetAccessible() || field.IsPublic();
 }