Skip to content

Commit 0cb6246

Browse files
authored
Remove UnsafeMemberAccess and Register methods
1 parent a5398a0 commit 0cb6246

29 files changed

+440
-804
lines changed

Fluid.Benchmarks/CompiledFluidBenchmarks.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ public class CompiledFluidBenchmarks : BaseBenchmarks
1111

1212
public CompiledFluidBenchmarks()
1313
{
14-
_options.MemberAccessStrategy.Register<Product>();
15-
_options.MemberAccessStrategy.MemberNameStrategy = MemberNameStrategies.CamelCase;
14+
_options.ModelNamesComparer = StringComparers.CamelCase;
1615
_parser.TryParse(ProductTemplate, out _fluidTemplate, out var _);
1716

1817
CheckBenchmark();

Fluid.Benchmarks/FluidBenchmarks.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ public class FluidBenchmarks : BaseBenchmarks
1212

1313
public FluidBenchmarks()
1414
{
15-
_options.MemberAccessStrategy.MemberNameStrategy = MemberNameStrategies.CamelCase;
16-
_options.MemberAccessStrategy.Register<Product>();
15+
_options.ModelNamesComparer = StringComparers.CamelCase;
1716
_parser.TryParse(ProductTemplate, out _fluidTemplate, out var _);
1817

1918
CheckBenchmark();

Fluid.Benchmarks/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Program
66
{
77
static void Main(string[] args)
88
{
9-
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
9+
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
1010
}
1111
}
1212
}

Fluid.MvcSample/Startup.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Fluid.MvcViewEngine;
1+
using Fluid.MvcViewEngine;
22
using Microsoft.AspNetCore.Builder;
33
using Microsoft.AspNetCore.Hosting;
44
using Microsoft.Extensions.DependencyInjection;
@@ -15,7 +15,6 @@ public void ConfigureServices(IServiceCollection services)
1515
services.Configure<FluidMvcViewOptions>(options =>
1616
{
1717
options.Parser = new CustomFluidViewParser(new FluidParserOptions());
18-
options.TemplateOptions.MemberAccessStrategy = UnsafeMemberAccessStrategy.Instance;
1918
});
2019

2120
services.AddMvc().AddFluid();

Fluid.MvcViewEngine/FluidRendering.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Fluid.ViewEngine;
1+
using Fluid.ViewEngine;
22
using Microsoft.AspNetCore.Hosting;
33
using Microsoft.AspNetCore.Mvc.ModelBinding;
44
using Microsoft.AspNetCore.Mvc.Rendering;
@@ -23,8 +23,6 @@ public FluidRendering(
2323
_hostingEnvironment = hostingEnvironment;
2424
_options = optionsAccessor.Value;
2525

26-
_options.TemplateOptions.MemberAccessStrategy.Register<ViewDataDictionary>();
27-
_options.TemplateOptions.MemberAccessStrategy.Register<ModelStateDictionary>();
2826
_options.TemplateOptions.FileProvider = _options.PartialsFileProvider ?? _hostingEnvironment.ContentRootFileProvider;
2927

3028
_fluidViewRenderer = new FluidViewRenderer(_options);

Fluid.Tests/ArrayFiltersTests.cs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ public async Task Map()
145145

146146
var options = new TemplateOptions();
147147
var context = new TemplateContext(options);
148-
options.MemberAccessStrategy.Register(new { Title = "a" }.GetType());
149148

150149
var result = await ArrayFilters.Map(input, arguments, context);
151150

@@ -169,8 +168,6 @@ public async Task Map_DeepProperties()
169168

170169
var options = new TemplateOptions();
171170
var context = new TemplateContext(options);
172-
options.MemberAccessStrategy.Register(sample.GetType());
173-
options.MemberAccessStrategy.Register(sample.Title.GetType());
174171

175172
var result = await ArrayFilters.Map(input, arguments, context);
176173

@@ -252,7 +249,6 @@ public async Task Sort()
252249

253250
var options = new TemplateOptions();
254251
var context = new TemplateContext(options);
255-
options.MemberAccessStrategy.Register(sample.GetType(), "Title");
256252

257253
var result = await ArrayFilters.Sort(input, arguments, context);
258254

@@ -264,9 +260,7 @@ public async Task Sort()
264260
arguments = new FilterArguments().Add(new StringValue("Address.Zip"));
265261

266262
options = new TemplateOptions();
267-
context = new TemplateContext(options);
268-
options.MemberAccessStrategy.Register(sample.GetType(), "Address");
269-
options.MemberAccessStrategy.Register(sample.Address.GetType(), "Zip");
263+
context = new TemplateContext(options);
270264

271265
result = await ArrayFilters.Sort(input, arguments, context);
272266

@@ -408,7 +402,6 @@ public async Task Where()
408402

409403
var options = new TemplateOptions();
410404
var context = new TemplateContext(options);
411-
options.MemberAccessStrategy.Register(new { Title = "a", Pinned = true }.GetType());
412405

413406
var arguments1 = new FilterArguments().Add(new StringValue("Pinned"));
414407

@@ -446,8 +439,6 @@ public async Task WhereWithTruthy()
446439

447440
var options = new TemplateOptions();
448441
var context = new TemplateContext(options);
449-
options.MemberAccessStrategy.Register(new { Title = "a", Pinned = true }.GetType());
450-
options.MemberAccessStrategy.Register(new { Title = "a", Pinned = true, Missing = 1 }.GetType());
451442

452443
// x | where: "Missing"
453444

@@ -494,7 +485,6 @@ public async Task WhereShouldNotThrow()
494485

495486
var options = new TemplateOptions();
496487
var context = new TemplateContext(options);
497-
options.MemberAccessStrategy.Register(new { Title = "a", Pinned = true }.GetType());
498488

499489
var arguments1 = new FilterArguments().Add(new StringValue("a.b.c"));
500490

@@ -518,7 +508,7 @@ public async Task Sum()
518508

519509
var options = new TemplateOptions();
520510
var context = new TemplateContext(options);
521-
options.MemberAccessStrategy.Register(sample.GetType(), "Value");
511+
//options.MemberAccessStrategy.Register(sample.GetType(), "Value");
522512

523513
var result = await ArrayFilters.Sum(input, arguments, context);
524514

@@ -713,11 +703,11 @@ public async Task SumWithDecimalsAndArguments(string filterArgument, decimal exp
713703

714704
var options = new TemplateOptions();
715705
var context = new TemplateContext(options);
716-
717-
options.MemberAccessStrategy.Register(quantityObjectType.GetType(), filterArgument);
718-
options.MemberAccessStrategy.Register(weightObjectType.GetType(), filterArgument);
719-
options.MemberAccessStrategy.Register(quantityAndWeightObjectType.GetType(), filterArgument);
720-
706+
707+
//options.MemberAccessStrategy.Register(quantityObjectType.GetType(), filterArgument);
708+
//options.MemberAccessStrategy.Register(weightObjectType.GetType(), filterArgument);
709+
//options.MemberAccessStrategy.Register(quantityAndWeightObjectType.GetType(), filterArgument);
710+
721711
var result = await ArrayFilters.Sum(input, arguments, context);
722712

723713
Assert.Equal(expectedValue, result.ToNumberValue());
@@ -734,7 +724,6 @@ public async Task Reject()
734724

735725
var options = new TemplateOptions();
736726
var context = new TemplateContext(options);
737-
options.MemberAccessStrategy.Register(new { Title = "a", Pinned = true }.GetType());
738727

739728
var arguments1 = new FilterArguments().Add(new StringValue("Pinned"));
740729

@@ -771,7 +760,6 @@ public async Task Find()
771760

772761
var options = new TemplateOptions();
773762
var context = new TemplateContext(options);
774-
options.MemberAccessStrategy.Register(new { Title = "a", Pinned = true }.GetType());
775763

776764
var arguments1 = new FilterArguments().Add(new StringValue("Pinned")).Add(BooleanValue.True);
777765

@@ -822,7 +810,6 @@ public async Task FindIndex()
822810

823811
var options = new TemplateOptions();
824812
var context = new TemplateContext(options);
825-
options.MemberAccessStrategy.Register(new { Title = "a", Pinned = true }.GetType());
826813

827814
var arguments1 = new FilterArguments().Add(new StringValue("Pinned")).Add(BooleanValue.True);
828815

@@ -873,7 +860,6 @@ public async Task Has()
873860

874861
var options = new TemplateOptions();
875862
var context = new TemplateContext(options);
876-
options.MemberAccessStrategy.Register(new { Title = "a", Pinned = true }.GetType());
877863

878864
var arguments1 = new FilterArguments().Add(new StringValue("Pinned")).Add(BooleanValue.True);
879865

Fluid.Tests/BinaryExpressionTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ public async Task ObjectValuesShouldCompareByValueNotReference()
296296
_parser.TryParse("{% if obj1 == obj2 %}equal{% else %}not equal{% endif %}", out var template, out var messages);
297297

298298
var context = new TemplateContext();
299-
context.Options.MemberAccessStrategy.Register<TestObject>();
300299
context.SetValue("obj1", obj1);
301300
context.SetValue("obj2", obj2);
302301

@@ -316,7 +315,6 @@ public async Task ArrayContainsShouldCompareByValueNotReference()
316315
_parser.TryParse("{% if array contains obj2 %}found{% else %}not found{% endif %}", out var template, out var messages);
317316

318317
var context = new TemplateContext();
319-
context.Options.MemberAccessStrategy.Register<TestObject>();
320318
context.SetValue("array", array);
321319
context.SetValue("obj2", obj2);
322320

0 commit comments

Comments
 (0)