c# class library required

I have below codes and working ok. But I want to make firstname REQUIRED,
so when my jr developer does not code l.firstname = "Sam", it will alert him.
Is it possible?
lead.cs
    public class Lead
    {
        public string subject { get; set; }
        public DateTime createdon { get; set; }
        public string fullname { get; set; }
        public string emailaddress1 { get; set; }
        public string firstname { get; set; }
        public string lastname { get; set; }
        public string telephone1 { get; set; }
        public string address1_name { get; set; }
        public string address1_city { get; set; }
        public string address1_stateorprovince { get; set; }
        public string address1_postalcode { get; set; }
        public string companyname { get; set; }
        public decimal revenue { get; set; }
        public DateTime new_primarydob { get; set; }
        public int leadsourcecode { get; set; } //optionset
        public int leadqualitycode { get; set; }
        public string websiteurl { get; set; }
    }

aspx.cs
	    Domain.Lead l = new Domain.Lead();
            l.subject = "Test";
            l.firstname = "Sam112323";
            l.lastname = "Yu";
            l.leadsourcecode = 8;
            l.leadqualitycode = 2;
            l.createdon = DateTime.Now;

            CRM.Service ser = new CRM.Service();
            string x = ser.CreateLead(l);
            Response.Write(x);

Open in new window

LVL 1
ITsolutionWizardAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
If some piece of data is required by a class, then that piece of information should be passed via the constructor. That is the only way to enforce (at compile time) that the data is required.
0
Nitin SontakkeDeveloperCommented:
In addition, needless to mention,  make default parameter-less constructor private.
0
AndyAinscowFreelance programmer / ConsultantCommented:
ps.  A class library (see question title) is something totally different.
0
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

ste5anSenior DeveloperCommented:
Well, as it looks like a DTO in DAL/repository scenario, e.g.

namespace Dto
{
    public interface IDataTransferObject
    {
        bool IsValid(out string validationMessages);
        string Serialize();
    }

    public class Lead : IDataTransferObject
    {
        public string FirstName { get; set; }

        public string FullName
        {
            get
            {
                return this.FirstName + " " + this.LastName;
            }
        }

        public string LastName { get; set; }

        public bool IsValid(out string validationMessages)
        {
            bool result = true;
            if (string.IsNullOrEmpty(this.FirstName))
            {
                result = false;
                validationMessages += "FirstName must be set.";
            }
            else if ( string.IsNullOrEmpty(this.FirstName.Trim()))
            {
                result = false;
                validationMessages += "FirstName must be set.";
            }

            if (string.IsNullOrEmpty(this.LastName))
            {
                result = false;
                validationMessages += "LastName must be set.";
            }
            else if ( string.IsNullOrEmpty(this.LastName.Trim()))
            {
                result = false;
                validationMessages += "LastName must be set.";
            }

            // etc.
            return result;
        }

        public string Serialize()
        {
            return "your serialized DTO."
        }
    }
}

Open in new window


with
Lead l = new Lead();
l.subject = "Test";
l.firstname = "Sam112323";
l.lastname = "Yu";
l.leadsourcecode = 8;
l.leadqualitycode = 2;
l.createdon = DateTime.Now;
string validationMessages;
if (l.IsValid(out validationMessages))
{
	Response.Write(l.Serialize());
}
else
{
  // show messages.
}

Open in new window


btw, stick to coding guidelines, like consistent naming. Also how can fullname have a public setter in your sample?

p.s. or consider using contracts.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ITsolutionWizardAuthor Commented:
sorry, i do not get it. please use my example if possible.
0
ste5anSenior DeveloperCommented:
Did you create an ER-diagram? Can you post it?
0
ITsolutionWizardAuthor Commented:
No
0
ste5anSenior DeveloperCommented:
Oops. Wrong thread... ;)

sorry, i do not get it. please use my example if possible.
I did. I just removed the unnecessary fields for a shorter sample.

 Did you test it?
0
käµfm³d 👽Commented:
@ste5an

Bit of a skewed distribution, don't you think?
0
ste5anSenior DeveloperCommented:
LoC and its more in the spirit of class library.. scnr.

hmm, how to change this?
0
ste5anSenior DeveloperCommented:
All are possible approaches to the given problem.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.