-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoadingResult.cs
66 lines (57 loc) · 1.73 KB
/
LoadingResult.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace Data.Net
{
/// <summary>
/// Holds loaded data.
/// </summary>
public class LoadingResult<TData> where TData : struct
{
public LoadingResult()
{
_loadedData = new Dictionary<TData, object>();
_exceptions = new List<Exception>();
}
/// <summary>
/// Tells if all requested data was loaded successfully
/// </summary>
public bool Success { get; set; }
/// <summary>
/// Gets loaded data
/// </summary>
/// <param name="key">type of data</param>
/// <returns>loaded value</returns>
public object this[TData key]
{
get { return _loadedData[key]; }
}
/// <summary>
/// Checks whether data with specified key has been loaded successfully
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public bool IsLoaded(TData key)
{
return _loadedData.ContainsKey(key) && this[key] != null;
}
/// <summary>
/// All catched exceptions while loading data
/// </summary>
public Exception[] Exceptions
{
get { return _exceptions.ToArray(); }
}
internal void AddData(TData key, object value)
{
_loadedData.Add(key, value);
}
internal void AddException(Exception ex)
{
_exceptions.Add(ex);
}
internal int Count { get { return _loadedData.Count; } }
private readonly IDictionary<TData, object> _loadedData;
private readonly List<Exception> _exceptions;
}
}