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)); }
/// <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())); }
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); }
/// <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); }
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()); } }
public override bool CompileTimeValidate(_Assembly assembly) { if (assembly != PostSharpEnvironment.CurrentProject.GetTargetAssembly(false)) { ThreadingMessageSource.Instance.Write(assembly, SeverityType.Error, "THR010"); return(false); } return(true); }
public override bool CompileTimeValidate( _Assembly assembly ) { if ( assembly != PostSharpEnvironment.CurrentProject.GetTargetAssembly( false ) ) { ThreadingMessageSource.Instance.Write( assembly, SeverityType.Error, "THR010" ); return false; } return true; }
#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); }); }
public void LoadFromAssembly(_Assembly assembly) { if (assembly == null) { throw new ArgumentNullException("assembly"); } _types.AddRange(assembly.GetTypes()); }
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); }
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() }); }
void AddAssembly(_Assembly assembly) { lock (_lockObject) { if (!_assemblies.Contains(assembly, comparer)) { _assemblies.Add(assembly); } } }
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>(); }
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]); }
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)); }
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)); }
/// <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); }
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)); }
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); }
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))); }
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; }
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)); }
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); }
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); }
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>(); }
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()); }
public AssemblyWebResources(_Assembly resourcesAssembly) { _ResourcesAssembly = resourcesAssembly; _WebSiteRoot = _ResourcesAssembly.GetName().Name; }
public FunnelWebScriptProvider(_Assembly assembly, Func <string, bool> filter, string databaseProviderName) { this.assembly = assembly; this.filter = filter; this.databaseProviderName = databaseProviderName.ToLower(); }
private static bool TryGetAttribute <T>(_Assembly assembly, out T attribute) where T : Attribute { attribute = (T)assembly.GetCustomAttributes(typeof(T), false).FirstOrDefault(); return(attribute != null); }
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)); }
public ScenarioTypeFinder(_Assembly assembly) { this.assembly = assembly; }
static MethodInfo FindMethod(_Assembly assembly, string namespaceName, string typeName, string methodName) { var type = FindType(assembly, namespaceName, typeName); return FindMethod(type, methodName); }
public PluginConfiguration(_Assembly assembly = null) { _logConfig = new Lazy <LogConfig>(() => GetLogConfig(assembly)); }
/// <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; }
public FunnelWebScriptProvider(_Assembly assembly, Func<string, bool> filter, string databaseProviderName) { this.assembly = assembly; this.filter = filter; this.databaseProviderName = databaseProviderName.ToLower(); }
public static AssemblyNameParts GetNameParts(this _Assembly assembly) { var parts = AssemblyExtensions.ParseAssemblyName(assembly.FullName); return(parts); }
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; }
/// <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())); }
void SpecifyRules(_Assembly assembly) { _assemblySpecifiers.SpecifyUsingSpecifiersFrom(assembly); }
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(); } } }
public bool IsAssemblyDynamic(_Assembly assembly) { var module = assembly.GetModules().FirstOrDefault(); if (module != null && module.GetType().Name == "InternalModuleBuilder") return true; return false; }
public AssemblyTestRunner(_Assembly assembly) { this.assembly = assembly; }