Exemple #1
0
        public static V GetValue <V>(this object self, string key, BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
        {
            if (self == null)
            {
                throw new ArgumentNullException(nameof(self));
            }

            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentNullException(nameof(key));
            }

            var(memberInfo, instance) = BuilderHelper.GetMemberInfo(self, key, bindingFlags);
            return(memberInfo.GetValue <V>(instance));
        }
Exemple #2
0
        public static T SetValue <T>(this T self, string key, object value, bool autoCast = false, BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) where T : class
        {
            if (self == null)
            {
                throw new ArgumentNullException(nameof(self));
            }

            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentNullException(nameof(key));
            }

            var(memberInfo, instance) = BuilderHelper.GetMemberInfo(self, key, bindingFlags);
            memberInfo.SetValue(instance, value);
            return(self);
        }