예제 #1
0
        internal static bool TryGetInstanceMethod(object value, string memberName, out PSMethodInfo methodInfo)
        {
            PSMemberInfoInternalCollection <PSMemberInfo> pSMemberInfos = null;
            PSMemberInfo item;

            if (PSObject.HasInstanceMembers(value, out pSMemberInfos))
            {
                item = pSMemberInfos[memberName];
            }
            else
            {
                item = null;
            }
            PSMemberInfo pSMemberInfo = item;

            methodInfo = pSMemberInfo as PSMethodInfo;
            if (pSMemberInfo != null)
            {
                if (methodInfo != null)
                {
                    return(true);
                }
                else
                {
                    object[] typeFullName = new object[2];
                    typeFullName[0] = ParserOps.GetTypeFullName(value);
                    typeFullName[1] = memberName;
                    throw InterpreterError.NewInterpreterException(memberName, typeof(RuntimeException), null, "MethodNotFound", ParserStrings.MethodNotFound, typeFullName);
                }
            }
            else
            {
                return(false);
            }
        }
예제 #2
0
        internal static object InvokeAdaptedSetMember(object obj, string methodName, object[] args, object valueToSet)
        {
            TypeTable        typeTable;
            ExecutionContext executionContextFromTLS = LocalPipeline.GetExecutionContextFromTLS();
            object           obj1 = obj;

            if (executionContextFromTLS != null)
            {
                typeTable = executionContextFromTLS.TypeTable;
            }
            else
            {
                typeTable = null;
            }
            PSObject.AdapterSet     mappedAdapter           = PSObject.GetMappedAdapter(obj1, typeTable);
            PSParameterizedProperty pSParameterizedProperty = mappedAdapter.OriginalAdapter.BaseGetMember <PSParameterizedProperty>(obj, methodName);

            if (pSParameterizedProperty == null && mappedAdapter.DotNetAdapter != null)
            {
                pSParameterizedProperty = mappedAdapter.DotNetAdapter.BaseGetMember <PSParameterizedProperty>(obj, methodName);
            }
            if (pSParameterizedProperty == null)
            {
                object[] typeFullName = new object[2];
                typeFullName[0] = ParserOps.GetTypeFullName(obj);
                typeFullName[1] = methodName;
                throw InterpreterError.NewInterpreterException(methodName, typeof(RuntimeException), null, "MethodNotFound", ParserStrings.MethodNotFound, typeFullName);
            }
            else
            {
                pSParameterizedProperty.InvokeSet(valueToSet, args);
                return(valueToSet);
            }
        }