コード例 #1
0
ファイル: Environments.cs プロジェクト: pondyond/db4o
            /// <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);
            }
コード例 #2
0
ファイル: ConstructorSupport.cs プロジェクト: pondyond/db4o
        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));
        }
コード例 #3
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);
 }
コード例 #4
0
 public virtual object NewInstance(object[] parameters)
 {
     return(ReflectPlatform.CreateInstance(_clazz));
 }
コード例 #5
0
 private static bool CanCallConstructor(string className)
 {
     return(ReflectPlatform.CreateInstance(className) != null);
 }