コード例 #1
0
ファイル: NetReflector.cs プロジェクト: danfma/db4o-net
 public virtual IReflectClass ForName(string className)
 {
     try
     {
         Type type = ReflectPlatform.ForName(className);
         if (type == null)
         {
             return(null);
         }
         return(ForClass(type));
     }
     catch
     {
     }
     return(null);
 }
コード例 #2
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);
 }
コード例 #3
0
        private void PrintStats(IObjectContainer con, string filename)
        {
            Tree unavailable   = new TreeString(Remove);
            Tree noConstructor = new TreeString(Remove);

            // one element too many, substract one in the end
            IStoredClass[] internalClasses = con.Ext().StoredClasses();
            for (int i = 0; i < internalClasses.Length; i++)
            {
                string internalClassName = internalClasses[i].GetName();
                Type   clazz             = ReflectPlatform.ForName(internalClassName);
                if (clazz == null)
                {
                    unavailable = unavailable.Add(new TreeString(internalClassName));
                }
                else
                {
                    if (!CanCallConstructor(internalClassName))
                    {
                        noConstructor = noConstructor.Add(new TreeString(internalClassName));
                    }
                }
            }
            unavailable   = unavailable.RemoveLike(new TreeString(Remove));
            noConstructor = noConstructor.RemoveLike(new TreeString(Remove));
            if (unavailable != null)
            {
                PrintHeader("UNAVAILABLE");
                unavailable.Traverse(new _IVisitor4_80());
            }
            if (noConstructor != null)
            {
                PrintHeader("NO PUBLIC CONSTRUCTOR");
                noConstructor.Traverse(new _IVisitor4_88());
            }
            PrintHeader("CLASSES");
            Sharpen.Runtime.Out.WriteLine("Number of objects per class:");
            ByRef ids = ByRef.NewInstance(new TreeInt(0));

            if (internalClasses.Length > 0)
            {
                Tree all = new TreeStringObject(internalClasses[0].GetName(), internalClasses[0]);
                for (int i = 1; i < internalClasses.Length; i++)
                {
                    all = all.Add(new TreeStringObject(internalClasses[i].GetName(), internalClasses[
                                                           i]));
                }
                all.Traverse(new _IVisitor4_107(ids));
            }
            PrintHeader("SUMMARY");
            Sharpen.Runtime.Out.WriteLine("File: " + filename);
            Sharpen.Runtime.Out.WriteLine("Stored classes: " + internalClasses.Length);
            if (unavailable != null)
            {
                Sharpen.Runtime.Out.WriteLine("Unavailable classes: " + unavailable.Size());
            }
            if (noConstructor != null)
            {
                Sharpen.Runtime.Out.WriteLine("Classes without public constructors: " + noConstructor
                                              .Size());
            }
            Sharpen.Runtime.Out.WriteLine("Total number of objects: " + (((Tree)ids.value).Size
                                                                             () - 1));
        }
コード例 #4
0
        public virtual IReflectClass ForName(string className)
        {
            Type clazz = ReflectPlatform.ForName(className);

            return(ForClass(clazz));
        }