Skip to content

Commit

Permalink
Add some [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.A…
Browse files Browse the repository at this point in the history
…ll)] annotations (#839)

* ...

* [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]

* <!--<IsTrimmable>true</IsTrimmable>-->

* fix

* fix ca

* 5

* fx

* fixed some warnings

* .

* .
  • Loading branch information
StefH committed Aug 26, 2024
1 parent 206e7ae commit c29a341
Show file tree
Hide file tree
Showing 35 changed files with 793 additions and 577 deletions.
19 changes: 19 additions & 0 deletions System.Linq.Dynamic.Core.sln
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Linq.Dynamic.Core.Te
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WasmDynamicLinq", "src-blazor\WasmDynamicLinq\WasmDynamicLinq.csproj", "{2DE2052F-0A50-40C7-B6FF-52B52386BF9A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SldcTrimmer", "src-examples\SldcTrimmer\SldcTrimmer.csproj", "{7A31366C-DD98-41A3-A0C1-A97068BD9658}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -913,6 +915,22 @@ Global
{2DE2052F-0A50-40C7-B6FF-52B52386BF9A}.Release|x64.Build.0 = Release|Any CPU
{2DE2052F-0A50-40C7-B6FF-52B52386BF9A}.Release|x86.ActiveCfg = Release|Any CPU
{2DE2052F-0A50-40C7-B6FF-52B52386BF9A}.Release|x86.Build.0 = Release|Any CPU
{7A31366C-DD98-41A3-A0C1-A97068BD9658}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7A31366C-DD98-41A3-A0C1-A97068BD9658}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7A31366C-DD98-41A3-A0C1-A97068BD9658}.Debug|ARM.ActiveCfg = Debug|Any CPU
{7A31366C-DD98-41A3-A0C1-A97068BD9658}.Debug|ARM.Build.0 = Debug|Any CPU
{7A31366C-DD98-41A3-A0C1-A97068BD9658}.Debug|x64.ActiveCfg = Debug|Any CPU
{7A31366C-DD98-41A3-A0C1-A97068BD9658}.Debug|x64.Build.0 = Debug|Any CPU
{7A31366C-DD98-41A3-A0C1-A97068BD9658}.Debug|x86.ActiveCfg = Debug|Any CPU
{7A31366C-DD98-41A3-A0C1-A97068BD9658}.Debug|x86.Build.0 = Debug|Any CPU
{7A31366C-DD98-41A3-A0C1-A97068BD9658}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7A31366C-DD98-41A3-A0C1-A97068BD9658}.Release|Any CPU.Build.0 = Release|Any CPU
{7A31366C-DD98-41A3-A0C1-A97068BD9658}.Release|ARM.ActiveCfg = Release|Any CPU
{7A31366C-DD98-41A3-A0C1-A97068BD9658}.Release|ARM.Build.0 = Release|Any CPU
{7A31366C-DD98-41A3-A0C1-A97068BD9658}.Release|x64.ActiveCfg = Release|Any CPU
{7A31366C-DD98-41A3-A0C1-A97068BD9658}.Release|x64.Build.0 = Release|Any CPU
{7A31366C-DD98-41A3-A0C1-A97068BD9658}.Release|x86.ActiveCfg = Release|Any CPU
{7A31366C-DD98-41A3-A0C1-A97068BD9658}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -965,6 +983,7 @@ Global
{B01B327C-FC68-49B6-BDE3-A13D0C66DF5C} = {7971CAEB-B9F2-416B-966D-2D697C4C1E62}
{7AFC2836-0F6E-4B0D-8BB3-13317A3B6616} = {8463ED7E-69FB-49AE-85CF-0791AFD98E38}
{2DE2052F-0A50-40C7-B6FF-52B52386BF9A} = {122BC4FA-7563-4E35-9D17-077F16F1629F}
{7A31366C-DD98-41A3-A0C1-A97068BD9658} = {BCA2A024-9032-4E56-A6C4-17A15D921728}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {94C56722-194E-4B8B-BC23-B3F754E89A20}
Expand Down
1 change: 1 addition & 0 deletions System.Linq.Dynamic.Core.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IL/@EntryIndexedValue">IL</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=UTC/@EntryIndexedValue">UTC</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=WASM/@EntryIndexedValue">WASM</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Corelib/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=DLL_0027s/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Formattable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ilgenerator/@EntryIndexedValue">True</s:Boolean>
Expand Down
13 changes: 13 additions & 0 deletions src-examples/SldcTrimmer/Color.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace SldcTrimmer
{
internal class Color
{
public byte Alpha { get; set; }
public byte Red { get; set; }
public byte Green { get; set; }
public byte Blue { get; set; }
public float Hue { get; set; }
public float Saturation { get; set; }
public float Brightness { get; set; }
}
}
13 changes: 13 additions & 0 deletions src-examples/SldcTrimmer/LambdaExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Linq.Dynamic.Core;

