0

I'm using codeeffect for my business rule engine. I have a user class with manager property with user type.

public class BasicUser
{
public int ID { get; set; }
public string Name { get; set; }
public BasicUser Manager { get; set; }
}

In the business rule engine currently showing User.Manager.Manager.Manage.Manager.ID But I would like to show only 2 levels like User.Manager.Manager.ID

Is there any attribute I can use?

Fereshteh Rabet
  • 191
  • 2
  • 18

1 Answers1

0

You can use the ParentAttribute to set display names of your User class. Details can be found here.

UPDATED: You can also use the SourceAttribute.MaxTypeNestingLevel property to control the number of hierarchy levels of your source object and all reference types it declares. Details are here. Use the ExcludeFromEvaluationAttribute class to remove any source member from the editor and, consequently, from evaluation. Its documentation is here

UPDATE 2: Consider the following two classes:

public class Address
{
    public Address() { }

    public string Street { get; set; }
    public Address InnerAddress { get; set; }
}

[Source(MaxTypeNestingLevel = 1)]
public class Patient
{
    public Patient() { }

    public string Name { get; set; }
    public Address InnerAddress { get; set; }
}

If I give the Patient class to the rule editor as its source and set the value of the nested levels to 1 or less I get the following menu options:

(
Name

I.e the editor ignores all reference types in the source because the level is 1.

If I give it level 2 I see the following options in the menu:

(
InnerAddress.Street
Name

The editor shows the InnerAddress instance (level one) with its Street property (level 2).

And if I set the level to 4 I get these options:

(
InnerAddress.InnerAddress.InnerAddress.Street
InnerAddress.InnerAddress.Street
InnerAddress.Street
Name

Obviously, options are shown up to the level 4 now. All this options are tested on one of Code Effects demo projects.

Alex
  • 566
  • 1
  • 6
  • 14
  • I don't want to change the display name of my property! – Fereshteh Rabet Aug 13 '19 at 13:17
  • @FereshtehRabet Code Effects' rule editor can only work with the actual structure of your class. It cannot change it on its own without you instructing it how to do that. That's what the ParentAttribute is for. You don't have to rename your properties, just give them the "shorter" names that satisfy your requirements, that's all. – Alex Aug 13 '19 at 15:51
  • I would like to exclude/hide a property after showing it more than 3 levels. for example, I would like to have User.Manager.ID and User.Manager.Manager.ID and hide it if User.Manager.Manager.Manager.ID and User.Manager.Manager.Manager.Manager.ID. I'm not sure how that Parent attribute can help me – Fereshteh Rabet Aug 13 '19 at 16:09
  • @FereshtehRabet I updated my answer. Sorry, seems like I misunderstood your original question. – Alex Aug 13 '19 at 18:01
  • Thanks, @Alex, but I tried that and it didn't help me – Fereshteh Rabet Aug 15 '19 at 15:42
  • I added [Source(MaxTypeNestingLevel = 2)] on top of my class but still showing 4 level – Fereshteh Rabet Aug 15 '19 at 20:56
  • @FereshtehRabet I updated my answer with code samples. Let me know if you need a working copy of this code example in a form of Code Effects demo project. – Alex Aug 16 '19 at 08:25