コード例 #1
0
        public T Scramble <T>(T objectToScramble, ScrambleMap scrambleMap)
        {
            var props = objectToScramble.GetType().GetProperties();

            ScrambleObjectProperties(objectToScramble, props, scrambleMap);

            return(objectToScramble);
        }
コード例 #2
0
        public T Scramble <T>(T objectToScramble, Action <ScrambleMap> scrambleMapConfigurator)
        {
            var props       = objectToScramble.GetType().GetProperties();
            var scrambleMap = new ScrambleMap();

            scrambleMapConfigurator?.Invoke(scrambleMap);

            ScrambleObjectProperties(objectToScramble, props, scrambleMap);

            return(objectToScramble);
        }
コード例 #3
0
        public IEnumerable <T> ScrambleEnumerable <T>(IEnumerable <T> collectionToScramble, Action <ScrambleMap> scrambleMapConfigurator)
        {
            var scrambleMap = new ScrambleMap();

            scrambleMapConfigurator?.Invoke(scrambleMap);

            foreach (var objectToScramble in collectionToScramble)
            {
                Scramble(objectToScramble, scrambleMap);
            }

            return(collectionToScramble);
        }
コード例 #4
0
 public void RegisterMap(string key, ScrambleMap map)
 {
     RegisteredMaps[key] = map;
 }
コード例 #5
0
        public IEnumerable <T> ScrambleEnumerable <T>(IEnumerable <T> collectionToScramble, ScrambleMap scrambleMap)
        {
            foreach (var objectToScramble in collectionToScramble)
            {
                Scramble(objectToScramble, scrambleMap);
            }

            return(collectionToScramble);
        }
コード例 #6
0
        private void UnscrambleObjectProperties <T>(T objectToUnscramble, PropertyInfo[] props, ScrambleMap scrambleMap)
        {
            foreach (var prop in props)
            {
                var replaceCondition = scrambleMap.FindReplaceCondition(prop.Name);

                if (replaceCondition?.ReplaceValue.Equals(prop.GetValue(objectToUnscramble)) ?? false)
                {
                    prop.SetValue(objectToUnscramble, replaceCondition.ConditonValue);
                }
                else if (scrambleMap.HasCustomScrambler(prop.PropertyType))
                {
                    var customeScrambler = scrambleMap.GetCustomScrambler(prop.PropertyType);
                    customeScrambler.UnscrambleValue(objectToUnscramble, prop);
                }
            }
        }
コード例 #7
0
        private void ScrambleObjectProperties <T>(T objectToScramble, PropertyInfo[] props, ScrambleMap scrambleMap)
        {
            for (int i = 0; i < props.Length; i++)
            {
                var replaceCondition = scrambleMap.FindReplaceCondition(props[i].Name);

                if (replaceCondition?.ConditonValue.Equals(props[i].GetValue(objectToScramble)) ?? false)
                {
                    props[i].SetValue(objectToScramble, replaceCondition.ReplaceValue);
                }
                else if (scrambleMap.HasCustomScrambler(props[i].PropertyType))
                {
                    var customScrambler = scrambleMap.GetCustomScrambler(props[i].PropertyType);
                    customScrambler.ScrambleValue(objectToScramble, props[i]);
                }
            }
        }