예제 #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);
        }
예제 #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);
            }
        }