Beispiel #1
0
        // централизованная проверка на пустые свойства (в ошибках показывать имена по русски..)
        protected override void CacheMetadata(CodeActivityMetadata metadata)
        {
            const string s = "Свойство {0} не может быть пустым";

            Type t = this.GetType();

            PropertyInfo[] pia = t.GetProperties();
            foreach (PropertyInfo pi in pia)
            {
                RequiredArgumentAttribute reqAttr = (RequiredArgumentAttribute)pi.GetCustomAttributes(typeof(RequiredArgumentAttribute), false).FirstOrDefault();
                if (reqAttr == null)
                {
                    continue;
                }
                object o = pi.GetValue(this, null);
                if (o != null)
                {
                    continue;
                }
                DisplayNameAttribute dNameAttr = (DisplayNameAttribute)pi.GetCustomAttributes(typeof(DisplayNameAttribute), false).FirstOrDefault();
                if (dNameAttr == null)
                {
                    continue;
                }
                string atrName = "'" + dNameAttr.DisplayName + "'";
                metadata.AddValidationError(string.Format(s, atrName));
            }
            base.CacheMetadata(metadata);
        }
Beispiel #2
0
        /// <summary>
        /// How many required properties are defined in this class?
        /// Use the [RequiredArgument] attribute to determine this.
        /// </summary>
        /// <returns>The count of the required properties</returns>
        private int GetRequiredPropertiesCount()
        {
            Attribute att   = new RequiredArgumentAttribute();
            var       count = this.
                              GetType().
                              GetProperties().
                              Where(x => x.GetCustomAttributes(att.GetType(), true).Any()).Count();

            return(count);
        }
Beispiel #3
0
        /// <summary>
        /// Check to see if a property has been tagged with the
        /// [RequiredArgument] attribute
        /// </summary>
        /// <param name="option">The CommandLineOption to inspect</param>
        /// <returns>true : Property is marked with attribute, false : not marked with attribute</returns>
        private bool IsPropertyMarkedAsRequired(dynamic option)
        {
            var att = new RequiredArgumentAttribute();
            var propertiesMarkedAsRequired = this.
                                             GetType().
                                             GetProperties().
                                             Where(x => x.GetCustomAttributes(att.GetType(), true).Any());

            foreach (var propertyInfo in propertiesMarkedAsRequired)
            {
                dynamic valueSet = propertyInfo.GetValue(this, null);
                if (valueSet != null)
                {
                    if (option.Name == valueSet.Name)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #4
0
        public void Register()
        {
            var builder = new AttributeTableBuilder();

            var imageHelpersCategoryAttribute = new CategoryAttribute("Community.ImageHelpers");
            var inputCategoryAttribute        = new CategoryAttribute("Input");
            var outputCategoryAttribute       = new CategoryAttribute("Output");
            var requiredArgumentAttribute     = new RequiredArgumentAttribute();
            var skipBordersCategoryAttribute  = new CategoryAttribute("SkipBorders");

            #region ChangeColorOnImageAttributes
            var changeColorOnImageType = typeof(ChangeColorOnImage);

            #region Categories
            builder.AddCustomAttributes(changeColorOnImageType, imageHelpersCategoryAttribute);

            builder.AddCustomAttributes(changeColorOnImageType, "ImageToConvert", inputCategoryAttribute);
            builder.AddCustomAttributes(changeColorOnImageType, "ColorToChange", inputCategoryAttribute);
            builder.AddCustomAttributes(changeColorOnImageType, "ColorToSet", inputCategoryAttribute);

            builder.AddCustomAttributes(changeColorOnImageType, "SkipPixelsFromLeft", skipBordersCategoryAttribute);
            builder.AddCustomAttributes(changeColorOnImageType, "SkipPixelsFromTop", skipBordersCategoryAttribute);
            builder.AddCustomAttributes(changeColorOnImageType, "SkipPixelsFromRight", skipBordersCategoryAttribute);
            builder.AddCustomAttributes(changeColorOnImageType, "SkipPixelsFromBottom", skipBordersCategoryAttribute);

            builder.AddCustomAttributes(changeColorOnImageType, "ChangedImage", outputCategoryAttribute);
            #endregion

            #region RequiredArguments
            builder.AddCustomAttributes(changeColorOnImageType, "ImageToConvert", requiredArgumentAttribute);
            builder.AddCustomAttributes(changeColorOnImageType, "ColorToChange", requiredArgumentAttribute);
            builder.AddCustomAttributes(changeColorOnImageType, "ColorToSet", requiredArgumentAttribute);
            builder.AddCustomAttributes(changeColorOnImageType, "ChangedImage", requiredArgumentAttribute);
            #endregion

            #region ArgumentDescriptions
            builder.AddCustomAttributes(changeColorOnImageType, "ImageToConvert", new DescriptionAttribute("Original image object to change color from."));
            builder.AddCustomAttributes(changeColorOnImageType, "ColorToChange", new DescriptionAttribute("System.Drawing.Color describing color range to change."));
            builder.AddCustomAttributes(changeColorOnImageType, "ColorToSet", new DescriptionAttribute("System.Drawing.Color describing color to set instead of ColorToChange."));
            builder.AddCustomAttributes(changeColorOnImageType, "ChangedImage", new DescriptionAttribute("New System.Drawing.Image generated from ImageToConvert."));
            #endregion
            #endregion

            #region GetColorsFromImage
            var getColorsFromImageType = typeof(GetColorsFromImage);

            #region Categories
            builder.AddCustomAttributes(getColorsFromImageType, imageHelpersCategoryAttribute);

            builder.AddCustomAttributes(getColorsFromImageType, "ImageToCheck", inputCategoryAttribute);

            builder.AddCustomAttributes(getColorsFromImageType, "SkipPixelsFromLeft", skipBordersCategoryAttribute);
            builder.AddCustomAttributes(getColorsFromImageType, "SkipPixelsFromTop", skipBordersCategoryAttribute);
            builder.AddCustomAttributes(getColorsFromImageType, "SkipPixelsFromRight", skipBordersCategoryAttribute);
            builder.AddCustomAttributes(getColorsFromImageType, "SkipPixelsFromBottom", skipBordersCategoryAttribute);

            builder.AddCustomAttributes(getColorsFromImageType, "ColorsInImage", outputCategoryAttribute);
            #endregion

            #region RequiredArguments
            builder.AddCustomAttributes(getColorsFromImageType, "ImageToCheck", requiredArgumentAttribute);
            builder.AddCustomAttributes(getColorsFromImageType, "ColorsInImage", requiredArgumentAttribute);
            #endregion

            #region ArgumentDescriptions
            builder.AddCustomAttributes(getColorsFromImageType, "ImageToCheck", new DescriptionAttribute("Image to get colors from."));
            builder.AddCustomAttributes(getColorsFromImageType, "ColorsInImage", new DescriptionAttribute("Sorted list of Colors, keyed by percentage of image covered. By default sorted ascending, use .Reverse to get from most common Color first."));
            #endregion
            #endregion

            MetadataStore.AddAttributeTable(builder.CreateTable());
        }