You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.8 KiB
45 lines
1.8 KiB
// Author: Gockner, Simon
|
|
// Created: 2020-09-18
|
|
// Copyright(c) 2020 SimonG. All Rights Reserved.
|
|
|
|
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using GBase.Exceptions;
|
|
using GBase.Interfaces;
|
|
|
|
namespace GBase
|
|
{
|
|
/// <summary>
|
|
/// GBase object that supplies inheriting classes with methods to get data from a <see cref="IGBase"/>
|
|
/// </summary>
|
|
public abstract class GBaseObject<T> : IGBaseObject where T : IGBaseObject, new()
|
|
{
|
|
private readonly IGBaseTable<T> _gBaseTable;
|
|
|
|
/// <summary>
|
|
/// GBase object that allows conversion from <see cref="string"/>
|
|
/// </summary>
|
|
/// <exception cref="MissingTableException{T}">No table for <typeparamref name="T"/> is existing</exception>
|
|
protected GBaseObject(IGBase gBase)
|
|
{
|
|
_gBaseTable = gBase.GetTable<T>();
|
|
if (_gBaseTable == null)
|
|
throw new MissingTableException<T>();
|
|
}
|
|
|
|
public GBaseKey Key { get; set; }
|
|
public abstract string FileName { get; }
|
|
|
|
protected async Task SetValue<TProperty>(T @this, string propertyName, TProperty value, CancellationToken cancellationToken) =>
|
|
await _gBaseTable.SetValue(@this, propertyName, value, cancellationToken);
|
|
|
|
protected async Task<TProperty> GetValue<TProperty>(T @this, string propertyName, CancellationToken cancellationToken) =>
|
|
await _gBaseTable.GetValue<TProperty>(@this, propertyName, cancellationToken);
|
|
|
|
protected async Task<IEnumerable<TProperty>> GetValues<TProperty>(T @this, string propertyName, CancellationToken cancellationToken) =>
|
|
await _gBaseTable.GetValues<TProperty>(@this, propertyName, cancellationToken);
|
|
|
|
public abstract void Initialize(GBaseKey key, List<object> parameters);
|
|
}
|
|
} |