Skip to content
Closed
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
10 changes: 8 additions & 2 deletions csharp/src/Google.Protobuf/Collections/RepeatedField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,13 @@ private unsafe bool TryGetArrayAsSpanPinnedUnsafe(FieldCodec<T> codec, out Span<
// 1. protobuf wire bytes is LittleEndian only
// 2. validate that size of csharp element T is matching the size of protobuf wire size
// NOTE: cannot use bool with this span because csharp marshal it as 4 bytes
if (BitConverter.IsLittleEndian && (codec.FixedSize > 0 && Marshal.SizeOf(typeof(T)) == codec.FixedSize))
if (BitConverter.IsLittleEndian && (codec.FixedSize > 0 &&
#if GOOGLE_PROTOBUF_SUPPORT_GENERIC_SIZEOF
Marshal.SizeOf<T>()
#else
Marshal.SizeOf(typeof(T))
#endif
== codec.FixedSize))
{
handle = GCHandle.Alloc(array, GCHandleType.Pinned);
span = new Span<byte>(handle.AddrOfPinnedObject().ToPointer(), array.Length * codec.FixedSize);
Expand Down Expand Up @@ -772,4 +778,4 @@ public RepeatedFieldDebugView(RepeatedField<T> list)
public T[] Items => list.ToArray();
}
}
}
}
6 changes: 3 additions & 3 deletions csharp/src/Google.Protobuf/Google.Protobuf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
<IsTrimmable>true</IsTrimmable>
<!-- Disable warnings about AOT and trimming features on older targets, e.g. netstandard2.0.
For now, continue to apply these features to these targets because some packages don't have a target that supports them -->
<NoWarn>$(NoWarn);NETSDK1195;NETSDK1210</NoWarn>
<NoWarn>$(NoWarn);NETSDK1195;NETSDK1210</NoWarn>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<DefineConstants>$(DefineConstants);GOOGLE_PROTOBUF_SUPPORT_FAST_STRING</DefineConstants>
<DefineConstants>$(DefineConstants);GOOGLE_PROTOBUF_SUPPORT_FAST_STRING;GOOGLE_PROTOBUF_SUPPORT_GENERIC_SIZEOF</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net50' ">
<DefineConstants>$(DefineConstants);GOOGLE_PROTOBUF_SUPPORT_FAST_STRING;GOOGLE_PROTOBUF_SIMD</DefineConstants>
<DefineConstants>$(DefineConstants);GOOGLE_PROTOBUF_SUPPORT_FAST_STRING;GOOGLE_PROTOBUF_SUPPORT_GENERIC_SIZEOF;GOOGLE_PROTOBUF_SIMD</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading