Repository navigation
feat: bind dictionary, ExpandoObject and DynamicObject rows by key (#361) - #507
Open
michaelstonis wants to merge 4 commits into
Open
michaelstonis wants to merge 4 commits into
michaelstonis wants to merge 4 commits into
Conversation
|
|
||
| Assert.True(CommitText(source, 0, "", out _)); | ||
|
|
||
| Assert.True(row.ContainsKey("Qty")); |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #361.
Changes
Rows held as dictionaries,
ExpandoObjector aDynamicObjectproperty bag used to show blank cells. They now display, sort, filter, group, summarize and edit by key with no app code. This is Track B stage 1 of spec #107, plus theDynamicObjectandFromDictionariesparts of stage 2.Built-in row providers (
KumikoUI.Core.Data)KumikoDictionaryAccessorProvider(public,Instancesingleton, internal constructor) handles three row shapes, checked in this order:IDictionary<string, object?>, which coversDictionary,ExpandoObjectand the concurrent and sorted dictionaries.IReadOnlyDictionary<string, object?>, read-only.IDictionarywith string keys, such asHashtableor a boxedDictionary<string, int>.OrdinalIgnoreCasescan. The scan is skipped when the dictionary's comparer already ignores case, and it allocates nothing forDictionary<string, object?>.object. Dotted paths read through nested dictionaries.KumikoDynamicObjectAccessorProvidercallsDynamicObject.TryGetMember/TrySetMemberdirectly. It uses two small privateGetMemberBinder/SetMemberBindersubclasses whoseFallback*methods throw. There is noCallSite, noMicrosoft.CSharpand no dynamic code.GetDynamicMemberNames()ignoring case.dynamic, a CLR property of the row type wins when reflection can see it.KumikoAccessorRegistryresolves in this order: type providers (Register,[KumikoGridItem]), thenAddProviderproviders, then the dictionary provider, then theDynamicObjectprovider, then reflection.DictionaryRowsSwitchName("KumikoUI.Core.IsDictionaryRowAccessSupported") andIsDictionaryRowAccessSupported([FeatureSwitchDefinition]). The switch is on by default, which answers Spec: paging and DataTable / dictionary / dynamic row sources #107 Q1 as the spec proposes.buildTransitive/KumikoUI.Core.targetsmaps theKumikoDictionaryRowAccessMSBuild property to that switch, the same way the reflection switch is wired.DynamicObjectIDynamicMetaObjectProvidertraces a one-time warning that names the alternatives.Why
DynamicObjectsupport is on by default and not an opt-in: the framework marks theGetMemberBinder/SetMemberBinderconstructors (andDynamicObject's own constructor)[RequiresDynamicCode], because a binder normally builds a call site. These binders never reach one. They only carry the member name into ordinary virtual calls, and the constructors only store the name. So the two binder constructors carry a narrowly justified[UnconditionalSuppressMessage("AOT", "IL3050")], and the library stays free of warnings.eng/AotSmokereads and writes aDynamicObjectrow in a Native AOT publish (TrimMode=full, warnings as errors), and the binary runs and passes.[RequiresDynamicCode]would have pushed a warning onto every AOT app, even though the path works.DynamicObjectrow type gets IL3050 from the framework'sDynamicObjectconstructor in its own code. The README says so, and the smoke app shows how to suppress it.KumikoColumn.ValueType(Type?)object.KumikoValuePath.TrySetValuehas a new overload that takes it. For an object-typed slot, the target isValueType, else the runtime type of the current value, else the value is stored raw. Null is always stored as-is.KumikoSource.TrySetItemValuepasses the column'sValueType.EditSession.TargetTypeuses this order: declared type (if notobject), thenValueType, then the original value's type, then the column-type default.KumikoColumnFactory.FromDictionaries(IEnumerable<object?> rows, int sampleSize = 100)DynamicObjectrows, in first-seen order. Other rows and null rows are skipped.Create(KumikoColumnMetadata)mapping, so it matches generated columns (Columns: auto-generate columns from the item type, with DataAnnotations and an AOT-safe source-generator path #315).ValueTypeis left null.Other changes
bench/KumikoUI.Benchmarks/DictionaryRowBenchmarks.cs(Spec: paging and DataTable / dictionary / dynamic row sources #107 section 8.9).CHANGELOG.mdentry, and new rows insamples/README.mdandbench/README.md.samples/Shared/DictionaryRowsData.cs). It hasDictionaryandExpandoObjectrows, columns fromFromDictionarieswithValueTypeand format adjustments, and a button that adds a key at run time.ValueTypelives onKumikoColumn, so both hosts' XAML can set it.Public API added (
PublicAPI.Unshipped.txt)KumikoDictionaryAccessorProvider,.Instance,.GetAccessor(Type, string)KumikoDynamicObjectAccessorProvider,.Instance,.GetAccessor(Type, string)KumikoAccessorRegistry.DictionaryRowsSwitchName,KumikoAccessorRegistry.IsDictionaryRowAccessSupportedKumikoColumn.ValueTypeKumikoColumnFactory.FromDictionaries(IEnumerable<object?>, int)Decisions
[user.name]): not implemented. Keys with dots need aValueAccessor, and the docs say so.PropertyName="Count"now reads the entry"Count"rather than the dictionary'sCountproperty. To restore the old behavior, setKumikoDictionaryRowAccess=false, or register a provider for that type.Acceptance criteria
ExpandoObject,IReadOnlyDictionary, non-genericIDictionaryandDynamicObjectrows display, sort, filter, group, summarize and edit by key with no app provider. Covered by tests inDictionaryRowTestsand by the AOT smoke app.AddProvider, dictionary, reflection) and the opt-out switch are tested (Precedence_*,DictionaryRowSwitchTests.SwitchOff_*).ValueTypeconverts edited text in object-typed cells, and invalid text gives the converter's localized message (ValueType_*, throughEditSessionwith customKumikoStrings).KumikoColumnFactory.FromDictionariesinfers keys, order and types from heterogeneous rows (Dictionary,ExpandoObject,DynamicObject, nulls and non-rows in one list).tests/KumikoUI.Core.Tests/Data, including with reflection access off (DictionaryRowSwitchTests).eng/AotSmokedictionary case (Dictionary,ExpandoObject,DynamicObject,FromDictionaries, sort, edit, filter) publishes with no IL warnings, and the AOT binary runs and passes.FromDictionaries. Both sample apps build, but neither page was opened in a running app.PublicAPI.Unshipped.txtis updated: theeng/update-public-api.sh Corecode fix wrote nothing on this machine, so the RS0016 entries were added by hand and sorted the way the script sorts.Verification
dotnet build src/KumikoUI.Core(Debug and Release): succeeded, 0 warnings.dotnet build src/KumikoUI.SkiaSharp: succeeded.dotnet build src/KumikoUI.Maui -f net10.0-maccatalyst: succeeded.dotnet build src/KumikoUI.Uno -f net10.0-desktop: succeeded.dotnet test tests/KumikoUI.Core.Tests: 4394 passed, 5 skipped, 0 failed. This includes 33 new tests inDictionaryRowTestsandDictionaryRowSwitchTests.dotnet test tests/KumikoUI.SkiaSharp.Tests: 42 passed.dotnet publish eng/AotSmoke -c Release -r osx-arm64: no IL2xxx/IL3xxx warnings withTreatWarningsAsErrors. The binary printedAOT smoke OK. Linking neededLIBRARY_PATHpointing at Homebrew's openssl and brotli on this machine; that is a local toolchain setting, not part of this change.dotnet run --project eng/DocsSnippets -c Release, then:dotnet build tests/KumikoUI.Docs.Snippets.Uno -f net10.0-desktop -c Release: succeeded.dotnet build tests/KumikoUI.Docs.Snippets.Maui -f net10.0-maccatalyst -c Release: succeeded.dotnet build samples/SampleApp.Uno -f net10.0-desktop: succeeded.dotnet build samples/SampleApp.Maui -f net10.0-maccatalyst -p:KumikoDevFlow=false: succeeded. The default Debug build fails restore with NU1605 (the DevFlowMicrosoft.Maui.Controlsoverride). That failure was already there and is unrelated to this change.dotnet run --project eng/TypeNameCheck -c Release -- src/KumikoUI.Core/bin/Release/net10.0/KumikoUI.Core.dll: no collisions.dotnet run -c Release --project bench/KumikoUI.Benchmarks -- --filter '*DictionaryRowBenchmarks*' --job short(Apple M4 Max):