The Dink Network

toof's Profile

duck.gif
toof
Peasant He/Him
I disagree. 
My biography is classified, 'cause it's classy.

Web Page http://toof17.github.io/toofweb/
Private Message

2019-02-14 17:02:57
duck.gif
toof
Peasant He/Him
I disagree. 
Just a reminder, not that important, don't bang your heads too hard

I'll keep it simple, then build on (ignore potential issues). Suppose you have a class Human with two properties:
class Human
{
  public string Name {get; set;}
  public int Age {get; set;}
}

When I instantiate that class, I wanna do it by using lambda expression that will set parameters to call certain functions within that class, which determine whether the input (set) is acceptable or not... Phew

Again, keeping it simple, let's say that if someone wanna set Human's age to 137, he can't do that because there's a limit. I'm aware that the class has no implementation for that yet.
So the constructor should look like this:
var human = new Human(cfg =>
  cfg.Age.MaximumAge = 70,
  cfg.Age.MinimumAge = 0
);


The values of minimum and maximum age can be a field, or properties of a nested class within Human.

If I also wanna be able to implement some restrictions to Name property, I'll add a function that will be called when setting the Name property. Some regular expression that will filter out strings containing characters or numbers. Don't worry about the function itself, just how to get this lambda to work.

var human = new Human(cfg =>
  cfg.Age.MaximimumAge = 70,
  cfg.Age.MinimumAge = 0,
  cfg.Name.ContainSymbols = false,
  cfg.Name.ContainNumbers = true
);


Use nested classes, delegates, whatever... If this has no solution, the other thing I'll accept as a replacement is some class, say... Factory. So you can pass any generic class to it, and do the same as above.

var crap = new Factory<Human> (cfg =>
  cfg.Name.ContainSymbols = false
  // etc
);


I know this post is a bit messy. If anything remained unclear, ask... Bottom line, make a class where restrictions on property values are defined in a constructor, via lambda expression...

toof has released 3 files

TitleCategoryAvgUpdated
Dink Hotel (The)D-Mod, RompGood 7.1April 2nd, 2019
Golden DuckD-Mod, RompGood 8.7October 4th, 2018
DinkC Syntax Highlighting for Notepad++ DarkDevelopment, UtilityN/AJuly 18th, 2018

toof has written 2 reviews

TitleFileTypeScoreDate
In a gadda da Brassweasel... Search (The)NormalGood 8.3October 1st, 2018
The good, the bad, and the this review The DiscipleFeaturedExceptional 9.2September 18th, 2017