protected override void Initialize() { base.Initialize(); this.currAssembly = this.Services.CurrentAssembly.Assembly.Assembly; this.Log.LogMessage("MSeqGenRecommender", "MSeqGenRecommender initialized"); this.LoadExplorableCandidates(); }
/// <summary> /// Tries to get the assembly set up tear down attribute. /// </summary> /// <param name="assembly"> /// The assembly. /// </param> /// <param name="setUp"> /// The set up. /// </param> /// <param name="tearDown"> /// The tear down. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public override bool TryGetAssemblySetupTeardownMethods(AssemblyEx assembly, out Method setUp, out Method tearDown) { setUp = null; tearDown = null; return(false); }
public void GetTypesWithAttributeInheriteTest() { var actual = AssemblyEx.GetTypesWithAttribute <FooAttribute>(true, GetType() .GetDeclaringAssembly()) .ToList(); actual.Should() .HaveCount(5); //BaseTextClass var attributes = actual.First(x => x.Type == typeof(BaseTestClass)) .Attributes.ToList(); attributes.Should() .HaveCount(1); attributes.First() .Value.Should() .Be("base"); // TestClassA attributes = actual.First(x => x.Type == typeof(TestClassA)) .Attributes.ToList(); attributes.Should() .HaveCount(2); attributes.Should() .Contain(x => x.Value == "A"); attributes.Should() .Contain(x => x.Value == "base"); // TestClassB attributes = actual.First(x => x.Type == typeof(TestClassB)) .Attributes.ToList(); attributes.Should() .HaveCount(1); attributes.First() .Value.Should() .Be("base"); // TestClassC attributes = actual.First(x => x.Type == typeof(TestClassC)) .Attributes.ToList(); attributes.Should() .HaveCount(1); attributes.Should() .Contain(x => x.Value == "C"); // TestClassD attributes = actual.First(x => x.Type == typeof(TestClassD)) .Attributes.ToList(); attributes.Should() .HaveCount(3); attributes.Should() .Contain(x => x.Value == "D1"); attributes.Should() .Contain(x => x.Value == "base"); attributes.Should() .Contain(x => x.Value == "D2"); }
public void GetTypesWithAttributeArgumentNullExceptionTest() { // ReSharper disable once AssignNullToNotNullAttribute // ReSharper disable once ReturnValueOfPureMethodIsNotUsed Action test = () => AssemblyEx.GetTypesWithAttribute <FooAttribute>(null); Assert.Throws <ArgumentNullException>(test); }
/// <summary> /// /// </summary> public override void Load() { if (this._zipFile == null || this._zipFile.Length == 0 || this._zipStream == null) { // read the open the zip archive Stream fs = null; this._zipFile = Path.GetFullPath(Name); if (File.Exists(this._zipFile)) { fs = File.OpenRead(this._zipFile); } if (fs == null) { this._zipFile = Name.Replace('/', '.'); var assemblyContent = (from assembly in AssemblyEx.Neighbors() where this._zipFile.StartsWith(assembly.FullName.Split(',')[0]) select assembly).FirstOrDefault(); if (assemblyContent != null) { fs = assemblyContent.GetManifestResourceStream(this._zipFile); } } #if (XBOX || XBOX360) if (fs == null) { _zipFile = Name; var isf = IsolatedStorageFile.GetUserStoreForApplication(); fs = isf.OpenFile(_zipFile, FileMode.Open, FileAccess.Read); } #endif if (fs == null) { throw new FileNotFoundException(Name); } fs.Position = 0; // get a input stream from the zip file this._zipStream = ZipFile.Read(fs); this._fileList.AddRange(from entry in _zipStream.Entries select new FileInfo { Archive = this, Filename = entry.FileName, Basename = Path.GetFileName(entry.FileName), Path = Path.GetDirectoryName(entry.FileName) + Path.DirectorySeparatorChar, CompressedSize = entry.CompressedSize, UncompressedSize = entry.UncompressedSize }); } }
/// <summary> /// Analyzes the given assembly statically and gathers all declared entities /// such as member variables and local variables /// </summary> /// <param name="assembly"></param> public static void CollectAllDeclEntitiesInAssembly(AssemblyEx assembly) { SafeDebug.AssumeNotNull(assembly, "assembly"); logger.Debug("Beginning of static analysis"); if (ade == null) { ade = DUCoverStore.GetInstance(); } foreach (TypeDefinition td in assembly.TypeDefinitions) { CollectAllDeclEntitiesInTypeDef(td); } }
public EmbeddedArchive(string name, string archType) : base(name.Split('/')[0], archType) { var named = Name + ","; this.assembly = (from a in AssemblyEx.Neighbors() where a.FullName.StartsWith(named) select a).First(); Name = name.Replace('/', '.'); this.resources = (from resource in this.assembly.GetManifestResourceNames() //where resource.StartsWith(Name) select resource).ToList(); this.resources.Sort(); }
private void AddCetrifugeSpecificCommands() { CommandTerminal.Terminal.Shell.AddCommand("cnfg_version", (args) => { var thisAssemblyVersion = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location); var reactorVersion = FileVersionInfo.GetVersionInfo(AssemblyEx.GetAssemblyByName("Reactor").Location); var centrifugeVersion = FileVersionInfo.GetVersionInfo(AssemblyEx.GetAssemblyByName("Centrifuge").Location); var reactorApiVersion = FileVersionInfo.GetVersionInfo(AssemblyEx.GetAssemblyByName("Reactor.API").Location); CommandTerminal.Terminal.Log(centrifugeVersion.ToString()); CommandTerminal.Terminal.Log(reactorApiVersion.ToString()); CommandTerminal.Terminal.Log(reactorVersion.ToString()); CommandTerminal.Terminal.Log(thisAssemblyVersion.ToString()); }, 0, -1, "Prints versions of all core Centrifuge modules."); }
public PexMePostProcessor(IPexComponent host) : base(host) { this.host = host; this.pmd = host.GetService <IPexMeDynamicDatabase>() as PexMeDynamicDatabase; this.psd = host.GetService <IPexMeStaticDatabase>() as PexMeStaticDatabase; this.pdw = new PexMeDumpWriter(host); this.currAssembly = this.pmd.Services.CurrentAssembly.Assembly.Assembly; var nestingdepth = System.Environment.GetEnvironmentVariable("PEXME_NESTED_DEPTH"); if (nestingdepth != null) { ndepth = Convert.ToInt32(nestingdepth, 10); } }
private static void AddReferencedAssemblies(CompilerParameters param, params Assembly[] assemblies) { foreach (string assembly in LibraryDependency) { string location = AssemblyEx.GetAssemblyLocation(assembly); if (File.Exists(location)) { param.ReferencedAssemblies.Add(location); } } // 외부 라이브러리 foreach (Assembly assm in assemblies) { param.ReferencedAssemblies.Add(assm.Location); } }
private static Type ResolveImpl(string typeName) { var type = Type.GetType(typeName); if (type != null) { return(type); } foreach (var assembly in AssemblyEx.GetAllAssemblies()) { type = assembly.GetType(typeName); if (type != null) { return(type); } } return(null); }
public static bool TryGetTypeExFromName(IPexComponent host, AssemblyEx assembly, string typename, out TypeEx typeEx) { if (typeExCache.TryGetValue(typename, out typeEx)) { return(true); } typeEx = null; foreach (var assemtype in assembly.TypeDefinitions) { if (assemtype.FullName == typename) { typeEx = assemtype.Instantiate(GetGenericTypeParameters(host, assemtype)); typeExCache.Add(typename, typeEx); return(true); } } return(false); }
/// <summary> /// Initializes DUCover. /// </summary> public static void Initialize(AssemblyEx assembly) { if (!bLoggerInitialized) { InitializeLogger(); bLoggerInitialized = true; logger = LogManager.GetCurrentClassLogger(); } //Check whether intialization information is required for this assembly var shortname = assembly.ShortName; if (DUCoverConstants.SystemAssemblies.Contains(shortname)) { return; } //Analyzes all classes and methods and collects all entities. DeclEntityCollector.CollectAllDeclEntitiesInAssembly(assembly); //Populate all Def-Use tables PopulateAllDUCoverTables(); }
/// <inheritdoc/> public override bool TryGetAssemblySetupTeardownMethods(AssemblyEx assembly, out Method setup, out Method teardown) { // xUnit.net does not have an assembly setup and teardown setup = teardown = null; return(false); }
/// <summary> /// Loads all inheritance hierarchies in the current library /// into TypeDictionary in the form of a tree suitable for traversal. /// </summary> public void LoadInheritanceHierarchies() { if (isInheritanceHierarchyLoaded) { return; } isInheritanceHierarchyLoaded = true; AssemblyEx currAssembly = this.Services.CurrentAssembly.Assembly.Assembly; foreach (var tdef in currAssembly.TypeDefinitions) { TypeStore currTypeStore; if (!this.TypeDictionary.TryGetValue(tdef, out currTypeStore)) { currTypeStore = new TypeStore(tdef); this.TypeDictionary.Add(tdef, currTypeStore); } var baseType = tdef.BaseTypeDefinition; //This restricts our implementation to a single assembly for time being. if (baseType != null && baseType.Module.Assembly == currAssembly) { TypeStore baseTypeStore; if (!this.TypeDictionary.TryGetValue(baseType, out baseTypeStore)) { baseTypeStore = new TypeStore(baseType); this.TypeDictionary.Add(baseType, baseTypeStore); } baseTypeStore.ExtendingTypes.Add(currTypeStore); } try { var typeEx = tdef.Instantiate(MethodOrFieldAnalyzer.GetGenericTypeParameters(this, tdef)); if (typeEx != null) { foreach (var ifTypeEx in typeEx.DeclaredInterfaces) { var parentIfDef = ifTypeEx.Definition; if (parentIfDef.Module.Assembly != currAssembly) { continue; } TypeStore ifTypeStore; if (!this.TypeDictionary.TryGetValue(parentIfDef, out ifTypeStore)) { ifTypeStore = new TypeStore(parentIfDef); this.TypeDictionary.Add(parentIfDef, ifTypeStore); } ifTypeStore.ExtendingTypes.Add(currTypeStore); } } } catch (Exception ex) { this.Log.LogWarningFromException(ex, WikiTopics.MissingWikiTopic, "InheritanceLoader", "Failed to instantiate class " + tdef.FullName.ToString()); } } }
/// <summary> /// Tries to get the assembly set up tear down attribute. /// </summary> /// <param name="assembly">The assembly.</param> /// <param name="setUp">The set up.</param> /// <param name="tearDown">The tear down.</param> /// <returns>True if found.</returns> public override bool TryGetAssemblySetupTeardownMethods( AssemblyEx assembly, out Method setUp, out Method tearDown) { // <preconditions> SafeDebug.AssumeNotNull((object)assembly, "assembly"); // </preconditions> setUp = tearDown = null; // look for [TestClass] types foreach (var typeDefinition in assembly.TypeDefinitions) { if (typeDefinition.IsVisible(VisibilityContext.Exported)) { if (typeDefinition.IsEnumType || typeDefinition.GenericTypeParameters.Length > 0) { continue; } if (!this.IsFixture(typeDefinition)) { continue; } // looking for assembly setup/teardown methods foreach (var methodDefinition in typeDefinition.DeclaredStaticMethods) { if (methodDefinition.IsVisible(VisibilityContext.Exported) && methodDefinition.GenericMethodParameters.Length == 0) { if (AttributeHelper.IsDefined(methodDefinition, this.AssemblySetUpAttribute, true)) { setUp = methodDefinition.Instantiate(TypeEx.NoTypes, TypeEx.NoTypes); } if (AttributeHelper.IsDefined(methodDefinition, this.AssemblyTearDownAttribute, true)) { tearDown = methodDefinition.Instantiate(TypeEx.NoTypes, TypeEx.NoTypes); } // nothing else to look for if (setUp != null && tearDown != null) { break; } } } // nothing else to look for if (setUp != null && tearDown != null) { break; } } } return(setUp != null || tearDown != null); }
private Assembly ReturnCallingAssembly() { return(AssemblyEx.GetCallingAssembly()); }
/// <summary> /// Retrieves the PUT for the method we are looking for in the current assembly /// </summary> /// <param name="method"></param> /// <returns></returns> public static bool TryRetrievePUT(IPexComponent host, AssemblyEx assembly, Method method, out Method putmethod) { //Get the class name of the target class that is including //the method we are looking for TypeEx declaringType; bool bresult = method.TryGetDeclaringType(out declaringType); SafeDebug.Assume(bresult, "Failed to get the declaring type!!!"); string tclassname = null; var declaringTypeDef = declaringType.Definition; if (declaringTypeDef.GenericTypeParametersCount == 0) { tclassname = declaringType.ShortName.ToString(); } else { tclassname = declaringType.ShortName.ToString(); tclassname = tclassname.Substring(0, tclassname.IndexOf('`')); foreach (var param in declaringTypeDef.GenericTypeParameters) { tclassname = tclassname + param.Name; } } tclassname = tclassname + "Test"; foreach (var classdef in assembly.TypeDefinitions) { if (classdef.ShortName != tclassname) { continue; } //TODO: To be more robust, we can later replace //this piece of code by actually checking whether there //is a method call to the method of the library we are looking for foreach (var mdef in classdef.DeclaredInstanceMethods) { if (mdef.ShortName == method.ShortName) { bool isPexMethod = false; foreach (var attr in mdef.DeclaredAttributes) { if (attr.SerializableName.ToString().Contains("PexMethodAttribute")) { isPexMethod = true; break; } } if (isPexMethod) { putmethod = mdef.Instantiate(MethodOrFieldAnalyzer.GetGenericTypeParameters(host, classdef), MethodOrFieldAnalyzer.GetGenericMethodParameters(host, mdef)); return(true); } } } } putmethod = null; return(false); }
protected override object BeforeExecution(IPexComponent host) { assemblyUnderTest = host.Services.CurrentAssembly.Assembly.Assembly; return(null); }
/// <summary> /// /// </summary> public override void Load() { if (this._zipFile == null || this._zipFile.Length == 0 || this._zipStream == null) { // read the open the zip archive Stream fs = null; #if SILVERLIGHT && !WINDOWS_PHONE if (Application.Current.HasElevatedPermissions) #endif { this._zipFile = Path.GetFullPath(Name); if (File.Exists(this._zipFile)) { fs = File.OpenRead(this._zipFile); } } if (fs == null) { this._zipFile = Name.Replace('/', '.'); var assemblyContent = (from assembly in AssemblyEx.Neighbors() where this._zipFile.StartsWith(assembly.FullName.Split(',')[0]) select assembly).FirstOrDefault(); if (assemblyContent != null) { fs = assemblyContent.GetManifestResourceStream(this._zipFile); } } #if (SILVERLIGHT && WINDOWS_PHONE) || (XBOX || XBOX360) if (fs == null) { _zipFile = Name; var isf = IsolatedStorageFile.GetUserStoreForApplication(); fs = isf.OpenFile(_zipFile, FileMode.Open, FileAccess.Read); } #endif #if SILVERLIGHT if (fs == null) { _zipFile = Name; var res = Application.GetResourceStream(new Uri(_zipFile, UriKind.RelativeOrAbsolute)); if (res != null) { fs = res.Stream; } } #endif if (fs == null) { throw new FileNotFoundException(Name); } fs.Position = 0; // get a input stream from the zip file this._zipStream = ZipFile.Read(fs); //ZipEntry entry = _zipStream.GetNextEntry(); //Regex ex = new Regex( pattern ); //while ( entry != null ) //{ // // get the full path for the output file // string file = entry.Name; // if ( ex.IsMatch( file ) ) // { // FileInfo fileInfo; // fileInfo.Archive = this; // fileInfo.Filename = entry.Name; // fileInfo.Basename = Path.GetFileName( entry.Name ); // fileInfo.Path = Path.GetDirectoryName( entry.Name ) + Path.DirectorySeparatorChar; // fileInfo.CompressedSize = entry.CompressedSize; // fileInfo.UncompressedSize = entry.Size; // _fileList.Add( fileInfo ); // } // entry = _zipStream.GetNextEntry(); //} } }
/// <summary> /// Returns assembly pack for a given assembly name. /// <para>For example: pack://application:,,,/[assemblyName];component</para> /// </summary> public static string GetAssemblyPack(string assemblyName) { return(AssemblyEx.GetAssemblyPack(assemblyName)); }
/// <summary> /// Returns the component path for a given assembly name /// </summary> public static string GetAssemblyComponent(string assemblyName) { return(AssemblyEx.GetAssemblyComponent(assemblyName)); }