mirror of
https://github.com/BepInEx/dotnet-runtime.git
synced 2026-11-24 04:11:14 -10:00
Commit migrated from https://github.com/dotnet/corefx/commit/fc3127b0365476f27b6028aeb928f42b36be5b93
52 lines
1.8 KiB
C#
52 lines
1.8 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
using System.Collections.Generic;
|
|
using Xunit;
|
|
|
|
namespace System.Reflection.Extensions.Tests
|
|
{
|
|
public class GetCustomAttributes_Compat
|
|
{
|
|
[Fact]
|
|
public void GetCustomAttributes_thisAsm()
|
|
{
|
|
IEnumerable<Attribute> attributes;
|
|
|
|
Assembly assembly = typeof(GetCustomAttributes_Compat).GetTypeInfo().Assembly;
|
|
|
|
attributes = CustomAttributeExtensions.GetCustomAttributes(assembly, typeof(MyAttribute));
|
|
CheckReturnType(attributes);
|
|
|
|
attributes = CustomAttributeExtensions.GetCustomAttributes(assembly.ManifestModule, typeof(MyAttribute));
|
|
CheckReturnType(attributes);
|
|
|
|
TypeInfo ti = typeof(GetCustomAttributes_Compat).GetTypeInfo();
|
|
attributes = CustomAttributeExtensions.GetCustomAttributes(ti, typeof(MyAttribute));
|
|
CheckReturnType(attributes);
|
|
|
|
attributes = CustomAttributeExtensions.GetCustomAttributes(ti, typeof(MyAttribute), true);
|
|
CheckReturnType(attributes);
|
|
|
|
ParameterInfo p = ti.GetDeclaredMethod("CheckReturnType").GetParameters()[0];
|
|
|
|
attributes = CustomAttributeExtensions.GetCustomAttributes(p, typeof(MyAttribute));
|
|
CheckReturnType(attributes);
|
|
|
|
attributes = CustomAttributeExtensions.GetCustomAttributes(p, typeof(MyAttribute), true);
|
|
CheckReturnType(attributes);
|
|
}
|
|
|
|
public void CheckReturnType(IEnumerable<Attribute> attributes)
|
|
{
|
|
Type expectedType = typeof(MyAttribute[]);
|
|
Type actualType = attributes.GetType();
|
|
Assert.Equal(expectedType, actualType);
|
|
}
|
|
|
|
public class MyAttribute : Attribute
|
|
{
|
|
}
|
|
}
|
|
}
|