Esempio n. 1
0
 public static object AutoSetCombinedKey(this ICombineKeyParser parser, object model, string key, object value)
 {
     if (model == null)
     {
         return(null);
     }
     SetProperty(model, key, value);
     return(model);
 }
Esempio n. 2
0
        public static string AutoGetCombinedKey(this ICombineKeyParser parser, object model, params string[] includeKeys)
        {
            if (model == null)
            {
                return(null);
            }

            var propertiesDic = GetGetPropertiesDic(model);

            return(parser.AutoGetCombinedKey(propertiesDic, includeKeys));
        }
Esempio n. 3
0
        public static T SetCombinedKeyByProperties <T>(this T model, ICombineKeyParser parser = null) where T : IHasCombineKey <T>
        {
            if (model == null)
            {
                return(default(T));
            }

            var includeKeyNames = model.GetIncludePropertyNames();
            var combineKeyName  = model.GetCombinedKeyName();

            return(SetCombinedKeyByProperties(model, combineKeyName, includeKeyNames, parser));
        }
Esempio n. 4
0
        public static object AutoSetCombinedKey(this ICombineKeyParser parser, object model, IDictionary <string, object> items, params string[] includeKeys)
        {
            if (model == null)
            {
                return(null);
            }
            var includedItems = SelectIncludeItems(items, includeKeys);

            foreach (var includedItem in includedItems)
            {
                SetProperty(model, includedItem.Key, includedItem.Value);
            }
            return(model);
        }
Esempio n. 5
0
        public static IDictionary <string, object> AutoSetCombinedKey(this ICombineKeyParser parser, IDictionary <string, object> model, string key, object value)
        {
            if (model == null)
            {
                return(null);
            }

            var theKey = model.Keys.SingleOrDefault(x => x.Equals(key, StringComparison.OrdinalIgnoreCase));

            if (theKey != null)
            {
                model[theKey] = value;
            }

            return(model);
        }
Esempio n. 6
0
        public static IDictionary <string, object> AutoSetCombinedKey(this ICombineKeyParser parser, IDictionary <string, object> model, IDictionary <string, object> items, params string[] includeKeys)
        {
            if (model == null)
            {
                return(null);
            }
            var includedItems = SelectIncludeItems(items, includeKeys);

            foreach (var includedItem in includedItems)
            {
                if (model.ContainsKey(includedItem.Key))
                {
                    model[includedItem.Key] = includedItem.Value;
                }
            }
            return(model);
        }
Esempio n. 7
0
        public static string AutoGetCombinedKey(this ICombineKeyParser parser, IDictionary <string, object> items, params string[] includeKeys)
        {
            var includedItems = SelectIncludeItems(items, includeKeys);

            return(parser.CreateCombinedKey(includedItems));
        }
Esempio n. 8
0
        public static T SetCombinedKeyByProperties <T>(this T model, string combinedKeyName, string[] includeKeyNames, ICombineKeyParser parser = null)
        {
            if (model == null)
            {
                return(default(T));
            }

            if (includeKeyNames == null || includeKeyNames.Length == 0)
            {
                return(model);
            }
            if (string.IsNullOrWhiteSpace(combinedKeyName))
            {
                return(model);
            }

            var combineKeyParser = parser ?? CombineKeyParser.Resolve();
            var combinedKeyValue = combineKeyParser.AutoGetCombinedKey(model, includeKeyNames);

            SetProperty(model, combinedKeyName, combinedKeyValue);
            return(model);
        }
Esempio n. 9
0
        public static T SetPropertiesByCombinedKey <T>(this T model, string combinedKeyName, string[] includeKeyNames, ICombineKeyParser parser = null)
        {
            if (model == null)
            {
                return(default(T));
            }

            if (includeKeyNames == null || includeKeyNames.Length == 0)
            {
                return(model);
            }

            if (string.IsNullOrWhiteSpace(combinedKeyName))
            {
                return(model);
            }

            var combineKeyValue = GetProperty(model, combinedKeyName);

            if (combineKeyValue == null)
            {
                return(model);
            }

            var combineKeyParser = parser ?? CombineKeyParser.Resolve();
            var includeKeys      = combineKeyParser.ParseCombinedKey(combineKeyValue.ToString());

            foreach (var includeKey in includeKeys)
            {
                SetProperty(model, includeKey.Key, includeKey.Value);
            }
            return(model);
        }