2

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"

4

1 回答 1

1

@Alan - 在 UiPath 中,访问自定义类和对象的唯一方法是通过 nuget 包。我自己没有尝试过,但理论上它应该按照以下步骤工作:

  1. 创建一个类库项目,然后创建该项目的 nuget 包
  2. 通过单击 UiPath 中的管理包将该 nuget 包导入您的项目
  3. 在 xaml 页面中导入包的命名空间
  4. 这应该使您的静态方法可用于您的活动

请尝试一下,让我知道它是怎么回事。

另一种选择是使用visual studio创建一个自定义活动,但我认为对于这样一个微不足道的问题来说这可能是一种矫枉过正

于 2020-08-24T10:11:09.247 回答