The Guard class in the Utility folder is a help class that is only visible in the ObjectBuilder project and mainly performs verification.
1 using System;
2 using System. Collections. Generic;
3 using System. Text;
4 using System. Globalization;
5 using System. Reflection;
6 using Microsoft. Practices. ObjectBuilder. Properties;
7
8 namespace Microsoft. Practices. ObjectBuilder
9 {
10/*** // <summary>
11 // help of "verification function"
12 /// helper class.
13 /// </summary>
14 internal static class Guard
15 {
16
17 public method # region Public Method
18/*** // <summary>
19 // verify the assignee class
20 // can a type be referenced?
21 // point to providedType
22 // type instance.
23 /// </summary>
24 /// <param name = "assignee">
25 // "reference variable" Class
26 /// type.
27 /// </param>
28 /// <param name = "providedType">
29 // "object instance" Class
30 /// type.
31 /// </param>
32 // <param name = "classBeingBuilt">
33 // use OB Block
34 // The object class created by the object
35 // type.
36 /// </param>
37 public static void TypeIsAssignableFromType (
38 Type assignee,
39 Type providedType,
40 Type classBeingBuilt)
41 {
42 if (! Assignee. IsAssignableFrom (providedType ))
43 {
44 throw new IncompatibleTypesException (string. Format (CultureInfo. CurrentCulture, Resources. TypeNotCompatible, assignee, providedType, classBeingBuilt ));
45}
46}
47/*** // <summary>
48 // verify the instance of the specified function
49 // whether the parameter is valid.
50 /// </summary>
51 // <param name = "methodInfo">
52 // the metadata of the function.
53 /// </param>
54 // <param name = "parameters">
55 // real parameters of the function.
56 /// </param>
57 // <param name = "typeBeingBuilt">
58 // use OB Block
59 // The object class created by the object
60 // type.
61 /// </param>
62 public static void ValidateMethodParameters (
63 MethodBase methodInfo,
64 object [] parameters,
65 Type typeBeingBuilt)
66 {
67 ParameterInfo [] paramInfos = methodInfo. GetParameters ();
68
69 for (int I = 0; I <paramInfos. Length; I ++)
70 {
71 if (parameters [I]! = Null)
72 {
73 Guard. TypeIsAssignableFromType (paramInfos [I]. ParameterType, parameters [I]. GetType (), typeBeingBuilt );
74}
75}
76}
77 # endregion
78
79}
80}
81