コード例 #1
0
        /// <summary>
        /// Tries the get member internal.
        /// </summary>
        /// <param name="binder">The binder.</param>
        /// <param name="memberName">Name of the member.</param>
        /// <param name="result">The result.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        private bool TryGetMemberInternal(DynamicMetaObjectBinder binder, string memberName, out object?result)
        {
            var objectType = this.Type;
            // Try and get a member associated with this object
            var member = ReflectionCache.GetMember(objectType, memberName, this.UseCache);

            if (member is not null)
            {
                var value = member.GetValue(this.Obj);
                result = value is not null
                    ? new DynamicObjectAccessor(value, this.UseCache)
                    : null;
                return(true);
            }

            // Try and get a method associated with this object
            var hasMethod = ReflectionCache.HasMethod(objectType, memberName, this.UseCache);

            if (hasMethod)
            {
                result = new DynamicMethodAccessor(this.Obj, memberName, this.UseCache);
                return(true);
            }

            // Nothing found, fail
            result = null;
            return(false);
        }
コード例 #2
0
        /// <summary>
        /// Tries the invoke member.
        /// </summary>
        /// <param name="binder">The binder.</param>
        /// <param name="args">The arguments.</param>
        /// <param name="result">The result.</param>
        /// <returns>bool.</returns>
        public override bool TryInvokeMember(InvokeMemberBinder binder, object?[]?args, out object?result)
        {
            var typeArgs       = binder.GetGenericTypeParameters();
            var methodAccessor = new DynamicMethodAccessor(this.Obj, binder.Name, this.UseCache);

            return(methodAccessor.TryInvokeInternal(args, typeArgs, out result));
        }