mirror of
https://github.com/DarthAffe/OBD.NET.git
synced 2025-12-12 08:48:30 +00:00
Added method to request data with a non-generic type-parameter
This commit is contained in:
parent
17aa5284c3
commit
9948f33a4f
@ -134,6 +134,18 @@ namespace OBD.NET.Common.Devices
|
||||
return await RequestDataAsync(pid) as T;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Requests the data asynchronous and return the data when available
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IOBDData> RequestDataAsync(Type type)
|
||||
{
|
||||
Logger?.WriteLine("Requesting Type " + type.Name + " ...", OBDLogLevel.Debug);
|
||||
byte pid = ResolvePid(type);
|
||||
return await RequestDataAsync(pid) as IOBDData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request data based on a pid
|
||||
/// </summary>
|
||||
@ -182,9 +194,12 @@ namespace OBD.NET.Common.Devices
|
||||
|
||||
protected virtual byte ResolvePid<T>()
|
||||
where T : class, IOBDData, new()
|
||||
=> ResolvePid(typeof(T));
|
||||
|
||||
protected virtual byte ResolvePid(Type type)
|
||||
{
|
||||
if (!PidCache.TryGetValue(typeof(T), out byte pid))
|
||||
pid = AddToPidCache<T>();
|
||||
if (!PidCache.TryGetValue(type, out byte pid))
|
||||
pid = AddToPidCache(type);
|
||||
|
||||
return pid;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user