예제 #1
0
 public virtual bool IsAssignableFrom(IReflectClass subclassCandidate)
 {
     if (subclassCandidate == null)
     {
         return(false);
     }
     if (Equals(subclassCandidate))
     {
         return(true);
     }
     if (_delegate != null)
     {
         if (subclassCandidate is Db4objects.Db4o.Reflect.Generic.GenericClass)
         {
             subclassCandidate = ((Db4objects.Db4o.Reflect.Generic.GenericClass)subclassCandidate
                                  ).GetDelegate();
         }
         return(_delegate.IsAssignableFrom(subclassCandidate));
     }
     if (!(subclassCandidate is Db4objects.Db4o.Reflect.Generic.GenericClass))
     {
         return(false);
     }
     return(IsAssignableFrom(subclassCandidate.GetSuperclass()));
 }
예제 #2
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);
        }
예제 #3
0
        private ITypeDescription CreateType(TypeName name,
                                            IReflectClass classInfo,
                                            Func <TypeName, Maybe <IReflectClass> > classLookup,
                                            IDictionary <string, ITypeDescription> knownTypes)
        {
            var knownType = typeResolver(name)
                            .Otherwise(() => typeResolver(name.GetGenericTypeDefinition()));

            if (knownType.HasValue)
            {
                var systemType = KnownType.Create(knownType.Value,
                                                  name.GenericArguments.Select(
                                                      t => GetOrCreateTypeByName(t.Value, classLookup, knownTypes)).
                                                  ToList(), IndexLookUp);
                knownTypes[name.FullName] = systemType;
                return(systemType);
            }
            return(SimpleClassDescription.Create(name,
                                                 classInfo.GetSuperclass().AsMaybe().Convert(sc => GetOrCreateType(sc, classLookup,
                                                                                                                   knownTypes)),
                                                 t =>
            {
                knownTypes[name.FullName] = t;
                return ExtractFields(name, classInfo,
                                     typeName =>
                                     GetOrCreateType(typeName, classLookup,
                                                     knownTypes));
            }));
        }
예제 #4
0
        private void CopyFieldValuesAcross(object src, object dest, IReflectClass claxx,
                                           IReplicationProviderInside sourceProvider, IReplicationProviderInside targetProvider
                                           )
        {
            if (dest == null)
            {
                throw new InvalidOperationException("Dest cannot be null: src=" + src + ", class="
                                                    + claxx + ", source=" + sourceProvider.GetName() + ", target=" + targetProvider
                                                    .GetName());
            }
            IEnumerator fields = FieldIterators.PersistentFields(claxx);

            while (fields.MoveNext())
            {
                IReflectField field = (IReflectField)fields.Current;
                object        value = field.Get(src);
                field.Set(dest, FindCounterpart(value, sourceProvider, targetProvider));
            }
            IReflectClass superclass = claxx.GetSuperclass();

            if (superclass == null)
            {
                return;
            }
            CopyFieldValuesAcross(src, dest, superclass, sourceProvider, targetProvider);
        }
		private ClassInfo MapSuperclass(IReflectClass claxx)
		{
			IReflectClass superClass = claxx.GetSuperclass();
			if (superClass != null)
			{
				return GetClassMeta(superClass);
			}
			return null;
		}
예제 #6
0
		private void TraverseSuperclass(object @object, IReflectClass claxx)
		{
			IReflectClass superclass = claxx.GetSuperclass();
			if (superclass == null)
			{
				return;
			}
			TraverseAllFields(@object, superclass);
		}
예제 #7
0
        private void TraverseSuperclass(object @object, IReflectClass claxx)
        {
            IReflectClass superclass = claxx.GetSuperclass();

            if (superclass == null)
            {
                return;
            }
            TraverseAllFields(@object, superclass);
        }
예제 #8
0
        private ClassInfo MapSuperclass(IReflectClass claxx)
        {
            IReflectClass superClass = claxx.GetSuperclass();

            if (superClass != null)
            {
                return(GetClassMeta(superClass));
            }
            return(null);
        }
예제 #9
0
		public static void ForEachField(IReflectClass claxx, IProcedure4 procedure)
		{
			while (claxx != null)
			{
				IReflectField[] declaredFields = claxx.GetDeclaredFields();
				for (int reflectFieldIndex = 0; reflectFieldIndex < declaredFields.Length; ++reflectFieldIndex)
				{
					IReflectField reflectField = declaredFields[reflectFieldIndex];
					procedure.Apply(reflectField);
				}
				claxx = claxx.GetSuperclass();
			}
		}
