diff --git a/src/LibProtodec/AssemblyInspector.cs b/src/LibProtodec/AssemblyInspector.cs index c9ebcbe..cfd2878 100644 --- a/src/LibProtodec/AssemblyInspector.cs +++ b/src/LibProtodec/AssemblyInspector.cs @@ -35,7 +35,8 @@ public sealed class AssemblyInspector : IDisposable public IEnumerable GetProtobufMessageTypes() { - Type? googleProtobufIMessage = AssemblyContext.LoadFromAssemblyName("Google.Protobuf") + Type? googleProtobufIMessage = LoadedTypes.SingleOrDefault(static type => type?.FullName == "Google.Protobuf.IMessage", null) + ?? AssemblyContext.LoadFromAssemblyName("Google.Protobuf") .GetType("Google.Protobuf.IMessage"); return from type in LoadedTypes @@ -58,7 +59,7 @@ public sealed class AssemblyInspector : IDisposable { public readonly IReadOnlyDictionary AssemblyPathLookup = assemblyPaths.ToDictionary( - path => Path.GetFileNameWithoutExtension(path), + static path => Path.GetFileNameWithoutExtension(path), StringComparer.OrdinalIgnoreCase); /// diff --git a/src/LibProtodec/Message.cs b/src/LibProtodec/Message.cs index 4fb5c71..75b58ae 100644 --- a/src/LibProtodec/Message.cs +++ b/src/LibProtodec/Message.cs @@ -44,7 +44,7 @@ public sealed class Message : Protobuf writer.WriteLine(" {"); writer.Indent++; - int[] oneOfs = OneOfs.SelectMany(oneOf => oneOf.Value).ToArray(); + int[] oneOfs = OneOfs.SelectMany(static oneOf => oneOf.Value).ToArray(); foreach ((int fieldId, (bool, string, string) field) in Fields) { diff --git a/src/LibProtodec/ProtodecContext.cs b/src/LibProtodec/ProtodecContext.cs index d98585e..c754c86 100644 --- a/src/LibProtodec/ProtodecContext.cs +++ b/src/LibProtodec/ProtodecContext.cs @@ -104,8 +104,8 @@ public sealed class ProtodecContext { string oneOfName = TranslateOneOfName(property.Name); int[] oneOfProtoFieldIds = propertyType.GetFields(BindingFlags.Public | BindingFlags.Static) - .Select(field => (int)field.GetRawConstantValue()!) - .Where(id => id > 0) + .Select(static field => (int)field.GetRawConstantValue()!) + .Where(static id => id > 0) .ToArray(); message.OneOfs.Add(oneOfName, oneOfProtoFieldIds); @@ -242,7 +242,7 @@ public sealed class ProtodecContext private string TranslateEnumFieldName(FieldInfo field, string enumName) { if (field.GetCustomAttributesData() - .SingleOrDefault(attr => attr.AttributeType.Name == "OriginalNameAttribute") + .SingleOrDefault(static attr => attr.AttributeType.Name == "OriginalNameAttribute") ?.ConstructorArguments[0] .Value is string originalName) @@ -280,6 +280,6 @@ public sealed class ProtodecContext private static bool HasProtocAttribute(MemberInfo member) => member.GetCustomAttributesData() - .Any(attr => attr.AttributeType.Name == nameof(GeneratedCodeAttribute) - && attr.ConstructorArguments[0].Value as string == "protoc"); + .Any(static attr => attr.AttributeType.Name == nameof(GeneratedCodeAttribute) + && attr.ConstructorArguments[0].Value as string == "protoc"); } \ No newline at end of file