TryGetMember() private method

private TryGetMember ( GetMemberBinder binder, object &result ) : bool
binder GetMemberBinder
result object
return bool
示例#1
0
        /// <summary>
        /// simple helper extension method that allows a get from a named property, determined at runtime by interrogating the member names.
        /// </summary>
        /// <param name="dyn"></param>
        /// <param name="memberName"></param>
        /// <returns></returns>
        public static object GetValue(this DynamicObject dyn, string memberName)
        {
            var    pd = new ProxyGetMemberBinder(memberName, true);
            object result;

            if (dyn.TryGetMember(pd, out result))
            {
                return(result);
            }
            return(null);
        }
        /// <summary>
        /// 获取动态类型的值
        /// </summary>
        /// <param name="dynamicObject">实例</param>
        /// <param name="key">键名</param>
        /// <param name="value">值</param>
        /// <returns></returns>
        private bool TryGetValue(DynamicObject dynamicObject, string key, out object value)
        {
            var keys = dynamicObject.GetDynamicMemberNames();
            key = keys.FirstOrDefault(item => string.Equals(item, key, StringComparison.OrdinalIgnoreCase));

            if (key != null)
            {
                return dynamicObject.TryGetMember(new KeyBinder(key, false), out value);
            }

            value = null;
            return false;
        }
        public static DynamicViewModel Create(DynamicObject entity)
        {
            var result = new DynamicViewModel();

            foreach (var memberName in entity.GetDynamicMemberNames())
            {
                object value;
                if (entity.TryGetMember(new GetBinder(memberName, false), out value))
                {
                    result.Set(memberName, value);
                }
            }

            return result;
        }
 private object GetPropValue(DynamicObject item, string propName)
 {
     try
     {
         object obj2;
         item.TryGetMember(new MyGetMemberBinder(propName, false), out obj2);
         return obj2;
     }
     catch (Exception innerException)
     {
         if ((innerException is TargetInvocationException) && (innerException.InnerException != null))
         {
             innerException = innerException.InnerException;
         }
         return innerException;
     }
 }
示例#5
0
文件: Grid.cs 项目: xzc3ss/Zaza
 internal static bool TryGetDynamicMember(DynamicObject o, string name, out object result)
 {
     return o.TryGetMember(new Binder(name, true), out result);
 }