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
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ resharper_csharp_wrap_after_invocation_lpar = true
resharper_csharp_wrap_arguments_style = chop_if_long
resharper_csharp_wrap_before_invocation_rpar = true
resharper_keep_existing_invocation_parens_arrangement = false
resharper_keep_existing_property_patterns_arrangement = false
resharper_max_invocation_arguments_on_line = 3
resharper_place_expr_property_on_single_line = true
resharper_place_simple_initializer_on_single_line = false
Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
<PropertyGroup Label="Language Properties">
<Deterministic>true</Deterministic>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>preview</LangVersion>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<RuntimeIdentifiers>linux-arm64;linux-x64;osx-arm64;osx-x64;win-x64</RuntimeIdentifiers>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion Examples/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

</Project>
7 changes: 7 additions & 0 deletions Framework/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<Project>

<PropertyGroup>
<IntersectRepoPath Condition="'$(IntersectRepoPath)' == ''">$(MSBuildProjectDirectory)\..\..</IntersectRepoPath>
</PropertyGroup>

<Import Project="../Directory.Build.props" />

<PropertyGroup>
<IntersectRepoPath>$(MSBuildProjectDirectory)\..\..</IntersectRepoPath>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Intersect.Framework.Converters.Json;

public abstract class GenericFactoryNewtonsoftJsonConverter : JsonConverter
{
private static readonly Dictionary<Type, JsonConverter> _converters = new Dictionary<Type, JsonConverter>();
private static readonly Dictionary<Type, JsonConverter> Converters = [];

private readonly Type _converterTypeDefinition;
private readonly Type _serializedGenericTypeDefinition;
Expand Down Expand Up @@ -60,7 +60,7 @@ private static JsonConverter CreateActualConverter(
Type objectType
)
{
if (_converters.TryGetValue(objectType, out JsonConverter? jsonConverter))
if (Converters.TryGetValue(objectType, out JsonConverter? jsonConverter))
{
return jsonConverter;
}
Expand All @@ -73,7 +73,7 @@ Type objectType
var identifiedType = targetType.FindGenericTypeParameters(serializedGenericTypeDefinition);
var converterType = converterTypeDefinition.MakeGenericType(identifiedType);
jsonConverter = Activator.CreateInstance(converterType) as JsonConverter;
_converters[objectType] = jsonConverter ?? throw new InvalidOperationException();
Converters[objectType] = jsonConverter ?? throw new InvalidOperationException();
return jsonConverter;
}
}
21 changes: 15 additions & 6 deletions Framework/Intersect.Framework/Intersect.Framework.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MessagePack.Annotations" Version="2.6.100-alpha" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="7.0.14" />
Expand All @@ -17,4 +11,19 @@
<PackageReference Include="System.Text.Json" Version="8.0.5" />
</ItemGroup>

<ItemGroup>
<Compile Update="Reflection\ReflectionStrings.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>ReflectionStrings.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Reflection\ReflectionStrings.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>ReflectionStrings.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

</Project>
21 changes: 12 additions & 9 deletions Framework/Intersect.Framework/Reflection/AssemblyExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Resources;
// ReSharper disable MemberCanBePrivate.Global

namespace Intersect.Framework.Reflection;

Expand Down Expand Up @@ -34,7 +35,7 @@ params object[] args
if (type == default)
{
throw new InvalidOperationException(
$"Found no matching subtype of {typeof(TParentType).FullName} that can be created."
string.Format(ReflectionStrings.AssemblyExtensions_NoMatchingSubtype, typeof(TParentType).FullName)
);
}

Expand All @@ -43,7 +44,9 @@ params object[] args
return instance;
}

throw new InvalidOperationException($"Failed to create instance of {typeof(TParentType).FullName}.");
throw new InvalidOperationException(
string.Format(ReflectionStrings.AssemblyExtensions_FailedToCreateInstance, typeof(TParentType).FullName)
);
}

public static string GetVersionName(this Assembly assembly)
Expand All @@ -61,7 +64,7 @@ public static string GetVersionName(this Assembly assembly)
}

public static IEnumerable<Type> FindAbstractSubtypesOf(this Assembly assembly, Type type) =>
assembly.FindSubtypesOf(type).Where(subtype => subtype?.IsAbstract ?? false);
assembly.FindSubtypesOf(type).Where(subtype => subtype.IsAbstract);

