Hi everyone,
I have an assignment, but I don't fully understand what is asked here. I would be glad if you help.
//handicap ;
// It's made to work only on the Person object. Salary will need to duplicate the code to do the same.
// It is decided whether there is an error in the return, whether the string content is full or not.
//Expectation :
//This code is operable for any desired object (all objects).
//Determine whether the return operation was successful or not, and only if the return was unsuccessful, then the content is displayed.
// This is how you edit the code. (Type : Reflection, Attributes, CustomAttributes,)
static void Main(string[] args)
{
Person person = new Person();
var result = person.PropertyNullorEmptyCheck();
if (result != "") Console.WriteLine(result);
//Salary salary = new Salary();
//result = salary.PropertyNullorEmptyCheck();
//if (result != "") Console.WriteLine(result);
}
public class Person
{
[Required]
public string Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
public string Surname { get; set; }
[Required]
public string Email { get; set; }
[Required]
public string Phone { get; set; }
[Required]
public string Address { get; set; }
}
public class Salary
{
[Required]
public string Id { get; set; }
[Required]
public double Pay { get; set; }
}
public static partial class GlobalProcess
{
public static string PropertyNullorEmptyCheck(this Person person)
{
string list = "";
list = list + (string.IsNullOrEmpty(person.Id) ? "Id bos olamaz. \n" : "");
list = list + (string.IsNullOrEmpty(person.Name) ? "Name bos olamaz. \n" : "");
list = list + (string.IsNullOrEmpty(person.Surname) ? "Surname bos olamaz. \n" : "");
list = list + (string.IsNullOrEmpty(person.Email) ? "Email bos olamaz. \n" : "");
list = list + (string.IsNullOrEmpty(person.Phone) ? "Phone bos olamaz. \n" : "");
list = list + (string.IsNullOrEmpty(person.Address) ? "Address bos olamaz. \n" : "");
return list;
}
}