-
Notifications
You must be signed in to change notification settings - Fork 325
/
Copy pathAspectContextExtensions.cs
34 lines (31 loc) · 1.17 KB
/
AspectContextExtensions.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
using System;
using System.Collections.Generic;
using System.Text;
using AspectCore.DynamicProxy;
namespace AspectCore.Extensions.DataValidation
{
public static class AspectContextExtensions
{
private const string DataValidationContextKey = "DataValidation-Context";
public static DataValidationContext GetDataValidationContext(this AspectContext aspectContext)
{
if (aspectContext == null)
{
throw new ArgumentNullException(nameof(aspectContext));
}
return aspectContext.AdditionalData[DataValidationContextKey] as DataValidationContext;
}
public static void SetDataValidationContext(this AspectContext aspectContext, DataValidationContext dataValidationContext)
{
if (aspectContext == null)
{
throw new ArgumentNullException(nameof(aspectContext));
}
if (dataValidationContext == null)
{
throw new ArgumentNullException(nameof(dataValidationContext));
}
aspectContext.AdditionalData[DataValidationContextKey] = dataValidationContext;
}
}
}