CSLA.NET 5.4.2
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
TaskLoader.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6
8{
9
10 internal class TaskDataPortalResult : IDataPortalResult
11 {
12 public object Object { get; internal set; }
13 public Exception Error { get; internal set; }
14 public object UserState { get; internal set; }
15 }
16
20 internal class TaskLoader<T> : IAsyncLoader
21 {
22 private readonly Task<T> _loader;
23 public IPropertyInfo Property { get; private set; }
24
25 public TaskLoader(IPropertyInfo property, Task<T> loader)
26 {
27 Property = property;
28 _loader = loader;
29 }
30
31 public async void Load(Action<IAsyncLoader, IDataPortalResult> callback)
32 {
33 TaskDataPortalResult result;
34 try
35 {
36 var o = await _loader;
37 result = new TaskDataPortalResult() { Error = null, Object = o };
38 }
39 catch (Exception ex)
40 {
41 result = new TaskDataPortalResult() { Error = ex, Object = null };
42 }
43
44 callback(this, result);
45 }
46 }
47}
@ Error
Represents a serious business rule violation that should cause an object to be considered invalid.