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 compilerMethods = compilerContainer
                                  .GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly)
                                  .Where(method => method.IsDefined(typeof(CompilerAttribute), false) && !method.IsGenericMethod);

            UpdateRegistry(compilerMethods.Select(ProcessCompiler), conflictHandlingMethod);
        }
        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;
            }
        }
Example #3
0
 /// <summary>
 ///   Initializes new instance of this type.
 /// </summary>
 /// <param name="targetType">Target type.</param>
 public CompilerContainerAttribute(Type targetType)
 {
     TargetType             = targetType;
     ConflictHandlingMethod = ConflictHandlingMethod.Default;
 }
Example #4
0
        // Constructors

        /// <summary>
        ///   Initializes new instance of this type.
        /// </summary>
        /// <param name="targetType">Target type.</param>
        /// <param name="conflictHandlingMethod">The conflict handling method.</param>
        public CompilerContainerAttribute(Type targetType, ConflictHandlingMethod conflictHandlingMethod)
        {
            TargetType             = targetType;
            ConflictHandlingMethod = conflictHandlingMethod;
        }
        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 RegisterCompilers(IEnumerable <KeyValuePair <MemberInfo, Func <MemberInfo, T, T[], T> > > compilerDefinitions, ConflictHandlingMethod conflictHandlingMethod)
        {
            ArgumentValidator.EnsureArgumentNotNull(compilerDefinitions, "compilerDefinitions");
            this.EnsureNotLocked();

            var newItems = compilerDefinitions.Select(item => (item.Key, (Delegate)item.Value));

            UpdateRegistry(newItems, conflictHandlingMethod);
        }