Пример #1
0
        protected override void ProcessRecord()
        {
            Type objectType = Type;

            if (objectType == null)
            {
                if (Object is PSObject pSObject)
                {
                    objectType = pSObject.BaseObject?.GetType();
                }
                else
                {
                    objectType = Object?.GetType();
                }
            }

            if (objectType == null)
            {
                throw new ArgumentException("Cannot determine object type", nameof(Type));
            }
            if (string.IsNullOrWhiteSpace(MethodName))
            {
                throw new ArgumentException("Method name is not provided", nameof(MethodName));
            }
            if ((GenericTypes?.Length ?? 0) <= 0)
            {
                throw new ArgumentException("Generic types are not provided", nameof(GenericTypes));
            }

            object[] args = null;
            if (Arguments?.Length > 0)
            {
                args = new object[Arguments.Length];
                for (int i = 0; i < args.Length; i++)
                {
                    var arg = Arguments[i];
                    if (arg is PSObject psArg)
                    {
                        arg = psArg.BaseObject;
                    }
                    args[i] = arg;
                }
            }

            var result = SCHost.DoInvokeGenericMethod(objectType, Object, MethodName, GenericTypes, args, MethodIndex);

            WriteObject(result);
        }