Simple impl to MockRailsEngineContext.Url
[castle.git] / Tools / DynamicProxy / Castle.DynamicProxy / AssertUtil.cs
blob73b975ce29a0d0cc3a13c2bd3ad4a38116295661
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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
17 using System;
18 using System.Reflection;
20 /// <summary>
21 /// Summary description for AssertUtil.
22 /// </summary>
23 internal abstract class AssertUtil
25 public static void NotNull(object argument, String argumentName)
27 if (argument == null)
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;
63 if (type.IsAbstract)
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;
73 break;
78 if (!hasAbstractMembers)
80 // class can be used as a base
81 // class even if it's abstract
82 return;
85 String message = String.Format("Argument '{0}' must be a concrete class", argumentName);
87 throw new ArgumentException(message);