// /* ============================================================================ // Copyright 2014 Hewlett Packard // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // ============================================================================ */ using System; using System.Collections.Generic; using System.Linq; using System.Reflection; namespace OpenStack.Common { /// /// Static class for extending reflection classes. /// internal static class ReflectionExtentions { /// /// Gets the assembly that contains the extended type. /// /// The given Type /// The assembly that contains the given type. public static Assembly GetAssembly(this Type input) { return input.GetTypeInfo().Assembly; } /// /// Determines if a type is assignable from the given type. /// /// The given type. /// The type to evaluate. /// A value indicating if the target is assignable from the given type. public static bool IsAssignableFrom(this Type input, Type target) { return input.GetTypeInfo().IsAssignableFrom(target.GetTypeInfo()); } /// /// Determines if the given type is an interface. /// /// The given type. /// A value indicating if the given type is an interface. public static bool IsInterface(this Type input) { return input.GetTypeInfo().IsInterface; } /// /// Gets a list of types that are defined in the given assembly. /// /// The given assembly. /// A list of types defined in the given assembly. public static IEnumerable GetDefinedTypes(this Assembly input) { return input.DefinedTypes.Select(ti => ti.AsType()); } /// /// Gets a list of defined constructors for the given type. /// /// The given type. /// A list of constructors for the given type. public static IEnumerable GetDefinedConstructors(this Type input) { return input.GetTypeInfo().DeclaredConstructors; } } }