Example #1
0
            public FixDescriptor([NotNull] FixAttribute attribute, [NotNull] IFix fix)
            {
                Assert.ArgumentNotNull(attribute, nameof(attribute));
                Assert.ArgumentNotNull(fix, nameof(fix));

                Attribute = attribute;
                Fix       = fix;
            }
Example #2
0
        public static void LoadType([NotNull] Type type, [NotNull] FixAttribute attribute)
        {
            Assert.ArgumentNotNull(type, nameof(type));
            Assert.ArgumentNotNull(attribute, nameof(attribute));

            var i = type.GetInterface(fixInterface);

            if (i == null)
            {
                return;
            }

            IFix fix;

            try
            {
                var constructorInfo = type.GetConstructor(Type.EmptyTypes);
                if (constructorInfo == null)
                {
                    return;
                }

                fix = constructorInfo.Invoke(null) as IFix;
            }
            catch
            {
                Trace.TraceError("Fix threw an exception in the constructor");
                return;
            }

            if (fix == null)
            {
                Trace.TraceError("Fix does not have a parameterless constructor");
                return;
            }

            var descriptor = new FixDescriptor(attribute, fix);

            Add(descriptor);
        }