VAF.Extensions.Community icon indicating copy to clipboard operation
VAF.Extensions.Community copied to clipboard

Expose a method to Extract the property ids of a placeholder

Open GuillaumeZanini opened this issue 4 years ago • 4 comments

In the ExpandSimpleConcatenation.cs a regex (ExtractPlaceholders) is used to extract property ids (and other stuff) from a configuration placeholder (using ids, aliases or guids etc...) then a function : ToPropertyIds is used to get the collection of these Ids and the to get the corresponding values of the object. It could be great to have an exposed method to get these property ids (list or array) from a placeholder. e.g. In order to react to a change of one of these properties.

GuillaumeZanini avatar Apr 21 '21 07:04 GuillaumeZanini

The current internal ExpandSimpleConcatenation method uses ToPropertyIds to retrieve an array of property IDs for each match. ToPropertyIds takes a single match and returns the property ID "path" to iterate over to retrieve the value. This is potentially called multiple times by ExpandSimpleConcatenation, once for each "grouping" (between %% characters). For example:

  • The input string "%PROPERTY_1078.PROPERTY_1094%" would end up calling ToPropertyIds once, with that call returning an array with two items (1078, 1094).
  • The input string "%PROPERTY_1078% %PROPERTY_1094%" would end up calling ToPropertyIds twice, with the first call (for the first group) returning a single value for 1078 and the second call (for the second group) returning a single value for 1094.

In the case of your requirements, what would you expect to pass into this method and what would you expect to get back?

CraigHawker avatar Apr 27 '21 08:04 CraigHawker

The input is a placeholder object from configuration.cs (with id, alias or guid style) like this [DataMember] [JsonConfEditor(TypeEditor = "placeholderText")] public string InputPlaceholderCriteria; It give a thing like that %PROPERTY_1234.PROPERTY_{PD.Projet}.PROPERTY_{7792C958-7DF6-4A63-BA57-437F7B5A6E82}%

The function you develop create a matchcollection using regex with different "type" like "objecttypeid", "property", "objecturl_web".... and in each of these case it return a value or a list.

So if the placeholder is a "property placeholder" as in my example the goal is to have an output like this [1234,1352,1406] which are the ids of the related properties choosen in the configuration placeholder.

GuillaumeZanini avatar Jun 02 '21 09:06 GuillaumeZanini

The current (internal) method ToPropertyIds does exactly this, although it operates on a regex group rather than a simple string. Potentially this could be exposed.

I don't think that it makes sense for the method to be able to handle strings that don't evaluate (exactly) to one "property path". By that I mean the string %PROPERTY_1234% %PROPERTY_5678% should throw an exception, as there are two paths. Similarly, paths that do not evaluate to properties (e.g. %OBJID%) should also throw an exception. Do you agree?

CraigHawker avatar Sep 03 '21 07:09 CraigHawker

Yes you're right, especially since in a configuration placeholder used to get the content of a property information, usually the user do not use separated properties but often "chained" properties.

GuillaumeZanini avatar Sep 23 '21 07:09 GuillaumeZanini