Beispiel #1
0
        /// <summary>
        /// Constructs a cleanser by generic type
        /// </summary>
        /// <returns></returns>
        public static Cleanser Construct(CleanserIDs id, string itemToCleanse)
        {
            Type            cleanserType = null;
            CleanserFactory factory      = new CleanserFactory();
            Cleanser        returnValue;

            cleanserType = factory.Cleansers[id];
            returnValue  = (Cleanser)Activator.CreateInstance(cleanserType);
            returnValue.TextToCleanse = itemToCleanse;

            return(returnValue);
        }
Beispiel #2
0
        /// <summary>
        /// Cleanses all properties marked with CleanseFor attribute
        /// </summary>
        /// <param name="classToCleanse"></param>
        public static void CleanseAll(object classToCleanse)
        {
            // Get properties with CleanseFor() attribute
            IEnumerable <PropertyInfo> props = classToCleanse.GetPropertiesByAttribute(typeof(CleanseFor));

            foreach (var item in props)
            {
                var      ValueToSet     = item.GetValue(classToCleanse, null).ToStringSafe();
                Cleanser cleanserWorker = CleanserFactory.Construct(item.GetAttributeValue <CleanseFor, CleanserIDs>(CleanserIDs.Default), ValueToSet);
                ValueToSet = cleanserWorker.Cleanse();
                item.SetValue(classToCleanse, ValueToSet);
            }
        }