1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.DynamicProxy
18 using System
.Reflection
;
21 /// Summary description for AssertUtil.
23 internal abstract class AssertUtil
25 public static void NotNull(object argument
, String argumentName
)
29 String message
= String
.Format("Argument '{0}' can't be null", argumentName
);
30 throw new ArgumentNullException(message
);
34 public static void IsInterface(Type type
, String argumentName
)
36 NotNull(type
, argumentName
);
38 if (!type
.IsInterface
)
40 String message
= String
.Format("Argument '{0}' must be an interface", argumentName
);
41 throw new ArgumentException(message
);
45 public static void IsInterface(Type
[] types
, String argumentName
)
47 NotNull(types
, argumentName
);
49 foreach (Type type
in types
)
51 IsInterface(type
, argumentName
);
55 public static void IsClass(Type type
, String argumentName
, bool checkAbstract
)
57 NotNull(type
, argumentName
);
59 if (!type
.IsClass
|| type
.IsAbstract
&& checkAbstract
)
61 bool hasAbstractMembers
= false;
65 MethodInfo
[] abstractMethods
=
66 type
.GetMethods(BindingFlags
.Instance
| BindingFlags
.Public
| BindingFlags
.NonPublic
);
68 foreach (MethodInfo methodInfo
in abstractMethods
)
70 if (methodInfo
.IsAbstract
)
72 hasAbstractMembers
= true;
78 if (!hasAbstractMembers
)
80 // class can be used as a base
81 // class even if it's abstract
85 String message
= String
.Format("Argument '{0}' must be a concrete class", argumentName
);
87 throw new ArgumentException(message
);