예제 #10
0
 public static void ForEachField(IReflectClass claxx, IProcedure4 procedure)
 {
     while (claxx != null)
     {
         var declaredFields = claxx.GetDeclaredFields();
         for (var reflectFieldIndex = 0; reflectFieldIndex < declaredFields.Length; ++reflectFieldIndex)
         {
             var reflectField = declaredFields[reflectFieldIndex];
             procedure.Apply(reflectField);
         }
         claxx = claxx.GetSuperclass();
     }
 }
예제 #11
0
 public static IReflectField Field(IReflectClass claxx, string name)
 {
     while (claxx != null)
     {
         try
         {
             return(claxx.GetDeclaredField(name));
         }
         catch (Exception)
         {
         }
         claxx = claxx.GetSuperclass();
     }
     return(null);
 }
예제 #12
0
            private bool HasNoActivatingFields(IReflectClass clazz)
            {
                IReflectClass curClass = clazz;

                while (curClass != null)
                {
                    IReflectField[] fields = curClass.GetDeclaredFields();
                    if (!this.HasNoActivatingFields(fields))
                    {
                        return(false);
                    }
                    curClass = curClass.GetSuperclass();
                }
                return(true);
            }
예제 #13
0
		public static IReflectField Field(IReflectClass claxx, string name)
		{
			while (claxx != null)
			{
				try
				{
					return claxx.GetDeclaredField(name);
				}
				catch (Exception)
				{
				}
				claxx = claxx.GetSuperclass();
			}
			return null;
		}
예제 #14
0
        public virtual IReflectClass GetSuperclass()
        {
            if (_superclass != null)
            {
                return(_superclass);
            }
            if (_delegate == null)
            {
                return(_reflector.ForClass(typeof(object)));
            }
            IReflectClass delegateSuperclass = _delegate.GetSuperclass();

            if (delegateSuperclass != null)
            {
                _superclass = _reflector.EnsureDelegate(delegateSuperclass);
            }
            return(_superclass);
        }
예제 #15
0
        public virtual IList Analyze()
        {
            IList         ancestors       = new ArrayList();
            ClassMetadata storedAncestor  = _storedClass.GetAncestor();
            IReflectClass runtimeAncestor = _runtimeClass.GetSuperclass();

            while (storedAncestor != null)
            {
                if (runtimeAncestor == storedAncestor.ClassReflector())
                {
                    ancestors.Add(new HierarchyAnalyzer.Same(storedAncestor));
                }
                else
                {
                    do
                    {
                        ancestors.Add(new HierarchyAnalyzer.Removed(storedAncestor));
                        storedAncestor = storedAncestor.GetAncestor();
                        if (null == storedAncestor)
                        {
                            if (IsObject(runtimeAncestor))
                            {
                                return(ancestors);
                            }
                            ThrowUnsupportedAdd(runtimeAncestor);
                        }
                        if (runtimeAncestor == storedAncestor.ClassReflector())
                        {
                            ancestors.Add(new HierarchyAnalyzer.Same(storedAncestor));
                            break;
                        }
                    }while (storedAncestor != null);
                }
                storedAncestor  = storedAncestor.GetAncestor();
                runtimeAncestor = runtimeAncestor.GetSuperclass();
            }
            if (runtimeAncestor != null && (!IsObject(runtimeAncestor)))
            {
                ThrowUnsupportedAdd(runtimeAncestor);
            }
            return(ancestors);
        }
예제 #16
0
        private void CopyFieldValuesAcross(object src, object dest, IReflectClass claxx,
                                           IReplicationProviderInside sourceProvider, IReplicationProviderInside targetProvider
                                           )
        {
            IEnumerator fields = FieldIterators.PersistentFields(claxx);

            while (fields.MoveNext())
            {
                IReflectField field = (IReflectField)fields.Current;
                object        value = field.Get(src);
                field.Set(dest, FindCounterpart(value, sourceProvider, targetProvider));
            }
            IReflectClass superclass = claxx.GetSuperclass();

            if (superclass == null)
            {
                return;
            }
            CopyFieldValuesAcross(src, dest, superclass, sourceProvider, targetProvider);
        }