public static IEnumerable<Type> FindAbstractSubtypesOf<TParentType>(this Assembly assembly) =>
assembly.FindAbstractSubtypesOf(typeof(TParentType));
Expand All @@ -75,16 +78,16 @@ public static IEnumerable<Type> FindDefinedSubtypesOf<TParentType>(this Assembly
assembly.FindDefinedSubtypesOf(typeof(TParentType));

public static IEnumerable<Type> FindGenericSubtypesOf(this Assembly assembly, Type type) =>
assembly.FindSubtypesOf(type).Where(subtype => subtype?.IsGenericType ?? false);
assembly.FindSubtypesOf(type).Where(subtype => subtype.IsGenericType);

public static IEnumerable<Type> FindGenericSubtypesOf<TParentType>(this Assembly assembly) =>
assembly.FindGenericSubtypesOf(typeof(TParentType));

public static IEnumerable<Type> FindInterfaceSubtypesOf(this Assembly assembly, Type type) =>
assembly.FindSubtypesOf(type).Where(subtype => subtype?.IsInterface ?? false);
assembly.FindSubtypesOf(type).Where(subtype => subtype.IsInterface);

public static IEnumerable<Type> FindInterfaceSubtypesOf<TParentType>(this Assembly assembly) =>
assembly.FindInterfaceSubtypesOf(typeof(Type));
assembly.FindInterfaceSubtypesOf(typeof(TParentType));

public static IEnumerable<Type> FindSubtypesOf(this Assembly assembly, Type type) =>
assembly.GetTypes().Where(type.IsAssignableFrom);
Expand All @@ -93,10 +96,10 @@ public static IEnumerable<Type> FindSubtypesOf<TParentType>(this Assembly assemb
assembly.FindGenericSubtypesOf(typeof(TParentType));

public static IEnumerable<Type> FindValueSubtypesOf(this Assembly assembly, Type type) =>
assembly.FindSubtypesOf(type).Where(subtype => subtype?.IsValueType ?? false);
assembly.FindSubtypesOf(type).Where(subtype => subtype.IsValueType);

public static IEnumerable<Type> FindValueSubtypesOf<TParentType>(this Assembly assembly) =>
assembly.FindValueSubtypesOf(typeof(Type));
assembly.FindValueSubtypesOf(typeof(TParentType));

public static bool TryFindResource(
this Assembly assembly,
Expand All @@ -111,7 +114,7 @@ public static bool TryFindResource(
}

manifestResourceName = assembly.GetManifestResourceNames()
.FirstOrDefault(name => name?.Contains(resourceName, StringComparison.CurrentCulture) ?? false);
.FirstOrDefault(name => name.Contains(resourceName, StringComparison.CurrentCulture));
return manifestResourceName != default;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Diagnostics;
using System.Reflection;
// ReSharper disable MemberCanBePrivate.Global

namespace Intersect.Framework.Reflection;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
// ReSharper disable MemberCanBePrivate.Global

namespace Intersect.Framework.Reflection;

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion Framework/Intersect.Framework/Reflection/ReflectionStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">

</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
Expand All @@ -27,4 +27,19 @@
<data name="ExpectedAnIncompleteTypeButReceivedX" xml:space="preserve">
<value>Expected an incomplete type but received {0}.</value>
</data>
<data name="TypeExtensions_FindGenericTypeParameters_NotGeneric" xml:space="preserve">
<value>{0} is not a generic type and does not extend from a generic type.</value>
</data>
<data name="TypeExtensions_FindGenericTypeParameters_NotValidGenericTypeDefinition" xml:space="preserve">
<value>Not a valid generic type definition: {0}</value>
</data>
<data name="TypeExtensions_FindConcreteType_ExpectedAbstractOrInterface" xml:space="preserve">
<value>Expected abstract/interface type, received {0}</value>
</data>
<data name="AssemblyExtensions_NoMatchingSubtype" xml:space="preserve">
<value>Found no matching subtype of {0} that can be created.</value>
</data>
<data name="AssemblyExtensions_FailedToCreateInstance" xml:space="preserve">
<value>Failed to create instance of {0}.</value>
</data>
</root>
Loading
Loading