Files
openstack-sdk-dotnet/OpenStack/OpenStack45-PCL/Common/ReflectionExtentions.cs
Wayne Foley 63d036cc88 Spliting the solution up into two projects. One project for 4.0 and another for 4.5.
Added retargeting code so the 4.0 project can use async await
Added extention methods to work around differences in reflection and async support.
Changed the output folders for each project, to relfect the .NET framework version they are being built with.
Updated the unit test project to build take a reference to the 4.5/PCL assembly.
Updated the example projects to take a dependency on the 4.5/PCL assembly.

Implements blueprint support-net35
Change-Id: Iefb776912cd8257b38a9aaf97cc7bb1b347b8892
2014-05-06 16:55:36 -07:00

81 lines
3.0 KiB
C#

// /* ============================================================================
// 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
{
/// <summary>
/// Static class for extending reflection classes.
/// </summary>
internal static class ReflectionExtentions
{
/// <summary>
/// Gets the assembly that contains the extended type.
/// </summary>
/// <param name="input">The given Type</param>
/// <returns>The assembly that contains the given type.</returns>
public static Assembly GetAssembly(this Type input)
{
return input.GetTypeInfo().Assembly;
}
/// <summary>
/// Determines if a type is assignable from the given type.
/// </summary>
/// <param name="input">The given type.</param>
/// <param name="target">The type to evaluate.</param>
/// <returns>A value indicating if the target is assignable from the given type.</returns>
public static bool IsAssignableFrom(this Type input, Type target)
{
return input.GetTypeInfo().IsAssignableFrom(target.GetTypeInfo());
}
/// <summary>
/// Determines if the given type is an interface.
/// </summary>
/// <param name="input">The given type.</param>
/// <returns>A value indicating if the given type is an interface.</returns>
public static bool IsInterface(this Type input)
{
return input.GetTypeInfo().IsInterface;
}
/// <summary>
/// Gets a list of types that are defined in the given assembly.
/// </summary>
/// <param name="input">The given assembly.</param>
/// <returns>A list of types defined in the given assembly.</returns>
public static IEnumerable<Type> GetDefinedTypes(this Assembly input)
{
return input.DefinedTypes.Select(ti => ti.AsType());
}
/// <summary>
/// Gets a list of defined constructors for the given type.
/// </summary>
/// <param name="input">The given type.</param>
/// <returns>A list of constructors for the given type.</returns>
public static IEnumerable<ConstructorInfo> GetDefinedConstructors(this Type input)
{
return input.GetTypeInfo().DeclaredConstructors;
}
}
}