mirror of
https://github.com/SirLecram/HospitalServerManager
synced 2024-10-20 01:00:35 +02:00
069f0612da
A few models has been improved; New pages has been added; NewRecordDialog has been added; ViewNavigator was created; A type providers has been added; new interfaces has been added; New validator, which checks if interface is implemented has been added; The application can read data and add new record by API now.
40 lines
1.0 KiB
C#
40 lines
1.0 KiB
C#
using HospitalServerManager.InterfacesAndEnums;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace HospitalServerManager.ViewModel.DataProvider
|
|
{
|
|
class TypeProvider : IProvideType
|
|
{
|
|
protected Dictionary<string, Type> NamesDictionary = new Dictionary<string, Type>();
|
|
|
|
public TypeProvider() { }
|
|
public TypeProvider(List<Type> typeToRegister)
|
|
{
|
|
typeToRegister.ForEach(x => RegisterType(x));
|
|
}
|
|
public TypeProvider(Type typeToRegister) : this(new List<Type> { typeToRegister }) { }
|
|
|
|
public Type GetTypeFromString(string typeName)
|
|
{
|
|
if (!NamesDictionary.ContainsKey(typeName))
|
|
throw new KeyNotFoundException("The key does not exist!");
|
|
|
|
return NamesDictionary[typeName];
|
|
}
|
|
|
|
public virtual void RegisterType(Type typeToRegister)
|
|
{
|
|
string typeName = typeToRegister.Name;
|
|
|
|
if (NamesDictionary.ContainsKey(typeName))
|
|
throw new Exception("Type was registred before!");
|
|
|
|
NamesDictionary.Add(typeName, typeToRegister);
|
|
}
|
|
}
|
|
}
|