Demo/Domain/Models/User.cs

38 lines
1.0 KiB
C#
Raw Permalink Normal View History

2024-10-17 11:46:19 +00:00
namespace Demo.Domain.Models
{
public class User
{
public required string FIO{get; set; }
public Guid Guid{get; set; }
public required Group Group{get; set; }
2024-10-24 15:57:52 +00:00
public static User Parse(string input)
{
2024-10-17 11:46:19 +00:00
string[] words = input.Split(" ");
2024-10-24 15:57:52 +00:00
if (words.Length < 4)
{
throw new FormatException("Input string does not have the expected number of elements.");
2024-10-17 11:46:19 +00:00
}
2024-10-24 15:57:52 +00:00
try
2024-10-17 11:46:19 +00:00
{
2024-10-24 15:57:52 +00:00
return new User
2024-10-17 11:46:19 +00:00
{
2024-10-24 15:57:52 +00:00
FIO = words[0],
Guid = Guid.Parse(words[1]),
Group = new Group
{
ID = Convert.ToInt32(words[2]),
Name = words[3]
}
};
}
catch (FormatException ex)
{
Console.WriteLine("Error parsing input: " + ex.Message);
throw;
}
2024-10-17 11:46:19 +00:00
}
}
}