Esempio n. 1
0
        private AssemblerAttribute GetAssemblerAttribute(Type type)
        {
            AssemblerAttribute assemblerAttribute
                = Attribute.GetCustomAttribute(type, typeof(AssemblerAttribute)) as AssemblerAttribute;

            if (assemblerAttribute == null)
            {
                throw new InvalidOperationException(
                          string.Format(
                              Resources.Culture,
                              Resources.ExceptionAssemblerAttributeNotSet,
                              type.FullName));
            }

            return(assemblerAttribute);
        }
Esempio n. 2
0
        private IAssembler <TObject, TConfiguration> GetAssembler(TConfiguration objectConfiguration)
        {
            bool exists = false;
            Type type   = objectConfiguration.GetType();
            IAssembler <TObject, TConfiguration> assembler;

            lock (assemblersMappingLock)
            {
                exists = assemblersMapping.TryGetValue(type, out assembler);
            }
            if (exists)
            {
                return(assembler);
            }

            AssemblerAttribute assemblerAttribute = GetAssemblerAttribute(type);

            if (!typeof(IAssembler <TObject, TConfiguration>).IsAssignableFrom(assemblerAttribute.AssemblerType))
            {
                throw new InvalidOperationException(
                          string.Format(
                              Resources.Culture,
                              Resources.ExceptionAssemblerTypeNotCompatible,
                              objectConfiguration.GetType().FullName,
                              typeof(IAssembler <TObject, TConfiguration>),
                              assemblerAttribute.AssemblerType.FullName));
            }

            assembler = (IAssembler <TObject, TConfiguration>)Activator.CreateInstance(assemblerAttribute.AssemblerType);
            lock (assemblersMappingLock)
            {
                assemblersMapping[type] = assembler;
            }

            return(assembler);
        }