public void RegisterCompilers(IEnumerable <KeyValuePair <MemberInfo, Func <MemberInfo, T, T[], T> > > compilerDefinitions, ConflictHandlingMethod conflictHandlingMethod)
        {
            ArgumentValidator.EnsureArgumentNotNull(compilerDefinitions, "compilerDefinitions");
            this.EnsureNotLocked();

            var newItems = new MemberCompilerCollection();

            foreach (var item in compilerDefinitions)
            {
                newItems.Add(new MemberCompilerRegistration(GetCanonicalMember(item.Key), item.Value));
            }
            UpdateRegistry(newItems, conflictHandlingMethod);
        }
        public void MergeWith(MemberCompilerCollection otherSource, bool failOnDuplicate)
        {
            if (failOnDuplicate)
            {
                foreach (var key in otherSource.items.Keys)
                {
                    if (items.ContainsKey(key))
                    {
                        throw new InvalidOperationException(string.Format(
                                                                Strings.ExCompilerForXIsAlreadyRegistered, key.GetFullName(true)));
                    }
                }
            }

            foreach (var registration in otherSource.items.Values)
            {
                items[registration.TargetMember] = registration;
            }
        }
        private void UpdateRegistry(MemberCompilerCollection newItems, ConflictHandlingMethod conflictHandlingMethod)
        {
            if (newItems.Count == 0)
            {
                return;
            }
            switch (conflictHandlingMethod)
            {
            case ConflictHandlingMethod.KeepOld:
                newItems.MergeWith(compilers, false);
                compilers = newItems;
                break;

            case ConflictHandlingMethod.Overwrite:
                compilers.MergeWith(newItems, false);
                break;

            case ConflictHandlingMethod.ReportError:
                compilers.MergeWith(newItems, true);
                break;
            }
        }
        public void RegisterCompilers(Type compilerContainer, ConflictHandlingMethod conflictHandlingMethod)
        {
            ArgumentValidator.EnsureArgumentNotNull(compilerContainer, "compilerContainer");
            this.EnsureNotLocked();

            if (compilerContainer.IsGenericType)
            {
                throw new InvalidOperationException(string.Format(
                                                        Strings.ExTypeXShouldNotBeGeneric, compilerContainer.GetFullName(true)));
            }

            var compilersToRegister = new MemberCompilerCollection();

            var compilerMethods = compilerContainer
                                  .GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly)
                                  .Where(method => method.IsDefined(typeof(CompilerAttribute), false) && !method.IsGenericMethod);

            foreach (var compiler in compilerMethods)
            {
                compilersToRegister.Add(ProcessCompiler(compiler));
            }

            UpdateRegistry(compilersToRegister, conflictHandlingMethod);
        }