Ejemplo n.º 1
0
        /// <summary>
        /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
        /// Returns an <see cref="IDatabaseAssembler"/> that represents the building process for a a concrete <see cref="Database"/>.
        /// </summary>
        /// <param name="type">The concrete <see cref="Database"/> type.</param>
        /// <param name="name">The name of the instance to build, or <see langword="null"/> (<b>Nothing</b> in Visual Basic).</param>
        /// <param name="reflectionCache">The cache to use retrieving reflection information.</param>
        /// <returns>The <see cref="IDatabaseAssembler"/> instance.</returns>
        /// <exception cref="InvalidOperationException">when concrete <see cref="Database"/> type does have the required <see cref="DatabaseAssemblerAttribute"/>.</exception>
        public IDatabaseAssembler GetAssembler(Type type, string name, ConfigurationReflectionCache reflectionCache)
        {
            bool exists = false;
            IDatabaseAssembler assembler;

            lock (assemblersMappingLock)
            {
                exists = assemblersMapping.TryGetValue(type, out assembler);
            }
            if (!exists)
            {
                DatabaseAssemblerAttribute assemblerAttribute
                    = reflectionCache.GetCustomAttribute <DatabaseAssemblerAttribute>(type);
                if (assemblerAttribute == null)
                {
                    throw new InvalidOperationException(
                              string.Format(
                                  Resources.Culture,
                                  Resources.ExceptionDatabaseTypeDoesNotHaveAssemblerAttribute,
                                  type.FullName,
                                  name));
                }

                assembler
                    = (IDatabaseAssembler)Activator.CreateInstance(assemblerAttribute.AssemblerType);

                lock (assemblersMappingLock)
                {
                    assemblersMapping[type] = assembler;
                }
            }

            return(assembler);
        }
 private InstrumentationListenerAttribute GetInstrumentationListenerAttribute(object createdObject, ConfigurationReflectionCache reflectionCache)
 {
     Type createdObjectType = createdObject.GetType();
     InstrumentationListenerAttribute listenerAttribute
         = reflectionCache.GetCustomAttribute<InstrumentationListenerAttribute>(createdObjectType, true);
     return listenerAttribute;
 }
		/// <summary>
		/// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
		/// Returns an <see cref="IDatabaseAssembler"/> that represents the building process for a a concrete <see cref="Database"/>.
		/// </summary>
		/// <param name="type">The concrete <see cref="Database"/> type.</param>
		/// <param name="name">The name of the instance to build, or <see langword="null"/> (<b>Nothing</b> in Visual Basic).</param>
		/// <param name="reflectionCache">The cache to use retrieving reflection information.</param>
		/// <returns>The <see cref="IDatabaseAssembler"/> instance.</returns>
		/// <exception cref="InvalidOperationException">when concrete <see cref="Database"/> type does have the required <see cref="DatabaseAssemblerAttribute"/>.</exception>
		public IDatabaseAssembler GetAssembler(Type type, string name, ConfigurationReflectionCache reflectionCache)
		{
			bool exists = false;
			IDatabaseAssembler assembler;
			lock (assemblersMappingLock)
			{
				exists = assemblersMapping.TryGetValue(type, out assembler);
			}
			if (!exists)
			{
				DatabaseAssemblerAttribute assemblerAttribute
					= reflectionCache.GetCustomAttribute<DatabaseAssemblerAttribute>(type);
				if (assemblerAttribute == null)
					throw new InvalidOperationException(
						string.Format(
							Resources.Culture,
							Resources.ExceptionDatabaseTypeDoesNotHaveAssemblerAttribute,
							type.FullName,
							name));

				assembler
					= (IDatabaseAssembler)Activator.CreateInstance(assemblerAttribute.AssemblerType);

				lock (assemblersMappingLock)
				{
					assemblersMapping[type] = assembler;
				}
			}
			
			return assembler;
		}
Ejemplo n.º 4
0
 public IDatabaseAssembler GetAssembler(Type type, string name, ConfigurationReflectionCache reflectionCache)
 {
     IDatabaseAssembler assembler;
     bool flag = false;
     lock (this.assemblersMappingLock)
     {
         flag = this.assemblersMapping.TryGetValue(type, out assembler);
     }
     if (!flag)
     {
         DatabaseAssemblerAttribute customAttribute = reflectionCache.GetCustomAttribute<DatabaseAssemblerAttribute>(type);
         if (customAttribute == null)
         {
             throw new InvalidOperationException(string.Format(Resources.Culture, Resources.ExceptionDatabaseTypeDoesNotHaveAssemblerAttribute, new object[] { type.FullName, name }));
         }
         assembler = (IDatabaseAssembler) Activator.CreateInstance(customAttribute.AssemblerType);
         lock (this.assemblersMappingLock)
         {
             this.assemblersMapping[type] = assembler;
         }
     }
     return assembler;
 }
Ejemplo n.º 5
0
        public void CanGetExistingAttributeForTheFirstTime()
        {
            MockAttribute attribute = cache.GetCustomAttribute <MockAttribute>(typeof(TypeWithMockAttributeA));

            Assert.IsNotNull(attribute);
            Assert.AreEqual(1, attribute.value);
        }