How to use Functions in coded workflow that returns void?

Hi everyone!

I create a Source Code file, and describe in it two classes: Car and Person.
Here full code:

using System;
using System.Collections.Generic;

namespace LetsTest
{
    public class SourceFile
    {

    }

    public class Car
    {
        public string Make { get; private set; }
        public string Model { get; private set; }
        public int Year { get; private set; }

        public Car(string make, string model, int year)
        {
            Make = make;
            Model = model;
            Year = year;
        }

        public void DisplayInfo()
        {
            Console.WriteLine($"Car: {Year} {Make} {Model}");
        }
    }
    
    public class Person
    {
        public string FirstName { get; private set; }
        public string LastName { get; private set; }
        public int Age { get; private set; }
        public List<Car> Cars { get; private set; }

        public Person(string firstName, string lastName, int age)
        {
            FirstName = firstName;
            LastName = lastName;
            Age = age;
            Cars = new List<Car>();
        }

        public void BuyCar(Car car)
        {
            Cars.Add(car);
        }

        public void DisplayInfo()
        {
            Console.WriteLine($"Person: {FirstName} {LastName}, Age: {Age}");
            Console.WriteLine("Cars owned:");
            foreach (var car in Cars)
            {
                car.DisplayInfo();
            }
        }
    }
}

I can create in low-code workflow two assigns and describe objects car and person, but how can I execute person.BuyCar(car) function?
It’s NOT a static function, so I can’t use Invoke Method. Are there any solutions?
Unfortunately, I don’t know any low-code activities that can execute void functions.

TIA

Invoke method can also execute instance methods

1 Like

Huh, it was really quick :slight_smile:
Thank you!

For me, it’s little not straight-forward that to Invoke Method activity TargetType for void should be null.

For future visitors, here how I do in Invoke Method:

For BuyCar function also in Invoke Method I added to Parameters my car object:

Cheers!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.