namespace SldcTrimmer
{
internal static class LambdaExtensions
{
public static Func<T1, T2> ParseLambda<T1, T2>(this string expression)
{
return DynamicExpressionParser.ParseLambda<T1, T2>(null, false, expression).Compile();
}
}
}
32 changes: 32 additions & 0 deletions src-examples/SldcTrimmer/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;

namespace SldcTrimmer
{
class Program
{
static void Main(string[] args)
{
try
{
const string filterStr = "Alpha == 255";
Console.WriteLine(filterStr);

var filter = filterStr.ParseLambda<Color, bool>();

var color1 = new Color { Alpha = 255 };
var value1 = filter(color1);
Console.WriteLine($"{color1.Alpha} -> {value1}");

var color2 = new Color { Alpha = 128 };
var value2 = filter(color2);
Console.WriteLine($"{color2.Alpha} -> {value2}");
}
catch (Exception e)
{
Console.WriteLine(e.GetType());
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>C:\temp\x</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId>
<TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
<PublishReadyToRun>true</PublishReadyToRun>
</PropertyGroup>
</Project>
22 changes: 22 additions & 0 deletions src-examples/SldcTrimmer/SldcTrimmer.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<PropertyGroup>
<PublishTrimmed>true</PublishTrimmed>
<TrimMode>full</TrimMode>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\System.Linq.Dynamic.Core\System.Linq.Dynamic.Core.csproj" />
</ItemGroup>

<ItemGroup>
<!--<PackageReference Include="System.Linq.Dynamic.Core" Version="1.4.5" />-->
<TrimmerRootAssembly Include="System.Linq.Dynamic.Core" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/System.Linq.Dynamic.Core/AnyOfTypes/AnyOfTypes.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ namespace AnyOfTypes
{
internal enum AnyOfType
{
Undefined = 0, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth, Tenth
Undefined = 0, First, Second
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#if !NET6_0_OR_GREATER

// ReSharper disable once CheckNamespace
namespace System.Diagnostics.CodeAnalysis;

//
// Summary:
// Specifies the types of members that are dynamically accessed. This enumeration
// has a System.FlagsAttribute attribute that allows a bitwise combination of its
// member values.
[Flags]
internal enum DynamicallyAccessedMemberTypes
{
//
// Summary:
// Specifies all members.
All = -1,
//
// Summary:
// Specifies no members.
None = 0,
//
// Summary:
// Specifies the default, parameterless public constructor.
PublicParameterlessConstructor = 1,
//
// Summary:
// Specifies all public constructors.
PublicConstructors = 3,
//
// Summary:
// Specifies all non-public constructors.
NonPublicConstructors = 4,
//
// Summary:
// Specifies all public methods.
PublicMethods = 8,
//
// Summary:
// Specifies all non-public methods.
NonPublicMethods = 16,
//
// Summary:
// Specifies all public fields.
PublicFields = 32,
//
// Summary:
// Specifies all non-public fields.
NonPublicFields = 64,
//
// Summary:
// Specifies all public nested types.
PublicNestedTypes = 128,
//
// Summary:
// Specifies all non-public nested types.
NonPublicNestedTypes = 256,
//
// Summary:
// Specifies all public properties.
PublicProperties = 512,
//
// Summary:
// Specifies all non-public properties.
NonPublicProperties = 1024,
//
// Summary:
// Specifies all public events.
PublicEvents = 2048,
//
// Summary:
// Specifies all non-public events.
NonPublicEvents = 4096,
//
// Summary:
// Specifies all interfaces implemented by the type.
Interfaces = 8192
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#if !NET6_0_OR_GREATER

// ReSharper disable once CheckNamespace
namespace System.Diagnostics.CodeAnalysis;

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Interface | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, Inherited = false)]
internal sealed class DynamicallyAccessedMembersAttribute : Attribute
{
public DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes memberTypes)
{
MemberTypes = memberTypes;
}

public DynamicallyAccessedMemberTypes MemberTypes { get; }
}
#endif
Loading

0 comments on commit c29a341

Please sign in to comment.