Skip to content

Commit

Permalink
fix: Resolve/mute nullability-related warnings in Intersect.Framework (
Browse files Browse the repository at this point in the history
  • Loading branch information
lodicolo authored Nov 2, 2024
1 parent dcd0123 commit a32f7d5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ params object[] args
public static string GetVersionName(this Assembly assembly)
{
var version = assembly.GetName().Version;

if (version == default)
{
return "???";
}

var versionMajorMinor = $"{version.Major}.{version.Minor}";
var versionSuffix = version.Major == 0 ? "-beta" : string.Empty;
return versionMajorMinor + versionSuffix;
Expand All @@ -62,6 +68,7 @@ public static IEnumerable<Type> FindAbstractSubtypesOf<TParentType>(this Assembl

public static IEnumerable<Type> FindDefinedSubtypesOf(this Assembly assembly, Type type) => assembly
.FindSubtypesOf(type)
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
.Where(subtype => !(subtype == null || subtype.IsAbstract || subtype.IsGenericType || subtype.IsInterface));

public static IEnumerable<Type> FindDefinedSubtypesOf<TParentType>(this Assembly assembly) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static string GetFullName(this MemberInfo memberInfo)
{
if (memberInfo is Type type)
{
return type.FullName;
return type.GetName(true);
}

var declaringType = memberInfo.DeclaringType;
Expand All @@ -21,8 +21,8 @@ public static string GetSignature(this MethodInfo methodInfo, bool fullyQualifie
{
Debug.Assert(methodInfo != null);

var returnTypeName = fullyQualified ? methodInfo.ReturnType.FullName : methodInfo.ReturnType.Name;
var declaringTypeName = fullyQualified ? methodInfo.DeclaringType.FullName : methodInfo.DeclaringType.Name;
var returnTypeName = methodInfo.ReturnType.GetName(fullyQualified);
var declaringTypeName = methodInfo.DeclaringType?.GetName(fullyQualified) ?? "???";
var parameterTypes = methodInfo.GetParameters().Select(parameter => parameter.ParameterType);
var parameterTypeNames = parameterTypes.Select(
parameterType => fullyQualified ? parameterType.FullName : parameterType.Name
Expand Down
10 changes: 7 additions & 3 deletions Framework/Intersect.Framework/Reflection/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public static IEnumerable<ConstructorInfo> FindConstructors(this Type type, para

var parameter = parameters[index];

// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
if (parameter == null)
{
if (constructorParameter.ParameterType.IsValueType)
Expand Down Expand Up @@ -196,7 +197,7 @@ public static Type[] FindDerivedTypes(this Type type, params Assembly[] assembli
return derivedTypes;
}

public static Type FindGenericType(this Type type) => type.FindGenericType(true);
public static Type? FindGenericType(this Type type) => type.FindGenericType(true);

public static Type? FindGenericType(this Type type, bool throwOnNonGeneric) =>
type.FindGenericType(default, throwOnNonGeneric);
Expand Down Expand Up @@ -296,11 +297,11 @@ public static Type[] FindGenericTypeParameters(this Type type, bool throwOnNonGe

public static Type[] FindGenericTypeParameters(
this Type type,
Type genericTypeDefinition,
Type? genericTypeDefinition,
bool throwOnNonGeneric = true
)
{
if (genericTypeDefinition != null && !genericTypeDefinition.IsGenericTypeDefinition)
if (genericTypeDefinition is { IsGenericTypeDefinition: false })
{
throw new ArgumentException(
$"Not a valid generic type definition: {genericTypeDefinition.FullName}",
Expand Down Expand Up @@ -375,6 +376,9 @@ public static Type[] FindImplementationsIn(this Type incompleteType, IEnumerable
return type.Assembly.GetName().Name ?? fallbackIfNull;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string GetName(this Type type, bool qualified = false) => qualified ? type.GetQualifiedName() : type.Name;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string GetQualifiedName(this Type type) => type.FullName ?? type.Name;

Expand Down
52 changes: 26 additions & 26 deletions Intersect.sln
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Intersect.Client", "Interse
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Intersect.Client.Framework", "Intersect.Client.Framework\Intersect.Client.Framework.csproj", "{40973F13-3339-4548-9008-FF76A0C8CD79}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Intersect.Editor", "Intersect.Editor\Intersect.Editor.csproj", "{5AC53DF1-8152-466D-B7D0-238657F013F7}"
EndProject
#Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Intersect.Editor", "Intersect.Editor\Intersect.Editor.csproj", "{5AC53DF1-8152-466D-B7D0-238657F013F7}"
#EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Intersect.Network", "Intersect.Network\Intersect.Network.csproj", "{E8F288CB-51DF-4D9D-A3B3-A61BD4FD3F45}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Intersect.Server", "Intersect.Server\Intersect.Server.csproj", "{9FFC7331-87BE-403B-82A0-B86D3CCE7C53}"
Expand Down Expand Up @@ -80,10 +80,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Framework", "Framework", "{
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Intersect.Framework", "Framework\Intersect.Framework\Intersect.Framework.csproj", "{1E87D2A5-7E36-4583-A533-064C97E330EE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinFormsUI", "vendor\dockpanelsuite\WinFormsUI\WinFormsUI.csproj", "{D831728A-6328-4F96-9692-8FE64E0B0AAD}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ThemeVS2015", "vendor\dockpanelsuite\WinFormsUI\ThemeVS2015.csproj", "{B9678B78-A00D-4765-9380-B1DC4EFD642D}"
EndProject
#Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinFormsUI", "vendor\dockpanelsuite\WinFormsUI\WinFormsUI.csproj", "{D831728A-6328-4F96-9692-8FE64E0B0AAD}"
#EndProject
#Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ThemeVS2015", "vendor\dockpanelsuite\WinFormsUI\ThemeVS2015.csproj", "{B9678B78-A00D-4765-9380-B1DC4EFD642D}"
#EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -109,12 +109,12 @@ Global
{40973F13-3339-4548-9008-FF76A0C8CD79}.NoFody|Any CPU.Build.0 = Debug|Any CPU
{40973F13-3339-4548-9008-FF76A0C8CD79}.Release|Any CPU.ActiveCfg = Release|Any CPU
{40973F13-3339-4548-9008-FF76A0C8CD79}.Release|Any CPU.Build.0 = Release|Any CPU
{5AC53DF1-8152-466D-B7D0-238657F013F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5AC53DF1-8152-466D-B7D0-238657F013F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5AC53DF1-8152-466D-B7D0-238657F013F7}.NoFody|Any CPU.ActiveCfg = Debug|Any CPU
{5AC53DF1-8152-466D-B7D0-238657F013F7}.NoFody|Any CPU.Build.0 = Debug|Any CPU
{5AC53DF1-8152-466D-B7D0-238657F013F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5AC53DF1-8152-466D-B7D0-238657F013F7}.Release|Any CPU.Build.0 = Release|Any CPU
# {5AC53DF1-8152-466D-B7D0-238657F013F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
# {5AC53DF1-8152-466D-B7D0-238657F013F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
# {5AC53DF1-8152-466D-B7D0-238657F013F7}.NoFody|Any CPU.ActiveCfg = Debug|Any CPU
# {5AC53DF1-8152-466D-B7D0-238657F013F7}.NoFody|Any CPU.Build.0 = Debug|Any CPU
# {5AC53DF1-8152-466D-B7D0-238657F013F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
# {5AC53DF1-8152-466D-B7D0-238657F013F7}.Release|Any CPU.Build.0 = Release|Any CPU
{E8F288CB-51DF-4D9D-A3B3-A61BD4FD3F45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E8F288CB-51DF-4D9D-A3B3-A61BD4FD3F45}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E8F288CB-51DF-4D9D-A3B3-A61BD4FD3F45}.NoFody|Any CPU.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -181,18 +181,18 @@ Global
{1E87D2A5-7E36-4583-A533-064C97E330EE}.NoFody|Any CPU.Build.0 = Debug|Any CPU
{1E87D2A5-7E36-4583-A533-064C97E330EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1E87D2A5-7E36-4583-A533-064C97E330EE}.Release|Any CPU.Build.0 = Release|Any CPU
{D831728A-6328-4F96-9692-8FE64E0B0AAD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D831728A-6328-4F96-9692-8FE64E0B0AAD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D831728A-6328-4F96-9692-8FE64E0B0AAD}.NoFody|Any CPU.ActiveCfg = Debug|Any CPU
{D831728A-6328-4F96-9692-8FE64E0B0AAD}.NoFody|Any CPU.Build.0 = Debug|Any CPU
{D831728A-6328-4F96-9692-8FE64E0B0AAD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D831728A-6328-4F96-9692-8FE64E0B0AAD}.Release|Any CPU.Build.0 = Release|Any CPU
{B9678B78-A00D-4765-9380-B1DC4EFD642D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B9678B78-A00D-4765-9380-B1DC4EFD642D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B9678B78-A00D-4765-9380-B1DC4EFD642D}.NoFody|Any CPU.ActiveCfg = Debug|Any CPU
{B9678B78-A00D-4765-9380-B1DC4EFD642D}.NoFody|Any CPU.Build.0 = Debug|Any CPU
{B9678B78-A00D-4765-9380-B1DC4EFD642D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B9678B78-A00D-4765-9380-B1DC4EFD642D}.Release|Any CPU.Build.0 = Release|Any CPU
# {D831728A-6328-4F96-9692-8FE64E0B0AAD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
# {D831728A-6328-4F96-9692-8FE64E0B0AAD}.Debug|Any CPU.Build.0 = Debug|Any CPU
# {D831728A-6328-4F96-9692-8FE64E0B0AAD}.NoFody|Any CPU.ActiveCfg = Debug|Any CPU
# {D831728A-6328-4F96-9692-8FE64E0B0AAD}.NoFody|Any CPU.Build.0 = Debug|Any CPU
# {D831728A-6328-4F96-9692-8FE64E0B0AAD}.Release|Any CPU.ActiveCfg = Release|Any CPU
# {D831728A-6328-4F96-9692-8FE64E0B0AAD}.Release|Any CPU.Build.0 = Release|Any CPU
# {B9678B78-A00D-4765-9380-B1DC4EFD642D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
# {B9678B78-A00D-4765-9380-B1DC4EFD642D}.Debug|Any CPU.Build.0 = Debug|Any CPU
# {B9678B78-A00D-4765-9380-B1DC4EFD642D}.NoFody|Any CPU.ActiveCfg = Debug|Any CPU
# {B9678B78-A00D-4765-9380-B1DC4EFD642D}.NoFody|Any CPU.Build.0 = Debug|Any CPU
# {B9678B78-A00D-4765-9380-B1DC4EFD642D}.Release|Any CPU.ActiveCfg = Release|Any CPU
# {B9678B78-A00D-4765-9380-B1DC4EFD642D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -209,8 +209,8 @@ Global
{8BA9007B-9707-46F3-9836-F93C99F8C0C7} = {D89EF539-3EC6-4D07-9E98-65BC55F1DAA4}
{999025E8-C034-4A91-8166-5C2D95E9C9C3} = {F990372C-0580-4D69-89DC-A46A86396BBD}
{1E87D2A5-7E36-4583-A533-064C97E330EE} = {1ABC3725-EB8C-494E-8BA8-A991CE7BD7A1}
{D831728A-6328-4F96-9692-8FE64E0B0AAD} = {31380BF9-EC1C-4ABE-8A1A-A715B6DF024A}
{B9678B78-A00D-4765-9380-B1DC4EFD642D} = {31380BF9-EC1C-4ABE-8A1A-A715B6DF024A}
# {D831728A-6328-4F96-9692-8FE64E0B0AAD} = {31380BF9-EC1C-4ABE-8A1A-A715B6DF024A}
# {B9678B78-A00D-4765-9380-B1DC4EFD642D} = {31380BF9-EC1C-4ABE-8A1A-A715B6DF024A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {06095334-0BBD-4FDA-A230-272D08AFB221}
Expand Down

0 comments on commit a32f7d5

Please sign in to comment.