예제 #1
0
		/// <summary>
		///   Determines whether this assembly has internals visible to dynamic proxy.
		/// </summary>
		/// <param name = "asm">The assembly to inspect.</param>
		public bool IsInternalToDynamicProxy(Assembly asm)
		{
			using (var locker = internalsToDynProxyLock.ForReadingUpgradeable())
			{
				if (internalsToDynProxy.ContainsKey(asm))
				{
					return internalsToDynProxy[asm];
				}

				locker.Upgrade();

				if (internalsToDynProxy.ContainsKey(asm))
				{
					return internalsToDynProxy[asm];
				}

                var internalsVisibleTo = asm.GetAttributes<InternalsVisibleToAttribute>();
                var found = internalsVisibleTo.Any(attr => {
                            var parts = attr.AssemblyName.Split(',');
                            return parts.Length > 0
                                && (parts[0] == this.moduleScope.StrongAssemblyName
                                    || parts[0] == this.moduleScope.WeakAssemblyName);
                        });

				internalsToDynProxy.Add(asm, found);
				return found;
			}
		}
        // ReSharper restore SuggestBaseTypeForParameter
        // ReSharper disable SuggestBaseTypeForParameter
        internal static Result<string> GetAssemblyConfiguration(Assembly callingAssembly)
        {
            var attributes = callingAssembly
                .GetAttributes<AssemblyConfigurationAttribute>(true);

            if (attributes.Length == 0)
                return Result<string>.CreateError("Attribute is not present");
            return Result.CreateSuccess(attributes[0].Configuration);
        }
예제 #3
0
        public static ITestAction[] GetActionsFromAttributeProvider(Assembly attributeProvider)
        {
            if (attributeProvider == null)
                return new ITestAction[0];

            var actions = attributeProvider.GetAttributes<ITestAction>().ToList();
            actions.Sort(SortByTargetDescending);

            return actions.ToArray();
        }
예제 #4
0
        /// <summary>
        ///     Add a compression stream to the library.  Zlib is the default.
        /// </summary>
        /// <param name="a">
        ///     The assembly containing the stream definition.
        /// </param>
        public static void AddCompression(Assembly a)
        {
            Log.Debug("Loading compression algorithms from {Assembly}", a.FullName);

            IEnumerable<CompressionAttribute> tags = a.GetAttributes<CompressionAttribute>();
            foreach (CompressionAttribute tag in tags)
            {
                Log.Debug("Loading algorithm {Algorithm}", tag.Algorithm);
                RegisteredItems.Add(tag.Algorithm, tag.ClassType);
            }
        }
예제 #5
0
        /// <summary>
        /// Add a compression stream to the library.  Zlib is the default.
        /// </summary>
        /// <param name="a">
        /// The assembly containing the stream definition.
        /// </param>
        public static void AddCompression(Assembly a)
        {
            Logger.DebugFormat(typeof(CompressionRegistry), "Adding assembly {0}", a.FullName);

            var tags = a.GetAttributes<CompressionAttribute>();
            foreach (var tag in tags)
            {
                Logger.DebugFormat(typeof(CompressionRegistry), "Adding {0}", tag.Algorithm);
                RegisteredItems.Add(tag.Algorithm, tag.ClassType);
            }
        }
예제 #6
0
        public AssemblyExplorationData Explore(Assembly assembly)
        {
            var bootstrapTypes = assembly.GetTypes().Where(x => x.IsInstantiatable<ILazyBootstrap>());

              var suiteTypes = assembly.GetTypes().Where(x => x.IsInstantiatable<ISuite>() && x.GetAttribute<SubjectAttributeBase>() != null).ToList();
              var suiteBaseTypes = suiteTypes.Select(x => x.GetImmediateDerivedTypesOf<ISuite>().Single()).Distinct();
              var testExtensions = assembly.GetAttributes<UseTestExtension>()
              .Select(x => x.TestExtensionType.CreateInstance<ITestExtension>())
              .OrderByDescending(x => x.Priority);
              var typeLoaders = suiteBaseTypes.ToDictionary(x => x, x => CreateTypeLoader(x, testExtensions));

              return new AssemblyExplorationData(typeLoaders, suiteTypes, bootstrapTypes);
        }
예제 #7
0
파일: Test.cs 프로젝트: nunit/nunit
 /// <summary>
 /// Modify a newly constructed test by applying any of NUnit's common
 /// attributes, based on a supplied ICustomAttributeProvider, which is
 /// usually the reflection element from which the test was constructed,
 /// but may not be in some instances. The attributes retrieved are 
 /// saved for use in subsequent operations.
 /// </summary>
 /// <param name="provider">An object deriving from MemberInfo</param>
 public void ApplyAttributesToTest(Assembly provider)
 {
     foreach (IApplyToTest iApply in provider.GetAttributes<IApplyToTest>())
         iApply.ApplyToTest(this);
 }