1
0
mirror of https://github.com/SirLecram/HospitalServerManager synced 2024-07-17 18:30:30 +02:00
admissionManager/ViewModel/DataProvider/TypeProvider.cs
Marcel Grześ 069f0612da Basic function development
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.
2018-12-29 11:58:25 +01:00

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);
}
}
}