예제 #17
0
        public static IReflectField GetDeclaredFieldInHeirarchy(IReflectClass aClass, string attribute)
        {
            try
            {
                while (aClass != null)
                {
					IReflectField refField = GetDeclaredField(aClass, attribute);
                    if (refField != null)
                        return refField;

                    aClass = aClass.GetSuperclass();
                }
            }
            catch (Exception e)
            {
                LoggingHelper.HandleException(e);
            }
            return null;

        }
예제 #18
0
        public static IReflectField GetDeclaredFieldInHeirarchy(IReflectClass aClass, string attribute)
        {
            try
            {
                while (aClass != null)
                {
                    IReflectField refField = GetDeclaredField(aClass, attribute);
                    if (refField != null)
                    {
                        return(refField);
                    }

                    aClass = aClass.GetSuperclass();
                }
            }
            catch (Exception e)
            {
                LoggingHelper.HandleException(e);
            }
            return(null);
        }
		private TernaryBool CallConstructorSpecialized(IReflectClass clazz)
		{
			Config4Class clazzConfig = _config.ConfigClass(clazz.GetName());
			if (clazzConfig != null)
			{
				TernaryBool res = clazzConfig.CallConstructor();
				if (!res.IsUnspecified())
				{
					return res;
				}
			}
			if (Platform4.IsEnum(_config.Reflector(), clazz))
			{
				return TernaryBool.No;
			}
			IReflectClass ancestor = clazz.GetSuperclass();
			if (ancestor != null)
			{
				return CallConstructorSpecialized(ancestor);
			}
			return TernaryBool.Unspecified;
		}
예제 #20
0
        private TernaryBool CallConstructorSpecialized(IReflectClass clazz)
        {
            Config4Class clazzConfig = _config.ConfigClass(clazz.GetName());

            if (clazzConfig != null)
            {
                TernaryBool res = clazzConfig.CallConstructor();
                if (!res.IsUnspecified())
                {
                    return(res);
                }
            }
            if (Platform4.IsEnum(_config.Reflector(), clazz))
            {
                return(TernaryBool.No);
            }
            IReflectClass ancestor = clazz.GetSuperclass();

            if (ancestor != null)
            {
                return(CallConstructorSpecialized(ancestor));
            }
            return(TernaryBool.Unspecified);
        }
예제 #21
0
        public static List <IReflectField> GetFieldList(IReflectClass aClass)
        {
            try
            {
                if (aClass == null)
                {
                    return(null);
                }

                List <IReflectField> ret    = NonVirtualFieldsFor(aClass);
                IReflectClass        parent = aClass.GetSuperclass();
                if (parent != null && !(parent.GetName().StartsWith("System.")))
                {
                    ret.AddRange(GetFieldList(parent));
                }

                return(ret);
            }
            catch (Exception e)
            {
                LoggingHelper.HandleException(e);
            }
            return(null);
        }
        internal bool CreateClassMetadata(ClassMetadata clazz, IReflectClass reflectClazz
                                          )
        {
            bool result = false;

            _classMetadataCreationDepth++;
            try
            {
                IReflectClass parentReflectClazz = reflectClazz.GetSuperclass();
                ClassMetadata parentClazz        = null;
                if (parentReflectClazz != null && !parentReflectClazz.Equals(Container()._handlers
                                                                             .IclassObject))
                {
                    parentClazz = ProduceClassMetadata(parentReflectClazz);
                }
                result = Container().CreateClassMetadata(clazz, reflectClazz, parentClazz);
            }
            finally
            {
                _classMetadataCreationDepth--;
            }
            InitClassMetadataOnUp();
            return(result);
        }
예제 #23
0
        public static List<IReflectField> GetFieldList(IReflectClass aClass)
        {
            try
            {
                if (aClass == null)
                    return null;

                List<IReflectField> ret = NonVirtualFieldsFor(aClass);
                IReflectClass parent = aClass.GetSuperclass();
                if (parent != null && !(parent.GetName().StartsWith("System.")))
                    ret.AddRange(GetFieldList(parent));

                return ret;
            }
            catch (Exception e)
            {
                LoggingHelper.HandleException(e);
            }
            return null;
        }
