Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

hahn-kev
Copy link
Contributor

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

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

Copy link

github-actions bot commented Oct 18, 2024

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
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.

Copy link
Contributor

@jasonleenaylor jasonleenaylor left a comment

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
Copy link
Contributor Author

hahn-kev commented Oct 19, 2024

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.

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