コード例 #1
0
        private GallioFunc <object[], TOutput> TryGetMemberAsField(FixtureMemberInvokerTargets targets, ITypeInfo ownerInfo)
        {
            if ((targets & FixtureMemberInvokerTargets.Field) != 0)
            {
                IFieldInfo info = ownerInfo.GetField(memberName, bindingFlags);

                if (info != null)
                {
                    return(args =>
                    {
                        object fixtureInstance = GetFixtureInstance(info.IsStatic);
                        FieldInfo field = (type == null) ? GetMemberInfo <FieldInfo>(t => t.GetField(memberName, bindingFlags)) : info.Resolve(true);

                        if (field == null)
                        {
                            throw new TestFailedException(String.Format("Could not find field '{0}''.", memberName));
                        }

                        return (TOutput)field.GetValue(fixtureInstance);
                    });
                }
            }

            return(null);
        }
コード例 #2
0
ファイル: Logger.Log4net.cs プロジェクト: rossmas/aws-sdk-net
        /// <summary>
        /// This should be a one time call to use reflection to find all the types and methods
        /// needed for the logging API.
        /// </summary>
        private static void loadStatics()
        {
            lock (InternalLog4netLogger.LOCK)
            {
                if (loadState != LoadState.Uninitialized)
                    return;

                loadState = LoadState.Loading;
                try
                {
                    loggerType = Type.GetType("Amazon.Runtime.Internal.Util.Logger");

                    // The LogManager and its methods
                    logMangerType = Type.GetType("log4net.Core.LoggerManager, log4net");
                    logMangerTypeInfo = TypeFactory.GetTypeInfo(logMangerType);
                    if (logMangerType == null)
                    {
                        loadState = LoadState.Failed;
                        return;
                    }

                    getLoggerWithTypeMethod = logMangerTypeInfo.GetMethod("GetLogger", new ITypeInfo[] { TypeFactory.GetTypeInfo(typeof(Assembly)), TypeFactory.GetTypeInfo(typeof(Type)) });

                    // The ILog and its methdods
                    logType = Type.GetType("log4net.Core.ILogger, log4net");
                    logTypeInfo = TypeFactory.GetTypeInfo(logType);

                    levelType = Type.GetType("log4net.Core.Level, log4net");
                    levelTypeInfo = TypeFactory.GetTypeInfo(levelType);

                    debugLevelPropertyValue = levelTypeInfo.GetField("Debug").GetValue(null);
                    infoLevelPropertyValue = levelTypeInfo.GetField("Info").GetValue(null);
                    errorLevelPropertyValue = levelTypeInfo.GetField("Error").GetValue(null);

                    systemStringFormatType = Type.GetType("log4net.Util.SystemStringFormat, log4net");

                    logMethod = logTypeInfo.GetMethod("Log", new ITypeInfo[] { TypeFactory.GetTypeInfo(typeof(Type)), levelTypeInfo, TypeFactory.GetTypeInfo(typeof(object)), TypeFactory.GetTypeInfo(typeof(Exception)) });
                    isEnabledForMethod = logTypeInfo.GetMethod("IsEnabledFor", new ITypeInfo[] { levelTypeInfo });

                    if (getLoggerWithTypeMethod == null ||
                        isEnabledForMethod == null ||
                        logType == null ||
                        levelType == null ||
                        logMethod == null)
                    {
                        loadState = LoadState.Failed;
                        return;
                    }

                    // If log4net logging is enabled, we attempt to activate log4net by calling XmlConfigurator.Configure()
                    if ((AWSConfigs.LoggingConfig.LogTo & LoggingOptions.Log4Net) == LoggingOptions.Log4Net)
                    {
                        ITypeInfo xmlConfiguratorType = TypeFactory.GetTypeInfo(Type.GetType("log4net.Config.XmlConfigurator, log4net"));
                        if (xmlConfiguratorType != null)
                        {
                            MethodInfo configureMethod = xmlConfiguratorType.GetMethod("Configure", new ITypeInfo[0]);
                            if (configureMethod != null)
                            {
                                configureMethod.Invoke(null, null);
                            }
                        }
                    }

                    loadState = LoadState.Success;
                }
                catch
                {
                    // Mark as failed so no attempted will be made on the logging methods.
                    loadState = LoadState.Failed;
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// This should be a one time call to use reflection to find all the types and methods
        /// needed for the logging API.
        /// </summary>
        private static void loadStatics()
        {
            lock (InternalLog4netLogger.LOCK)
            {
                if (loadState != LoadState.Uninitialized)
                {
                    return;
                }

                loadState = LoadState.Loading;
                try
                {
                    loggerType = Type.GetType("Amazon.Runtime.Internal.Util.Logger");

                    // The LogManager and its methods
                    logMangerType     = Type.GetType("log4net.Core.LoggerManager, log4net");
                    logMangerTypeInfo = TypeFactory.GetTypeInfo(logMangerType);
                    if (logMangerType == null)
                    {
                        loadState = LoadState.Failed;
                        return;
                    }

                    getLoggerWithTypeMethod = logMangerTypeInfo.GetMethod("GetLogger", new ITypeInfo[] { TypeFactory.GetTypeInfo(typeof(Assembly)), TypeFactory.GetTypeInfo(typeof(Type)) });

                    // The ILog and its methdods
                    logType     = Type.GetType("log4net.Core.ILogger, log4net");
                    logTypeInfo = TypeFactory.GetTypeInfo(logType);

                    levelType     = Type.GetType("log4net.Core.Level, log4net");
                    levelTypeInfo = TypeFactory.GetTypeInfo(levelType);

                    debugLevelPropertyValue = levelTypeInfo.GetField("Debug").GetValue(null);
                    infoLevelPropertyValue  = levelTypeInfo.GetField("Info").GetValue(null);
                    errorLevelPropertyValue = levelTypeInfo.GetField("Error").GetValue(null);

                    systemStringFormatType = Type.GetType("log4net.Util.SystemStringFormat, log4net");

                    logMethod          = logTypeInfo.GetMethod("Log", new ITypeInfo[] { TypeFactory.GetTypeInfo(typeof(Type)), levelTypeInfo, TypeFactory.GetTypeInfo(typeof(object)), TypeFactory.GetTypeInfo(typeof(Exception)) });
                    isEnabledForMethod = logTypeInfo.GetMethod("IsEnabledFor", new ITypeInfo[] { levelTypeInfo });

                    if (getLoggerWithTypeMethod == null ||
                        isEnabledForMethod == null ||
                        logType == null ||
                        levelType == null ||
                        logMethod == null)
                    {
                        loadState = LoadState.Failed;
                        return;
                    }

                    // If log4net logging is enabled, we attempt to activate log4net by calling XmlConfigurator.Configure()
                    if ((AWSConfigs.LoggingConfig.LogTo & LoggingOptions.Log4Net) == LoggingOptions.Log4Net)
                    {
                        ITypeInfo xmlConfiguratorType = TypeFactory.GetTypeInfo(Type.GetType("log4net.Config.XmlConfigurator, log4net"));
                        if (xmlConfiguratorType != null)
                        {
                            MethodInfo configureMethod = xmlConfiguratorType.GetMethod("Configure", new ITypeInfo[0]);
                            if (configureMethod != null)
                            {
                                configureMethod.Invoke(null, null);
                            }
                        }
                    }

                    loadState = LoadState.Success;
                }
                catch
                {
                    // Mark as failed so no attempted will be made on the logging methods.
                    loadState = LoadState.Failed;
                }
            }
        }
コード例 #4
0
 private static void loadStatics()
 {
     lock (LOCK)
     {
         if (loadState == LoadState.Uninitialized)
         {
             loadState = LoadState.Loading;
             try
             {
                 loggerType        = Type.GetType("Amazon.Runtime.Internal.Util.Logger");
                 logMangerType     = Type.GetType("log4net.Core.LoggerManager, log4net");
                 logMangerTypeInfo = TypeFactory.GetTypeInfo(logMangerType);
                 if (logMangerType == null)
                 {
                     loadState = LoadState.Failed;
                 }
                 else
                 {
                     getLoggerWithTypeMethod = logMangerTypeInfo.GetMethod("GetLogger", new ITypeInfo[2]
                     {
                         TypeFactory.GetTypeInfo(typeof(Assembly)),
                         TypeFactory.GetTypeInfo(typeof(Type))
                     });
                     logType                 = Type.GetType("log4net.Core.ILogger, log4net");
                     logTypeInfo             = TypeFactory.GetTypeInfo(logType);
                     levelType               = Type.GetType("log4net.Core.Level, log4net");
                     levelTypeInfo           = TypeFactory.GetTypeInfo(levelType);
                     debugLevelPropertyValue = levelTypeInfo.GetField("Debug").GetValue(null);
                     infoLevelPropertyValue  = levelTypeInfo.GetField("Info").GetValue(null);
                     errorLevelPropertyValue = levelTypeInfo.GetField("Error").GetValue(null);
                     systemStringFormatType  = Type.GetType("log4net.Util.SystemStringFormat, log4net");
                     logMethod               = logTypeInfo.GetMethod("Log", new ITypeInfo[4]
                     {
                         TypeFactory.GetTypeInfo(typeof(Type)),
                         levelTypeInfo,
                         TypeFactory.GetTypeInfo(typeof(object)),
                         TypeFactory.GetTypeInfo(typeof(Exception))
                     });
                     isEnabledForMethod = logTypeInfo.GetMethod("IsEnabledFor", new ITypeInfo[1]
                     {
                         levelTypeInfo
                     });
                     if (getLoggerWithTypeMethod == null || isEnabledForMethod == null || logType == null || levelType == null || logMethod == null)
                     {
                         loadState = LoadState.Failed;
                     }
                     else
                     {
                         if (AWSConfigs.XmlSectionExists("log4net") && (AWSConfigs.LoggingConfig.LogTo & LoggingOptions.Log4Net) == LoggingOptions.Log4Net)
                         {
                             TypeFactory.GetTypeInfo(Type.GetType("log4net.Config.XmlConfigurator, log4net"))?.GetMethod("Configure", new ITypeInfo[0])?.Invoke(null, null);
                         }
                         loadState = LoadState.Success;
                     }
                 }
             }
             catch
             {
                 loadState = LoadState.Failed;
             }
         }
     }
 }
コード例 #5
0
ファイル: UnresolvedType.cs プロジェクト: soelske/mbunit-v3
        public override FieldInfo GetField(string name, BindingFlags bindingAttr)
        {
            IFieldInfo field = adapter.GetField(name, bindingAttr);

            return(field != null?field.Resolve(false) : null);
        }