Hello gurus,
First, I am resubmitting this question because of a misunderstanding I had about the Code Project sign-in. My apologies for any confusion this may cause.
In a
previous post I had a problem which was neatly solved using partial function applications. Now I have a problem, not with the coding of the solution, but with trying to understand the syntax of the solution.
Background:
I have defined a set of Funcs which I use to validate data. An example is
Func<int, Func<object, string>> MaxLen => max => value => CheckLength(value, max);
which I use in a Dictionary that defines rules for various data fields in a file:
_rules = new FileRules()
{
{ "FH03", new FieldRules() { AlphaNumeric, MaxLen(10), ... } },
{ "FH04", new FieldRules() { AlphaNumeric, MaxLen(30), ... } },
...
};
I use it like this
object validated = stuffToOutput;
try
{
foreach (var rule in _rules[fieldId])
{
validated = rule(validated);
}
}
catch (Exception ex) { ... }
This allows me to pass in the data for field FH03 and have it checked to see that it is alphanumeric and has a maximum length of 10 characters, etc. This code works wonderfully, and I understand how it works. My problem is that I am struggling to express to others how it works. In particular, the proper terminology to use to describe definition of the partial function application in the syntax I am using.
Problem:
This page indicates that lambda expressions are interpreted as parameters on the left of the => and expression on the right. With that
value => CheckLength(value, max)
is easily explained as a lambda that takes a parameter called
value and returns the result of
CheckLength(value, max).
max => value => CheckLength(value, max)
is explained as a lambda that takes a parameter called
max and returns the result of the lamb
da on the right.
But then I get to
Func<int, Func<object, string>> MaxLen => max => value => CheckLength(value, max)
In the lexicon of C#, what is
MaxLen?
It is not a
parameter - its usage in the first code block (where the dictionary entries are defined) is inconsistent with it being a parameter.
I thought it would make sense to say it is the name of a
named delegate, but it does not match the syntactic signature of any delegate types shown on
this MS page. All of those examples show
Delegate delegatename = delegatedefinition;
There is no
= in the syntax I am using.
Even
this reference, which shows the Action delegate type used with a lambda expression as the definition, uses the syntax
Action delegatename = parms => lambda-expression;
Is
MaxLen a
Func? Again
this entry shows that Funcs are also expressed with equal signs
Func funcname = parms => lambda-expression;
Again, no equal sign in mine.
So, how would I word what
MaxLen is? What is the proper terminology to describe it?
What I have tried:
Racking my brain
Scouring MS sites for terminology