Пример #1
0
        private void AssertFullyQualifiedName(Type clazz)
        {
            var reflectClass = Platform4.ReflectorForType(clazz).ForClass(clazz);

            Assert.AreEqual(ReflectPlatform.FullyQualifiedName(clazz), reflectClass.GetName()
                            );
        }
Пример #2
0
        /// <summary>Returns a ReflectClass instance for the specified class</summary>
        /// <param name="clazz">class</param>
        /// <returns>a ReflectClass instance for the specified class</returns>
        /// <seealso cref="Db4objects.Db4o.Reflect.IReflectClass">Db4objects.Db4o.Reflect.IReflectClass
        ///     </seealso>
        public virtual IReflectClass ForClass(Type clazz)
        {
            if (clazz == null)
            {
                return(null);
            }
            IReflectClass claxx = (IReflectClass)_classByClass.Get(clazz);

            if (claxx != null)
            {
                return(claxx);
            }
            if (!clazz.IsArray && ReflectPlatform.IsNamedClass(clazz))
            {
                claxx = ForName(ReflectPlatform.FullyQualifiedName(clazz));
                if (claxx != null)
                {
                    _classByClass.Put(clazz, claxx);
                    return(claxx);
                }
            }
            claxx = _delegate.ForClass(clazz);
            if (claxx == null)
            {
                return(null);
            }
            claxx = EnsureDelegate(claxx);
            _classByClass.Put(clazz, claxx);
            return(claxx);
        }
Пример #3
0
        public void FallBackIfTypeNotFound()
        {
            var runtimeType = ReflectPlatform.FullyQualifiedName(typeof(string));

            var type = toTest.ForName(runtimeType);

            Assert.AreEqual(runtimeType, type.GetName());
        }
        public virtual void TestRetypedField()
        {
            Type targetClazz = typeof(AccessOldFieldVersionsTestCase.RetypedFieldData);

            RenameClass(typeof(AccessOldFieldVersionsTestCase.OriginalData), ReflectPlatform.
                        FullyQualifiedName(targetClazz));
            AssertField(targetClazz, FieldName, OrigType, OrigValue);
        }
Пример #5
0
        public virtual void TestRemovedField()
        {
            var targetClazz = typeof(RemovedFieldData);

            RenameClass(typeof(OriginalData), ReflectPlatform.FullyQualifiedName
                            (targetClazz));
            AssertField(targetClazz, FieldName, FieldType, FieldValue);
        }
 public override IReflectClass ForClass(Type forType)
 {
     if (null == forType)
     {
         return(null);
     }
     return(ResolveByTypeName(ReflectPlatform.FullyQualifiedName(forType), () => FallbackResolve(forType)));
 }
Пример #7
0
        public virtual bool ProcessAtClient()
        {
            ByteArrayInputStream @is = new ByteArrayInputStream(_payLoad._buffer);
            int dispatcherID         = PrimitiveCodec.ReadInt(@is);
            CallbackObjectInfoCollections callbackInfos = Decode(@is);

            Container().ThreadPool().Start(ReflectPlatform.SimpleName(GetType()) + ": calling commit callbacks thread"
                                           , new _IRunnable_111(this, callbackInfos, dispatcherID));
            return(true);
        }
        private string GetVersion()
        {
#if !CF && !SILVERLIGHT
            CrossDomainRef <object> returnValue = new CrossDomainRef <object>();
            _domain.DoCallBack(new MethodInvoker(returnValue, ReflectPlatform.FullyQualifiedName(typeof(Db4oFactory)), "Version").InvokeStaticMethod);
            return((string)returnValue.Value);
#else
            return(null);
#endif
        }
        public object InvokeInstanceMethod(Type type, string methodName, params object[] args)
        {
#if !CF && !SILVERLIGHT
            CrossDomainRef <object> returnValue = new CrossDomainRef <object>();
            _domain.DoCallBack(new MethodInvoker(returnValue, ReflectPlatform.FullyQualifiedName(type), methodName, args).InvokeInstanceMethod);
            return(returnValue.Value);
#else
            return(null);
#endif
        }
Пример #10
0
        private static void ConfigureReflector(ICommonConfigurationProvider configuration,
                                               IEnumerable <KeyValuePair <ITypeDescription, Type> > types)
        {
            var reflector = DynamicGeneratedTypesReflector.CreateInstance();

            configuration.Common.ReflectWith(reflector);
            foreach (var typeInfo in types.Where(t => t.Key.TypeName.FullName != ReflectPlatform.FullyQualifiedName(t.Value)))
            {
                reflector.AddType(typeInfo.Key.TypeName.FullName, typeInfo.Value);
            }
        }
