Dear Sir/Mam,
Please have a look in my Name class below
which is intended to Use Like Built in sealed String Class : -
public class NameField
{
readonly string _value;
public NameField(string value)
{
this._value = value;
}
public static implicit operator string(NameField d)
{
if (d._value.Length > 5) throw new System.Exception("");
return d._value;
}
public static implicit operator NameField(string d)
{
return new NameField(d);
}
}
now we can set values like:-
NameField myName="Sanjeeb Kumar Chaudhary"
Now I want to Show Conditional Compile Time error like below:-
- if string length is greater than 10 then "can not be greater than 10 characters "
- if string length is less than 5 then "can not be less than 5 characters "
- and much more as per requirements ....
Thus, kindly suggest how to do so ?
Sanjeeb KumarPosted Dec 30, 2021, 3:01 AM
Dear Sai Sir,
preprocessors type error is required as you suggested.
We need like followings :-
[nvarchar(100),MinLength(5),MaxLength(100)]
public NameField StudentName{get;set;}
[nvarchar(200),MaxLength(200)]
public AddressField StudentAddress{get;set;}
[int,MinValue(20),MaxValue(50)]
public AgeField StudentAge{get;set;}
and so on so on ...
so that if any values not valid even when setting:-
1. in any precompiled, compile and runtime like NameField="Hi"
should highlight an error in precompile and through error when compiling....
because it's length is less than 5 which is defined when declaration.
2. it should also work with ef-core field creation as well as with validations.
can you please help us doing so ?
Regards-
Sanjeeb
Sai Kumar KoonaPosted Dec 29, 2021, 8:48 AM