-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Managed TestCase Properties implemented
* `ManagedType` and `ManagedMethod` support added to `Microsoft.TestPlatform.ObjectModel.TestCase`
- Loading branch information
Showing
54 changed files
with
2,935 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/Microsoft.TestPlatform.CoreUtilities/Extensions/ReflectionExtensions.MethodBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Extensions | ||
{ | ||
using System; | ||
using System.Reflection; | ||
|
||
public static partial class ReflectionExtensions | ||
{ | ||
#if NETSTANDARD1_0 || NETSTANDARD1_3 || WINDOWS_UWP | ||
private static readonly Type methodBase = typeof(MethodBase); | ||
|
||
private const string MemberTypePropertyName = "MemberType"; | ||
private const string ReflectedTypePropertyName = "ReflectedType"; | ||
private const string MethodHandlePropertyName = "MethodHandle"; | ||
|
||
private static readonly PropertyInfo memberTypeProperty = methodBase.GetRuntimeProperty(MemberTypePropertyName); | ||
private static readonly PropertyInfo reflectedTypeProperty = methodBase.GetRuntimeProperty(ReflectedTypePropertyName); | ||
private static readonly PropertyInfo methodHandleProperty = methodBase.GetRuntimeProperty(MethodHandlePropertyName); | ||
#endif | ||
|
||
public static bool IsMethod(this MethodBase method) | ||
{ | ||
#if !NETSTANDARD1_0 && !NETSTANDARD1_3 && !WINDOWS_UWP | ||
return method.MemberType == MemberTypes.Method; | ||
#else | ||
AssertSupport(memberTypeProperty, MemberTypePropertyName, methodBase.FullName); | ||
|
||
return (int)memberTypeProperty.GetValue(method) == 8; | ||
#endif | ||
} | ||
|
||
public static Type GetReflectedType(this MethodBase method) | ||
{ | ||
#if !NETSTANDARD1_0 && !NETSTANDARD1_3 && !WINDOWS_UWP | ||
return method.ReflectedType; | ||
#else | ||
AssertSupport(memberTypeProperty, ReflectedTypePropertyName, methodBase.FullName); | ||
|
||
return reflectedTypeProperty.GetValue(method) as Type; | ||
#endif | ||
} | ||
|
||
public static RuntimeMethodHandle GetMethodHandle(this MethodBase method) | ||
{ | ||
#if !NETSTANDARD1_0 && !NETSTANDARD1_3 && !WINDOWS_UWP | ||
return method.MethodHandle; | ||
#else | ||
AssertSupport(memberTypeProperty, MethodHandlePropertyName, methodBase.FullName); | ||
|
||
return (RuntimeMethodHandle)methodHandleProperty.GetValue(method); | ||
#endif | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/Microsoft.TestPlatform.CoreUtilities/Extensions/ReflectionExtensions.Type.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Extensions | ||
{ | ||
using System; | ||
using System.Reflection; | ||
|
||
public static partial class ReflectionExtensions | ||
{ | ||
public static bool IsGenericType(this Type type) | ||
{ | ||
#if !NETSTANDARD1_0 && !NETSTANDARD1_3 && !WINDOWS_UWP | ||
return type.IsGenericType; | ||
#else | ||
return type.GetTypeInfo().IsGenericType; | ||
#endif | ||
} | ||
|
||
public static MethodBase GetDeclaringMethod(this Type type) | ||
{ | ||
#if !NETSTANDARD1_0 && !NETSTANDARD1_3 && !WINDOWS_UWP | ||
return type.DeclaringMethod; | ||
#else | ||
return type.GetTypeInfo().DeclaringMethod; | ||
#endif | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Microsoft.TestPlatform.CoreUtilities/Extensions/ReflectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Extensions | ||
{ | ||
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Resources; | ||
|
||
using System; | ||
|
||
public static partial class ReflectionExtensions | ||
{ | ||
private static void AssertSupport<T>(T obj, string methodName, string className) | ||
where T : class | ||
{ | ||
if (obj == null) | ||
{ | ||
throw new NotImplementedException(string.Format(Resources.MethodNotImplementedOnPlatform, className, methodName)); | ||
} | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions
11
src/Microsoft.TestPlatform.CoreUtilities/Resources/Resources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.