Пример #11
0
 private object CreateProxy(Level loggingLevel)
 {
     try
     {
         return(ReflectPlatform.NewInstance(_ctorLoggerClass, new object[] { this, loggingLevel }));
     }
     catch (Db4oException e)
     {
         throw new Exception("Error creating proxy", e);
     }
 }
Пример #12
0
            /// <summary>
            ///     Resolves a service interface to its default implementation using the
            ///     db4o namespace convention:
            ///     interface foo.bar.Baz
            ///     default implementation foo.internal.bar.BazImpl
            /// </summary>
            /// <returns>the convention based type name for the requested service</returns>
            private object Resolve(Type service)
            {
                var className = DefaultImplementationFor(service);
                var binding   = ReflectPlatform.CreateInstance(className);

                if (null == binding)
                {
                    throw new ArgumentException("Cant find default implementation for " + service + ": " + className);
                }
                return(binding);
            }
Пример #13
0
        /// <exception cref="System.Exception"></exception>
        public virtual void TestFailureEvent()
        {
            var executed  = ByRef.NewInstance(false);
            var exception = new Exception();

            _subject.UncaughtException += new _IEventListener4_20(exception, executed).OnEvent;
            _subject.Start(ReflectPlatform.SimpleName(GetType()) + " throwing exception thread"
                           , new _IRunnable_27(exception));
            _subject.Join(1000);
            Assert.IsTrue((((bool)executed.value)));
        }
 public void AddType(string name, Type type)
 {
     if (type.IsArray)
     {
         return;
     }
     lock (sync)
     {
         specialTypes[name] = type;
         renames[ReflectPlatform.FullyQualifiedName(type)] = Tuple.Create(name, type);
     }
 }
        public virtual void TestDiagnostic()
        {
            Store(new ClassHasNoFieldsTestCase.Item());
            IList diagnostics = NativeCollections.Filter(_collector.Diagnostics(), new _IPredicate4_34
                                                             ());

            Assert.AreEqual(1, diagnostics.Count);
            ClassHasNoFields diagnostic = (ClassHasNoFields)((IDiagnostic)diagnostics[0]);

            Assert.AreEqual(ReflectPlatform.FullyQualifiedName(typeof(ClassHasNoFieldsTestCase.Item
                                                                      )), diagnostic.Reason());
        }
        private void AssertPilotAndCarMissing(IList classesNotFound)
        {
            IList excluded = Arrays.AsList(new string[] { ReflectPlatform.FullyQualifiedName(
                                                              typeof(MissingClassDiagnosticsTestCase.Pilot)), ReflectPlatform.FullyQualifiedName
                                                              (typeof(MissingClassDiagnosticsTestCase.Car)) });

            Assert.AreEqual(excluded.Count, classesNotFound.Count);
            for (IEnumerator candidateIter = excluded.GetEnumerator(); candidateIter.MoveNext
                     ();)
            {
                string candidate = ((string)candidateIter.Current);
                Assert.IsTrue(classesNotFound.Contains(candidate));
            }
        }
Пример #17
0
        public void Aliasing()
        {
            DB.Store(new ClassWithFields());

            Reopen(c => c.Common.AddAlias(
                       new TypeAlias(
                           ReflectPlatform.FullyQualifiedName(typeof(ClassWithFields)),
                           ReflectPlatform.FullyQualifiedName(typeof(Base))
                           )));

            var result = from b in DB.AsQueryable <Base>()
                         select b;

            Assert.AreEqual(1, result.Count());
        }
Пример #18
0
 public virtual IReflectClass ForName(string className)
 {
     try
     {
         Type type = ReflectPlatform.ForName(className);
         if (type == null)
         {
             return(null);
         }
         return(ForClass(type));
     }
     catch
     {
     }
     return(null);
 }
Пример #19
0
        public virtual void TestDiagnostic()
        {
            IQuery query = NewQuery(typeof(DescendIntoTranslatorTestCase.Item));

            query.Descend("_name").Constrain("foo").StartsWith(true);
            query.Execute();
            IList diagnostics = NativeCollections.Filter(_collector.Diagnostics(), new _IPredicate4_36
                                                             ());

            Assert.AreEqual(1, diagnostics.Count);
            DescendIntoTranslator diagnostic = (DescendIntoTranslator)((IDiagnostic)diagnostics
                                                                       [0]);

            Assert.AreEqual(ReflectPlatform.FullyQualifiedName(typeof(DescendIntoTranslatorTestCase.Item
                                                                      )) + "." + "_name", diagnostic.Reason());
        }
Пример #20
0
        private string LoggingQualifiedBaseName()
        {
            string simpleName = string.Empty;
            Type   parent     = _logInterface;

            while (parent != null)
            {
                if (simpleName.Length > 0)
                {
                    simpleName = "_" + simpleName;
                }
                simpleName = ReflectPlatform.GetJavaInterfaceSimpleName(parent) + simpleName;
                parent     = parent.DeclaringType;
            }
            return(simpleName);
        }
