toof's Profile
My biography is classified, 'cause it's classy.
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:
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:
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.
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.
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...
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
Title | Category | Avg | Updated |
---|---|---|---|
Dink Hotel (The) | D-Mod, Romp | 7.1 | April 2nd, 2019 |
Golden Duck | D-Mod, Romp | 8.7 | October 4th, 2018 |
DinkC Syntax Highlighting for Notepad++ Dark | Development, Utility | N/A | July 18th, 2018 |
toof has written 2 reviews
Title | File | Type | Score | Date |
---|---|---|---|---|
In a gadda da Brassweasel... | Search (The) | Normal | 8.3 | October 1st, 2018 |
The good, the bad, and the this review | The Disciple | Featured | 9.2 | September 18th, 2017 |