예제 #24
0
		public virtual bool IsAssignableFrom(IReflectClass subclassCandidate)
		{
			if (subclassCandidate == null)
			{
				return false;
			}
			if (Equals(subclassCandidate))
			{
				return true;
			}
			if (_delegate != null)
			{
				if (subclassCandidate is Db4objects.Db4o.Reflect.Generic.GenericClass)
				{
					subclassCandidate = ((Db4objects.Db4o.Reflect.Generic.GenericClass)subclassCandidate
						).GetDelegate();
				}
				return _delegate.IsAssignableFrom(subclassCandidate);
			}
			if (!(subclassCandidate is Db4objects.Db4o.Reflect.Generic.GenericClass))
			{
				return false;
			}
			return IsAssignableFrom(subclassCandidate.GetSuperclass());
		}
예제 #25
0
		private void CopyFieldValuesAcross(object src, object dest, IReflectClass claxx, 
			IReplicationProviderInside sourceProvider, IReplicationProviderInside targetProvider
			)
		{
			if (dest == null)
			{
				throw new InvalidOperationException("Dest cannot be null: src=" + src + ", class="
					 + claxx + ", source=" + sourceProvider.GetName() + ", target=" + targetProvider
					.GetName());
			}
			IEnumerator fields = FieldIterators.PersistentFields(claxx);
			while (fields.MoveNext())
			{
				IReflectField field = (IReflectField)fields.Current;
				object value = field.Get(src);
				field.Set(dest, FindCounterpart(value, sourceProvider, targetProvider));
			}
			IReflectClass superclass = claxx.GetSuperclass();
			if (superclass == null)
			{
				return;
			}
			CopyFieldValuesAcross(src, dest, superclass, sourceProvider, targetProvider);
		}
		private void CopyFieldValuesAcross(object src, object dest, IReflectClass claxx, 
			IReplicationProviderInside sourceProvider, IReplicationProviderInside targetProvider
			)
		{
			IEnumerator fields = FieldIterators.PersistentFields(claxx);
			while (fields.MoveNext())
			{
				IReflectField field = (IReflectField)fields.Current;
				object value = field.Get(src);
				field.Set(dest, FindCounterpart(value, sourceProvider, targetProvider));
			}
			IReflectClass superclass = claxx.GetSuperclass();
			if (superclass == null)
			{
				return;
			}
			CopyFieldValuesAcross(src, dest, superclass, sourceProvider, targetProvider);
		}
		internal bool CreateClassMetadata(ClassMetadata clazz, IReflectClass reflectClazz
			)
		{
			bool result = false;
			_classMetadataCreationDepth++;
			try
			{
				IReflectClass parentReflectClazz = reflectClazz.GetSuperclass();
				ClassMetadata parentClazz = null;
				if (parentReflectClazz != null && !parentReflectClazz.Equals(Container()._handlers
					.IclassObject))
				{
					parentClazz = ProduceClassMetadata(parentReflectClazz);
				}
				result = Container().CreateClassMetadata(clazz, reflectClazz, parentClazz);
			}
			finally
			{
				_classMetadataCreationDepth--;
			}
			InitClassMetadataOnUp();
			return result;
		}
예제 #28
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);
		}
예제 #29
0
 private ITypeDescription CreateType(TypeName name,
     IReflectClass classInfo,
     Func<TypeName, Maybe<IReflectClass>> classLookup,
     IDictionary<string, ITypeDescription> knownTypes)
 {
     var knownType = typeResolver(name)
         .Otherwise(() => typeResolver(name.GetGenericTypeDefinition()));
     if (knownType.HasValue)
     {
         var systemType = KnownType.Create(knownType.Value,
                                           name.GenericArguments.Select(
                                               t => GetOrCreateTypeByName(t.Value, classLookup, knownTypes)).
                                               ToList(), IndexLookUp);
         knownTypes[name.FullName] = systemType;
         return systemType;
     }
     return SimpleClassDescription.Create(name,
                                          classInfo.GetSuperclass().AsMaybe().Convert(sc=>GetOrCreateType(sc, classLookup,
                                                                     knownTypes)),
                                          t =>
                                              {
                                                  knownTypes[name.FullName] = t;
                                                  return ExtractFields(name, classInfo,
                                                                       typeName =>
                                                                       GetOrCreateType(typeName, classLookup,
                                                                                       knownTypes));
                                              });
 }