Example #1
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);
        }
Example #2
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);
        }