1 public class LengthParameterInspector : IParameterInspector
2 {
3 public int ParameterIndex { get; private set; }
4
5 public int MaxLength { get; private set; }
6
7 public LengthParameterInspector(int parameterIndex, int maxLength)
8 {
9 this.ParameterIndex = parameterIndex;
10 this.MaxLength = maxLength;
11 }
12
13 public void AfterCall(string operationName, object[] outputs, object returnValue, object correlationState)
14 {
15 //throw new NotImplementedException();
16 }
17
18 public object BeforeCall(string operationName, object[] inputs)
19 {
20 if (inputs.Length < ParameterIndex)
21 {
22 return null;
23 }
24
25 string input = inputs[ParameterIndex] as string;
26
27 if (input != null)
28 {
29 if (input.Length > this.MaxLength)
30 {
31 throw new FaultException(string.Format("the length of parameter {0} must less than {1}", ParameterIndex.ToString(), MaxLength.ToString()));
32 }
33 }
34
35 return null;
36 }
37 }