Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/Reflectify/EmbeddedAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#if !REFLECTIFY_COMPILE
// <autogenerated />
#pragma warning disable
#endif

#nullable disable

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace Microsoft.CodeAnalysis;

/// <summary>
/// A special attribute recognized by Roslyn, that marks a type as "embedded", meaning it won't ever be visible from
/// other assemblies.
/// </summary>
/// <remarks>
/// Another source-only package compiled into the same assembly may declare this attribute too. Declaring it as
/// <c>partial</c> lets both declarations merge into one type instead of colliding. For that to work, no part may
/// carry a type-level attribute such as <c>[AttributeUsage]</c>, because attributes cannot be repeated across parts.
/// Leaving it off is harmless: <c>AttributeTargets.All</c> is the default.
/// </remarks>
#pragma warning disable RCS1203, MA0010, CA1018 // Deliberately omitted so that duplicate declarations can merge, see above.
internal sealed partial class EmbeddedAttribute : System.Attribute
#pragma warning restore RCS1203, MA0010, CA1018
{
}
6 changes: 6 additions & 0 deletions src/Reflectify/MemberInfoExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@

namespace Reflectify;

#if REFLECTIFY_COMPILE
public static class MemberInfoExtensions
#else
[global::Microsoft.CodeAnalysis.Embedded]
[global::System.Diagnostics.DebuggerNonUserCode]
internal static class MemberInfoExtensions
#endif
{
public static bool HasAttribute<TAttribute>(this MemberInfo member)
where TAttribute : Attribute
Expand Down
11 changes: 11 additions & 0 deletions src/Reflectify/MemberKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ namespace Reflectify;
/// Defines the kinds of members you want to get when querying for the fields and properties of a type.
/// </summary>
[Flags]
#if REFLECTIFY_COMPILE
public enum MemberKind
#else
[global::Microsoft.CodeAnalysis.Embedded]
internal enum MemberKind
#endif
{
None,
Public = 1,
Expand All @@ -24,7 +29,13 @@ internal enum MemberKind
Static = 16
}

#if REFLECTIFY_COMPILE
public static class MemberKindExtensions
#else
[global::Microsoft.CodeAnalysis.Embedded]
[global::System.Diagnostics.DebuggerNonUserCode]
internal static class MemberKindExtensions
#endif
{
public static BindingFlags ToBindingFlags(this MemberKind kind)
{
Expand Down
6 changes: 6 additions & 0 deletions src/Reflectify/ParameterInfoExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@

namespace Reflectify;

#if REFLECTIFY_COMPILE
public static class ParameterInfoExtensions
#else
[global::Microsoft.CodeAnalysis.Embedded]
[global::System.Diagnostics.DebuggerNonUserCode]
internal static class ParameterInfoExtensions
#endif
{
/// <summary>
/// Returns <see langword="true" /> if the parameter is decorated with the specific <typeparamref name="TAttribute"/>,
Expand Down
6 changes: 6 additions & 0 deletions src/Reflectify/PropertyInfoExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@

namespace Reflectify;

#if REFLECTIFY_COMPILE
public static class PropertyInfoExtensions
#else
[global::Microsoft.CodeAnalysis.Embedded]
[global::System.Diagnostics.DebuggerNonUserCode]
internal static class PropertyInfoExtensions
#endif
{
/// <summary>
/// Returns <see langword="true" /> if the property is an indexer, or <see langword="false" /> otherwise.
Expand Down
7 changes: 1 addition & 6 deletions src/Reflectify/Reflectify.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@
<NuSpecFile>.nuspec</NuSpecFile>
<NuspecProperties>version=$(Version)</NuspecProperties>
<DefineConstants>REFLECTIFY_COMPILE</DefineConstants>
<NoWarn>1591;1573</NoWarn>
</PropertyGroup>

<ItemGroup Label="Internals visible to">
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>Reflectify.Specs</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DocumentationFile>bin\Debug\Reflectify.xml</DocumentationFile>
</PropertyGroup>
Expand Down
8 changes: 7 additions & 1 deletion src/Reflectify/Reflector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ namespace Reflectify;
/// <summary>
/// Helper class to get all the public and internal fields and properties from a type.
/// </summary>
#if REFLECTIFY_COMPILE
public sealed class Reflector(Type typeToReflect, MemberKind kind)
#else
[global::Microsoft.CodeAnalysis.Embedded]
[global::System.Diagnostics.DebuggerNonUserCode]
internal sealed class Reflector(Type typeToReflect, MemberKind kind)
#endif
{
private readonly object lazyLoadingLock = new();
private volatile PropertyInfo[] cachedProperties;
Expand Down Expand Up @@ -173,7 +179,7 @@ private static bool HasVisibility(MemberKind kind, FieldInfo field)
((kind & MemberKind.Internal) != MemberKind.None && (field.IsAssembly || field.IsFamilyOrAssembly));
}

private class OrderedPropertyCollection
private sealed class OrderedPropertyCollection
{
private readonly Dictionary<string, PropertyKind> kindMap = new();
private readonly List<(string Name, PropertyInfo Property)> propertiesWithName = new();
Expand Down
6 changes: 6 additions & 0 deletions src/Reflectify/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@

namespace Reflectify;

#if REFLECTIFY_COMPILE
public static class TypeExtensions
#else
[global::Microsoft.CodeAnalysis.Embedded]
[global::System.Diagnostics.DebuggerNonUserCode]
internal static class TypeExtensions
#endif
{
/// <summary>
/// If the type provided is a nullable type, gets the underlying type. Returns the type itself otherwise.
Expand Down
6 changes: 6 additions & 0 deletions src/Reflectify/TypeMemberExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@

namespace Reflectify;

#if REFLECTIFY_COMPILE
public static class TypeMemberExtensions
#else
[global::Microsoft.CodeAnalysis.Embedded]
[global::System.Diagnostics.DebuggerNonUserCode]
internal static class TypeMemberExtensions
#endif
{
private static readonly ConcurrentDictionary<(Type Type, MemberKind Kind), Reflector> ReflectorCache = new();

Expand Down
6 changes: 6 additions & 0 deletions src/Reflectify/TypeMetaDataExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@

namespace Reflectify;

#if REFLECTIFY_COMPILE
public static class TypeMetaDataExtensions
#else
[global::Microsoft.CodeAnalysis.Embedded]
[global::System.Diagnostics.DebuggerNonUserCode]
internal static class TypeMetaDataExtensions
#endif
{
/// <summary>
/// Returns the name of the type without the generic backtick and the type arguments.
Expand Down