2
votes

I have a c# class that is extending types as follows:

public static class TypeExtensions
{
    public static String nameof<TType, TMember>(this TType obj, Expression<Func<TType, TMember>> propertyAccessor)
    {
        if (propertyAccessor.Body.NodeType == ExpressionType.MemberAccess)
        {
            var memberExpression = propertyAccessor.Body as MemberExpression;
            if (memberExpression == null)
                return null;
            return memberExpression.Member.Name;
        }
        return null;
    }
}

In C# i would generally access the method like this:

obj.nameof(o => o.PropertyXY)

However, in UiPath Studio I’m not able to extend it. Here's what I've tried

obj.[nameof](Function(o) o.PropertyXY)

I've made sure the namespace is imported correctly.

Am I doing something wrong or is there any known limitation of extending Types in UiPath?

Thanks in advance. Alan

EDIT After properly cleaning the VisualStudio Library-Project (by removing the bin/obj folders) and rebuild, I'm now at least able to see the extension method listed in Intellisense. However, when calling it UiPath complains: "Operation is not valid due to the current state of the object"

1

1 Answers

1
votes

@Alan - In UiPath the only way to access your custom class and objects are via nuget package. I haven't tried this myself but in theory it should work with following steps:

  1. Create a class library project and then create nuget package of that project
  2. Import that nuget package to your project by clikcing managing packages in the UiPath
  3. In the xaml page import the namespace of your package
  4. This should make your static method available to your activity

Please try it and let me know how it goes.

Another option is to create a custom activity using visual studio but I think that can be a overkill for such a trivial problem