Skip to content

Add T Create(Guid) to ILcmFactory<T>#313

Merged
hahn-kev merged 6 commits into
masterfrom
factory-create-with-guid
Nov 2, 2024
Merged

Add T Create(Guid) to ILcmFactory<T>#313
hahn-kev merged 6 commits into
masterfrom
factory-create-with-guid

Conversation

@hahn-kev

@hahn-kev hahn-kev commented Oct 18, 2024

Copy link
Copy Markdown
Contributor

Right now to make a given object with a specific GUID you need to use a specialized factory method, this PR adds a low lever API to make any object with a predefined GUID.

There was a conflict with ICmPictureFactory because it declared it's own version with the same signature which I then had to remove from the actual CmPictureFactory.


This change is Reviewable

@github-actions

github-actions Bot commented Oct 18, 2024

Copy link
Copy Markdown

LCM Tests

    16 files  ±0      16 suites  ±0   2m 52s ⏱️ ±0s
 2 828 tests +1   2 808 ✅ +1   20 💤 ±0  0 ❌ ±0 
11 260 runs  +4  11 081 ✅ +4  179 💤 ±0  0 ❌ ±0 

Results for commit 0808a6a. ± Comparison against base commit 93d7e90.

♻️ This comment has been updated with latest results.

@jasonleenaylor

Copy link
Copy Markdown
Contributor

src/SIL.LCModel/LcmGenerate/factory.vm.cs line 67 at r1 (raw file):

				throw new InvalidOperationException("Can not create more than one ${className}");
#end
			if (guid == Guid.Empty) guid = Guid.NewGuid();

Is this a real use case we want to support? I can't imagine a case where you want to create an unowned object with a guid that you don't know...
I'd throw instead.

@jasonleenaylor jasonleenaylor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So after looking at this and seeing that you only had to remove one I realized the more common pattern for this is the create which takes a Guid and an owner. It also you might something like that in practice. See the FactoryAdditions for LexRefTypeFactory for an example.

Reviewed 8 of 8 files at r1, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @hahn-kev)

@hahn-kev

hahn-kev commented Oct 19, 2024

Copy link
Copy Markdown
Contributor Author

src/SIL.LCModel/LcmGenerate/factory.vm.cs line 67 at r1 (raw file):

				throw new InvalidOperationException("Can not create more than one ${className}");
#end
			if (guid == Guid.Empty) guid = Guid.NewGuid();

Is this a real use case we want to support? I can't imagine a case where you want to create an unowned object with a guid that you don't know...
I'd throw instead.

Well I didn't support it originally (I threw as well), but the tests for ICmPicture had an explicit test for passing in an empty GUID. So in order to not break existing code I kept that test passing.

@jasonleenaylor jasonleenaylor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @hahn-kev)

@hahn-kev
hahn-kev enabled auto-merge (squash) November 2, 2024 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants