private IEnumerable <Type> GetTypesFromBaseType(_Assembly assembly, Type baseType)
        {
            ReadOnlyCollection <Type> allTypesInAssembly;

            try
            {
                allTypesInAssembly = AssemblyTypeCache.GetTypes(assembly);
            }
            catch (ReflectionTypeLoadException ex)
            {
                string message = string.Format(
                    "The types from assembly '{0}' could not be loaded.{1}{2}",
                    assembly.GetName(),
                    Environment.NewLine,
                    string.Join(Environment.NewLine, ex.LoaderExceptions.Select(e => e.Message)));
                throw new TypeLoadException(message, ex);
            }

            if (baseType == null)
            {
                return(allTypesInAssembly);
            }

            return(GetFilteredTypes(allTypesInAssembly, baseType));
        }
コード例 #2
0
 /// <summary>
 /// Gets all testable methods that are not inside a testable class
 /// </summary>
 public static IEnumerable <MethodInfo> GetUnattachedTestMethods(this _Assembly assembly)
 {
     return(assembly
            .GetTypes()
            .Where(type => !type.IsTestable())
            .SelectMany(type => type.GetTestMethods()));
 }
コード例 #3
0
        public IBugDatabaseProvider Load(string path, IEnumerable <string> args, IWebRequest webRequest)
        {
            _Assembly dll = bugDatabaseFactory.LoadFile(path);

            IEnumerable <Type> validTypes = dll.GetExportedTypes().Where((type) => typeof(IBugDatabaseProvider).IsAssignableFrom(type));

            if (!validTypes.Any())
            {
                throw new Exception($"Dll must contain a public implementation of '{typeof(IBugDatabaseProvider)}'");
            }
            else if (validTypes.Count() > 1)
            {
                throw new Exception($"Dll can only contain one public implementation of '{typeof(IBugDatabaseProvider)}'. Found {validTypes.Count()}");
            }

            IBugDatabaseProvider databaseProvider = bugDatabaseFactory.CreateInstance(validTypes.First());

            databaseProvider.Logger     = logger;
            databaseProvider.WebRequest = webRequest;
            if (databaseProvider.ProcessArgs(args) != 0)
            {
                throw new Exception("Unable to parse Dll arguments. Check requirements");
            }

            return(databaseProvider);
        }
コード例 #4
0
        /// <summary>
        /// Creates the assembly suite
        /// </summary>
        /// <param name="assemblyToScan">The assembly to scan for tests</param>
        protected virtual ITestSuite CreateTest(_Assembly assemblyToScan)
        {
            var test = new AssemblySuite(assemblyToScan, Filters, Configurator);

            test.Configure(Configurator);
            return(test);
        }
コード例 #5
0
        public static IEnumerable <Type> SafeGetTypes(this _Assembly assembly)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException(nameof(assembly));
            }

            try
            {
                return(assembly.GetTypes());
            }
            catch (ReflectionTypeLoadException ex)
            {
                if (IgnoreExceptions)
                {
                    return(new List <Type>());
                }

                var builder = new StringBuilder();

                foreach (var exception in ex.LoaderExceptions)
                {
                    builder.AppendLine(exception.Message);
                }

                throw new InvalidOperationException(builder.ToString());
            }
        }
コード例 #6
0
 public override bool CompileTimeValidate(_Assembly assembly)
 {
     if (assembly != PostSharpEnvironment.CurrentProject.GetTargetAssembly(false))
     {
         ThreadingMessageSource.Instance.Write(assembly, SeverityType.Error, "THR010");
         return(false);
     }
     return(true);
 }
コード例 #7
0
 public override bool CompileTimeValidate( _Assembly assembly )
 {
     if ( assembly != PostSharpEnvironment.CurrentProject.GetTargetAssembly( false ) )
     {
         ThreadingMessageSource.Instance.Write( assembly, SeverityType.Error, "THR010" );
         return false;
     }
     return true;
 }
コード例 #8
0
ファイル: AssemblySpecifiers.cs プロジェクト: LenFon/Bifrost
#pragma warning disable 1591 // Xml Comments
        public void SpecifyUsingSpecifiersFrom(_Assembly assembly)
        {
            var assemblySpecifiers = _typeFinder.FindMultiple<ICanSpecifyAssemblies>(_contractToImplementorsMap);
            assemblySpecifiers.Where(type => type.HasDefaultConstructor()).ForEach(type =>
            {
                var specifier = Activator.CreateInstance(type) as ICanSpecifyAssemblies;
                specifier.Specify(_assemblyRuleBuilder);
            });
        }
コード例 #9
0
        public void LoadFromAssembly(_Assembly assembly)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            _types.AddRange(assembly.GetTypes());
        }
コード例 #10
0
        public void GetAssemblyPath_FromNonLocalUri()
        {
            MockRepository mockRepository = new MockRepository();
            _Assembly      assemblyMock   = mockRepository.StrictMock <_Assembly>();

            SetupResult.For(assemblyMock.EscapedCodeBase).Return("http://server/File.ext");
            mockRepository.ReplayAll();

            ReflectionUtility.GetAssemblyDirectory(assemblyMock);
        }
コード例 #11
0
ファイル: RunnerService.cs プロジェクト: jbteba/LiveDev
        public virtual CorrectionResult RunMethod(_Assembly assembly, Question question)
        {
            var        instance   = assembly.CreateInstance(question.ContractDefinition.ClassName);
            var        type       = instance.GetType();
            MethodInfo methodInfo = type.GetMethod(question.ContractDefinition.MethodName);

            return(new CorrectionResult {
                Result = methodInfo.Invoke(instance, null).ToString()
            });
        }
コード例 #12
0
ファイル: AssemblyProvider.cs プロジェクト: csuffyy/Bifrost
 void AddAssembly(_Assembly assembly)
 {
     lock (_lockObject)
     {
         if (!_assemblies.Contains(assembly, comparer))
         {
             _assemblies.Add(assembly);
         }
     }
 }
コード例 #13
0
        public void WHEN_assemblyToCrawl_Is_Null_SHOULD_throw_ArgumentNullException()
        {
            //Arrange
            _Assembly nullAssembly = null;

            //Act
            var action = new Action(() => Composer.TypeExtensions.MvcUtils.GetControllerTypes(nullAssembly));

            //Assert
            action.ShouldThrow <ArgumentNullException>();
        }
コード例 #14
0
        public object Eval(string expression, IDictionary <object, object> args)
        {
            var       sources = _codeGenerator.GetSources(_code, expression, _namespaces, _definitions);
            _Assembly asm     = _compilerImpl.Compile(sources, _references);
            var       obj     = (IComparer <IDictionary <object, object> >)asm.CreateInstance("CoApp.Eval.GeneratedCode.Foo");
            var       result  = new Dictionary <object, object>();

            _permissions.PermitOnly();
            obj.Compare(args, result);
            return(result[String.Empty]);
        }
コード例 #15
0
        public static string GetAssemblyDirectory(_Assembly assembly)
        {
            ArgumentUtility.CheckNotNull("assembly", assembly);

            Uri codeBaseUri = new Uri(assembly.EscapedCodeBase);

            if (!codeBaseUri.IsFile)
            {
                throw new InvalidOperationException(String.Format("The assembly's code base '{0}' is not a local path.", codeBaseUri.OriginalString));
            }
            return(Path.GetDirectoryName(codeBaseUri.LocalPath));
        }
コード例 #16
0
ファイル: CSharpCompiler.cs プロジェクト: hahoyer/HWsqlass.cs
 static Type FindType(_Assembly assembly, string namespaceName, string typeName)
 {
     if(namespaceName != "?" && typeName != "?")
     {
         var typeFullName = typeName;
         if(namespaceName != "")
             typeFullName = namespaceName + "." + typeName;
         return assembly.GetType(typeFullName);
     }
     var types = assembly.GetTypes();
     return types.FirstOrDefault(t => IsMatch(t, namespaceName, typeName));
 }
コード例 #17
0
ファイル: MvcUtils.cs プロジェクト: Orckestra/BetterRetail
        /// <summary>
        /// Extracts the controller types in the specified assembly.
        /// </summary>
        /// <param name="assemblyToCrawl">Assembly to crawl for Controllers.</param>
        /// <returns>Enumeration of controllers discovered. If none found, will return an empty enumeration.</returns>
        public static IEnumerable <Type> GetControllerTypes(_Assembly assemblyToCrawl)
        {
            if (assemblyToCrawl == null)
            {
                throw new ArgumentNullException(nameof(assemblyToCrawl));
            }

            var controllerTypes =
                assemblyToCrawl.GetTypes().Where(t => t.Inherits <Controller>() && t.IsPublic && !t.IsAbstract && ControllerNameRegex.IsMatch(t.Name));

            return(controllerTypes);
        }
コード例 #18
0
    public override bool CompileTimeValidate(_Assembly assembly)
    {
        IEnumerable <object> myAttributes = typeof(Program).GetCustomAttributes(inherit: true)
                                            .Where(atr => atr.GetType() == typeof(MyAttribute));

        if (!myAttributes.Any())
        {
            Message.Write(MessageLocation.Of(typeof(Program)), SeverityType.Error, "DESIGN1",
                          "You haven't marked {0} with {1}", typeof(Program), typeof(MyAttribute));
        }

        return(base.CompileTimeValidate(assembly));
    }
コード例 #19
0
 public DBVersionRepository AddVersions(_Assembly ass)
 {
     m_log.Debug(string.Format("Importing methods from assembly {0}", ass.FullName));
     foreach (Type type in ass.GetExportedTypes())
     {
         if (Minder.Engine.AttributeParser.GetAttribute <DBHistoryAttribute>(type) == null)
         {
             continue;
         }
         AddVersions(type);
     }
     return(this);
 }
コード例 #20
0
        public static IEnumerable <string> GetReferencedAssembliesPath(this _Assembly assembly, string location, bool includeSystemAssemblies = false)
        {
            Log.Write("GetReferencedAssembliesPath Started - Parameters assembly: {0}, includeSystemAssemblies: {1}", assembly.ToString(), includeSystemAssemblies);
            List <string> retPaths = new List <string>();

            List <string> referencedAssemblies = assembly.GetReferencedAssemblies()
                                                 .Where(name => includeSystemAssemblies || !IsSystemAssembly(name.Name))
                                                 .Select(name => name.Name)
                                                 .ToList();

            if (!referencedAssemblies.Any())
            {
                return(retPaths);
            }
            Log.Write($"There are {referencedAssemblies.Count} referenced non system assemblies");

            Log.Write($"Current Assembly is at location {assembly.Location}");

            string currentAssemblyPath = string.Empty;

            try
            {
                currentAssemblyPath = FileSystem.Path.GetDirectoryName(location);
            }
            catch (Exception exception)
            {
                string context = $"GetDirectoryName of assembly: {assembly.FullName} failed. Path is wrong {location}";

                Log.Write(exception, context);
                RavenWrapper.Instance.Capture(exception, message: context);
            }


            if (string.IsNullOrEmpty(currentAssemblyPath))
            {
                return(Enumerable.Empty <string>());
            }

            Log.Write("currentAssemblyPath: {0}", currentAssemblyPath);

            referencedAssemblies
            .ForEach(s =>
            {
                Log.Write("Assembly {0} Located in {1} References Assembly {2} ", assembly.GetName().Name,
                          assembly.Location, s);
                retPaths.Add(FindPath(s, currentAssemblyPath));
            });

            return(retPaths.Where(s => !string.IsNullOrEmpty(s)));
        }
コード例 #21
0
        public AssemblyFileResourceProvider(_Assembly sourceAssembly, IAssemblyResourceFilePathProvider assemblyResourceFilePathProvider)
        {
            if (sourceAssembly == null)
            {
                throw new ArgumentNullException("sourceAssembly");
            }

            if (assemblyResourceFilePathProvider == null)
            {
                throw new ArgumentNullException("assemblyResourceFilePathProvider");
            }

            this.sourceAssembly = sourceAssembly;
            this.assemblyResourceFilePathProvider = assemblyResourceFilePathProvider;
        }
コード例 #22
0
        internal static bool ReferencesAssembly(this _Assembly assembly, Assembly referencedAssembly)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException(nameof(assembly));
            }
            if (referencedAssembly == null)
            {
                throw new ArgumentNullException(nameof(referencedAssembly));
            }

            string targetAssemblyName = referencedAssembly.GetName().Name;

            return(assembly.GetName().Name == targetAssemblyName || assembly.GetReferencedAssemblies().Any(r => r.Name == targetAssemblyName));
        }
コード例 #23
0
        private LogConfig GetLogConfig(_Assembly assembly)
        {
            var context = Container.Resolve <IPluginExecutionContext>();

            if (!LogConfig.TryParse(context.SharedVariables, out var logConfig))
            {
                logConfig =
                    GetLogConfigFromAssemblyAttribute(assembly) ??
                    new LogConfig(PluginLogOption.Off, null);

                logConfig.Save(context.SharedVariables);
            }

            return(logConfig);
        }
コード例 #24
0
        private LogConfig GetLogConfigFromAssemblyAttribute(_Assembly assembly)
        {
            assembly = assembly ?? Assembly.GetExecutingAssembly();
            if (TryGetAttribute <FilePluginLoggingAttribute>(assembly, out var filePluginLogAttribute))
            {
                if (Directory.Exists(filePluginLogAttribute.DirPath))
                {
                    return(new LogConfig(PluginLogOption.File, filePluginLogAttribute.DirPath));
                }
            }
            else if (TryGetAttribute <CrmPluginLoggingAttribute>(assembly, out var pluginCrmLogAttribute) && ShouldLogToCrm())
            {
                return(new LogConfig(PluginLogOption.Crm, null));
            }

            return(null);
        }
コード例 #25
0
        public SelfUpdateCommand(ApplicationInformation applicationInformation, ISelfUpdateService selfUpdateService, _Assembly targetAssembly)
        {
            if (applicationInformation == null)
            {
                throw new ArgumentNullException("applicationInformation");
            }

            if (selfUpdateService == null)
            {
                throw new ArgumentNullException("selfUpdateService");
            }

            if (targetAssembly == null)
            {
                throw new ArgumentNullException("targetAssembly");
            }

            this.applicationInformation = applicationInformation;
            this.selfUpdateService = selfUpdateService;
            this.targetAssembly = targetAssembly;

            this.Attributes = new CommandAttributes
            {
                CommandName = CommandName,
                AlternativeCommandNames = this.alternativeCommandNames,
                RequiredArguments = new string[] { },
                PositionalArguments = new string[] { },
                Description = string.Format(Resources.SelfUpdateCommand.CommandDescriptionTextTemplate, this.applicationInformation.NameOfExecutable),
                Usage = string.Format("{0}", CommandName),
                Examples = new Dictionary<string, string>
                    {
                        {
                            string.Format("{0}", CommandName),
                            Resources.SelfUpdateCommand.CommandExampleDescription1
                        }
                    },
                ArgumentDescriptions = new Dictionary<string, string>()
            };

            this.Arguments = new Dictionary<string, string>();
        }
コード例 #26
0
        public void LoadFlushedCode(_Assembly assembly)
        {
            ArgumentUtility.CheckNotNull("assembly", assembly);

            var typePipeAttribute =
                (TypePipeAssemblyAttribute)assembly.GetCustomAttributes(typeof(TypePipeAssemblyAttribute), inherit: false).SingleOrDefault();

            if (typePipeAttribute == null)
            {
                throw new ArgumentException("The specified assembly was not generated by the pipeline.", "assembly");
            }

            if (typePipeAttribute.ParticipantConfigurationID != _typeAssembler.ParticipantConfigurationID)
            {
                var message = string.Format(
                    "The specified assembly was generated with a different participant configuration: '{0}'.",
                    typePipeAttribute.ParticipantConfigurationID);
                throw new ArgumentException(message, "assembly");
            }

            _typeCache.LoadTypes(assembly.GetTypes());
        }
コード例 #27
0
 public AssemblyWebResources(_Assembly resourcesAssembly)
 {
     _ResourcesAssembly = resourcesAssembly;
     _WebSiteRoot       = _ResourcesAssembly.GetName().Name;
 }
コード例 #28
0
 public FunnelWebScriptProvider(_Assembly assembly, Func <string, bool> filter, string databaseProviderName)
 {
     this.assembly             = assembly;
     this.filter               = filter;
     this.databaseProviderName = databaseProviderName.ToLower();
 }
コード例 #29
0
 private static bool TryGetAttribute <T>(_Assembly assembly, out T attribute)
     where T : Attribute
 {
     attribute = (T)assembly.GetCustomAttributes(typeof(T), false).FirstOrDefault();
     return(attribute != null);
 }
コード例 #30
0
 public PluginConfiguration(IPluginBase plugin, IContainer container, _Assembly assembly = null)
     : this(assembly)
 {
     Plugin    = plugin ?? throw new ArgumentNullException(nameof(plugin));
     Container = container ?? throw new ArgumentNullException(nameof(container));
 }
コード例 #31
0
 public ScenarioTypeFinder(_Assembly assembly)
 {
     this.assembly = assembly;
 }
コード例 #32
0
ファイル: CSharpCompiler.cs プロジェクト: hahoyer/HWsqlass.cs
 static MethodInfo FindMethod(_Assembly assembly, string namespaceName, string typeName, string methodName)
 {
     var type = FindType(assembly, namespaceName, typeName);
     return FindMethod(type, methodName);
 }
コード例 #33
0
 public PluginConfiguration(_Assembly assembly = null)
 {
     _logConfig = new Lazy <LogConfig>(() => GetLogConfig(assembly));
 }
コード例 #34
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AssemblyTypeSource"/> class.
 /// </summary>
 /// <param name="assembly">The assembly.</param>
 public AssemblyTypeSource(Assembly assembly)
 {
     AssertUtils.ArgumentNotNull(assembly, "assembly");
     _assembly = assembly;
 }
コード例 #35
0
 public FunnelWebScriptProvider(_Assembly assembly, Func<string, bool> filter, string databaseProviderName)
 {
     this.assembly = assembly;
     this.filter = filter;
     this.databaseProviderName = databaseProviderName.ToLower();
 }
コード例 #36
0
        public static AssemblyNameParts GetNameParts(this _Assembly assembly)
        {
            var parts = AssemblyExtensions.ParseAssemblyName(assembly.FullName);

            return(parts);
        }
コード例 #37
0
 public DBVersionRepository AddVersions(_Assembly ass)
 {
     m_log.Debug(string.Format("Importing methods from assembly {0}", ass.FullName));
     foreach (Type type in ass.GetExportedTypes())
     {
         if (Minder.Engine.AttributeParser.GetAttribute<DBHistoryAttribute>(type) == null)
             continue;
         AddVersions(type);
     }
     return this;
 }
コード例 #38
0
 /// <summary>
 /// Gets all testable classes (types) within the assembly
 /// </summary>
 public static IEnumerable <Type> GetTestClasses(this _Assembly assembly)
 {
     return(assembly
            .GetTypes()
            .Where(type => type.IsTestable()));
 }
コード例 #39
0
ファイル: AssemblyProvider.cs プロジェクト: LenFon/Bifrost
 void SpecifyRules(_Assembly assembly)
 {
     _assemblySpecifiers.SpecifyUsingSpecifiersFrom(assembly);
 }
コード例 #40
0
ファイル: AssemblyProvider.cs プロジェクト: LenFon/Bifrost
        void AddAssembly(_Assembly assembly)
        {
            lock (_lockObject)
            {
                if (!_assemblies.Contains(assembly, comparer) &&
                    !_assemblyUtility.IsAssemblyDynamic(assembly))
                {
                    _assemblies.Add(assembly);

                    if (assembly.FullName.Contains("Web"))
                    {
                        var i = 0;
                        i++;
                    }
                    _contractToImplementorsMap.Feed(assembly.GetTypes());
                    SpecifyRules(assembly);
                    ReapplyFilter();
                }
            }
        }
コード例 #41
0
ファイル: AssemblyUtility.cs プロジェクト: LenFon/Bifrost
 public bool IsAssemblyDynamic(_Assembly assembly)
 {
     var module = assembly.GetModules().FirstOrDefault();
     if (module != null && module.GetType().Name == "InternalModuleBuilder") return true;
     return false;
 }
コード例 #42
0
 public AssemblyTestRunner(_Assembly assembly)
 {
     this.assembly = assembly;
 }