Пример #21
0
        private Db4objects.Db4o.Reflect.Generic.GenericClass GenericClass(IReflectClass clazz
                                                                          )
        {
            Db4objects.Db4o.Reflect.Generic.GenericClass ret;
            string name = clazz.GetName();

            if (name.Equals(ReflectPlatform.FullyQualifiedName(typeof(GenericArray))))
            {
                // special case, comparing name because can't compare class == class directly with ReflectClass
                ret = new GenericArrayClass(this, clazz, name, null);
            }
            else
            {
                ret = new Db4objects.Db4o.Reflect.Generic.GenericClass(this, clazz, name, null);
            }
            return(ret);
        }
        /// <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());
        }
Пример #23
0
        public static ReflectConstructorSpec CreateConstructor(IConstructorAwareReflectClass
                                                               claxx, Type clazz, IReflectorConfiguration config, IReflectConstructor[] constructors
                                                               )
        {
            if (claxx == null)
            {
                return(ReflectConstructorSpec.InvalidConstructor);
            }
            if (claxx.IsAbstract() || claxx.IsInterface())
            {
                return(ReflectConstructorSpec.InvalidConstructor);
            }
            if (!Platform4.CallConstructor())
            {
                var skipConstructor = !config.CallConstructor(claxx);
                if (!claxx.IsCollection())
                {
                    var serializableConstructor = SkipConstructor(claxx, skipConstructor
                                                                  , config.TestConstructors());
                    if (serializableConstructor != null)
                    {
                        return(new ReflectConstructorSpec(serializableConstructor, null));
                    }
                }
            }
            if (!config.TestConstructors())
            {
                return(new ReflectConstructorSpec(new PlatformReflectConstructor(clazz), null));
            }
            if (ReflectPlatform.CreateInstance(clazz) != null)
            {
                return(new ReflectConstructorSpec(new PlatformReflectConstructor(clazz), null));
            }
            var sortedConstructors = SortConstructorsByParamsCount(constructors);

            return(FindConstructor(claxx, sortedConstructors));
        }
Пример #24
0
 internal LoggingWrapper(Type clazz)
 {
     _logInterface = clazz;
     try
     {
         string loggingImplBaseName = LoggingSupportBaseName() + "_LoggingSupport" + ReflectPlatform
                                      .InnerClassSeparator + LoggingQualifiedBaseName();
         string loggerClassName = ReflectPlatform.AdjustClassName(loggingImplBaseName + "Logger"
                                                                  , clazz);
         string nullImplClassName = ReflectPlatform.AdjustClassName(loggingImplBaseName +
                                                                    "Adapter", clazz);
         Type logerClass = ReflectPlatform.ForName(loggerClassName);
         if (logerClass == null)
         {
             throw new ArgumentException("Cannot find logging support for " + ReflectPlatform.
                                         SimpleName(_logInterface));
         }
         _ctorLoggerClass = logerClass.GetConstructor(loggerConstructorParameterTypes);
         nullImpl         = (object)ReflectPlatform.CreateInstance(nullImplClassName);
     }
     catch (SecurityException e)
     {
         throw new Exception("Error accessing logging support for class " + clazz.FullName
                             , e);
     }
     catch (MissingMethodException e)
     {
         throw new Exception("Error accessing logging support for class " + clazz.FullName
                             , e);
     }
     trace = CreateProxy(Logger.Trace);
     debug = CreateProxy(Logger.Debug);
     info  = CreateProxy(Logger.Info);
     warn  = CreateProxy(Logger.Warn);
     error = CreateProxy(Logger.Error);
     fatal = CreateProxy(Logger.Fatal);
 }
Пример #25
0
 public override string ToString()
 {
     return(ReflectPlatform.SimpleName(GetType()) + "(" + _classMetadata.GetName() + ")");
 }
Пример #26
0
 private static string FullyQualifiedName(Type type)
 {
     return(ReflectPlatform.FullyQualifiedName(type));
 }
Пример #27
0
 private static void RegisterPrimitive(Type primitive)
 {
     Primitives.Put(ReflectPlatform.FullyQualifiedName(Platform4.NullableTypeFor(primitive
                                                                                 )), primitive);
 }
 private bool IsKnownClass(Type klass)
 {
     return(IsKnownClass(ReflectPlatform.FullyQualifiedName(klass)));
 }
Пример #29
0
 public virtual object NewInstance(object[] parameters)
 {
     return(ReflectPlatform.CreateInstance(_clazz));
 }
Пример #30
0
 public static string FullyQualifiedName(Type klass)
 {
     return(ReflectPlatform.FullyQualifiedName(klass));
 }