forked from postsharp/PostSharp.Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNormalizeStringAspect.cs
More file actions
31 lines (28 loc) · 867 Bytes
/
NormalizeStringAspect.cs
File metadata and controls
31 lines (28 loc) · 867 Bytes
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
using PostSharp.Aspects;
using PostSharp.Extensibility;
using PostSharp.Reflection;
using PostSharp.Serialization;
namespace PostSharp.Samples.NormalizeString
{
[PSerializable]
class NormalizeStringAttribute : LocationInterceptionAspect
{
public override bool CompileTimeValidate(LocationInfo locationInfo)
{
if (locationInfo.LocationType != typeof(string))
{
Message.Write(locationInfo, SeverityType.Error, "MY001", "[NormalizeString] cannot be applied to {0} because its type is not string.", locationInfo);
return false;
}
return true;
}
public override void OnSetValue(LocationInterceptionArgs args)
{
if (args.Value != null)
{
args.Value = ((string) args.Value).Trim().ToLowerInvariant();
}
args.ProceedSetValue();
}
}
}