@@ -140,7 +140,7 @@ internal void CompleteExemplars(WritingSystems writingSystems)
140140 {
141141 if ( entry . CitationForm is not null )
142142 LcmHelpers . ContributeExemplars ( entry . CitationForm , wsExemplarsByHandle ) ;
143- if ( entry . LexemeFormOA is { Form : not null } )
143+ if ( entry . LexemeFormOA is { Form : not null } )
144144 LcmHelpers . ContributeExemplars ( entry . LexemeFormOA . Form , wsExemplarsByHandle ) ;
145145 }
146146
@@ -294,7 +294,7 @@ public IAsyncEnumerable<PartOfSpeech> GetPartsOfSpeech()
294294 ? FromLcmPartOfSpeech ( partOfSpeech ) : null ) ;
295295 }
296296
297- public async Task < PartOfSpeech > CreatePartOfSpeech ( PartOfSpeech partOfSpeech )
297+ public Task < PartOfSpeech > CreatePartOfSpeech ( PartOfSpeech partOfSpeech )
298298 {
299299 IPartOfSpeech ? lcmPartOfSpeech = null ;
300300 if ( partOfSpeech . Id == default ) partOfSpeech . Id = Guid . NewGuid ( ) ;
@@ -307,7 +307,8 @@ public async Task<PartOfSpeech> CreatePartOfSpeech(PartOfSpeech partOfSpeech)
307307 . Create ( partOfSpeech . Id , Cache . LangProject . PartsOfSpeechOA ) ;
308308 UpdateLcmMultiString ( lcmPartOfSpeech . Name , partOfSpeech . Name ) ;
309309 } ) ;
310- return FromLcmPartOfSpeech ( lcmPartOfSpeech ?? throw new InvalidOperationException ( "Part of speech was not created" ) ) ;
310+ return Task . FromResult ( FromLcmPartOfSpeech (
311+ lcmPartOfSpeech ?? throw new InvalidOperationException ( "Part of speech was not created" ) ) ) ;
311312 }
312313
313314 public Task < PartOfSpeech > UpdatePartOfSpeech ( Guid id , UpdateObjectInput < PartOfSpeech > update )
@@ -351,19 +352,20 @@ public async Task<Publication> CreatePublication(Publication pub)
351352 UpdateLcmMultiString ( lcmPublication . Name , pub . Name ) ;
352353 }
353354 ) ;
354- return await Task . FromResult ( FromLcmPossibility ( lcmPublication ?? throw new InvalidOperationException ( "Failed to create publication" ) ) ) ;
355+ return await Task . FromResult ( FromLcmPossibility (
356+ lcmPublication ?? throw new InvalidOperationException ( "Failed to create publication" ) ) ) ;
355357 }
356358
357- private Publication FromLcmPossibility ( ICmPossibility lcmPossibility )
359+ private Publication FromLcmPossibility ( ICmPossibility lcmPossibility )
358360 {
359- var possibility = new Publication
360- {
361- Id = lcmPossibility . Guid ,
362- Name = FromLcmMultiString ( lcmPossibility . Name )
363- } ;
361+ var possibility = new Publication
362+ {
363+ Id = lcmPossibility . Guid ,
364+ Name = FromLcmMultiString ( lcmPossibility . Name )
365+ } ;
364366
365- return possibility ;
366- }
367+ return possibility ;
368+ }
367369
368370 public Task < Publication > UpdatePublication ( Guid id , UpdateObjectInput < Publication > update )
369371 {
@@ -496,7 +498,7 @@ private ComplexFormType ToComplexFormType(ILexEntryType t)
496498 return new ComplexFormType ( ) { Id = t . Guid , Name = FromLcmMultiString ( t . Name ) } ;
497499 }
498500
499- public async Task < ComplexFormType > CreateComplexFormType ( ComplexFormType complexFormType )
501+ public Task < ComplexFormType > CreateComplexFormType ( ComplexFormType complexFormType )
500502 {
501503 if ( complexFormType . Id == default ) complexFormType . Id = Guid . NewGuid ( ) ;
502504 UndoableUnitOfWorkHelper . DoUsingNewOrCurrentUOW ( "Create complex form type" ,
@@ -510,7 +512,7 @@ public async Task<ComplexFormType> CreateComplexFormType(ComplexFormType complex
510512 ComplexFormTypes . PossibilitiesOS . Add ( lexComplexFormType ) ;
511513 UpdateLcmMultiString ( lexComplexFormType . Name , complexFormType . Name ) ;
512514 } ) ;
513- return ToComplexFormType ( ComplexFormTypesFlattened . Single ( c => c . Guid == complexFormType . Id ) ) ;
515+ return Task . FromResult ( ToComplexFormType ( ComplexFormTypesFlattened . Single ( c => c . Guid == complexFormType . Id ) ) ) ;
514516 }
515517
516518 public Task < ComplexFormType > UpdateComplexFormType ( Guid id , UpdateObjectInput < ComplexFormType > update )
@@ -657,9 +659,9 @@ private Entry FromLexEntry(ILexEntry entry)
657659 CitationForm = FromLcmMultiString ( entry . CitationForm ) ,
658660 LiteralMeaning = FromLcmMultiString ( entry . LiteralMeaning ) ,
659661 MorphType = LcmHelpers . FromLcmMorphType ( entry . PrimaryMorphType ) , // TODO: Decide what to do about entries with *mixed* morph types
660- Senses = entry . AllSenses . Select ( FromLexSense ) . ToList ( ) ,
662+ Senses = [ .. entry . AllSenses . Select ( FromLexSense ) ] ,
661663 ComplexFormTypes = ToComplexFormTypes ( entry ) ,
662- Components = ToComplexFormComponents ( entry ) . ToList ( ) ,
664+ Components = [ .. ToComplexFormComponents ( entry ) ] ,
663665 ComplexForms = [
664666 ..entry . ComplexFormEntries . Select ( complexEntry => ToEntryReference ( entry , complexEntry ) ) ,
665667 ..entry . AllSenses . SelectMany ( sense => sense . ComplexFormEntries . Select ( complexEntry => ToSenseReference ( sense , complexEntry ) ) )
@@ -747,7 +749,7 @@ private ComplexFormComponent ToSenseReference(ILexSense componentSense, ILexEntr
747749
748750 private static int Order ( ICmObject component , ILexEntry complexEntry )
749751 {
750- int order = 0 ;
752+ var order = 0 ;
751753 foreach ( var entryRef in complexEntry . ComplexFormEntryRefs )
752754 {
753755 var foundIndex = entryRef . ComponentLexemesRS . IndexOf ( component ) ;
@@ -768,16 +770,16 @@ private static int Order(ICmObject component, ILexEntry complexEntry)
768770 private Sense FromLexSense ( ILexSense sense )
769771 {
770772 var pos = sense . MorphoSyntaxAnalysisRA ? . GetPartOfSpeech ( ) ;
771- var s = new Sense
773+ var s = new Sense
772774 {
773775 Id = sense . Guid ,
774776 EntryId = sense . Entry . Guid ,
775777 Gloss = FromLcmMultiString ( sense . Gloss ) ,
776778 Definition = FromLcmMultiString ( sense . Definition ) ,
777779 PartOfSpeech = pos is null ? null : FromLcmPartOfSpeech ( pos ) ,
778780 PartOfSpeechId = pos ? . Guid ,
779- SemanticDomains = sense . SemanticDomainsRC . Select ( FromLcmSemanticDomain ) . ToList ( ) ,
780- ExampleSentences = sense . ExamplesOS . Select ( sentence => FromLexExampleSentence ( sense . Guid , sentence ) ) . ToList ( )
781+ SemanticDomains = [ .. sense . SemanticDomainsRC . Select ( FromLcmSemanticDomain ) ] ,
782+ ExampleSentences = [ .. sense . ExamplesOS . Select ( sentence => FromLexExampleSentence ( sense . Guid , sentence ) ) ]
781783 } ;
782784 return s ;
783785 }
@@ -791,13 +793,13 @@ private ExampleSentence FromLexExampleSentence(Guid senseGuid, ILexExampleSenten
791793 SenseId = senseGuid ,
792794 Sentence = FromLcmMultiString ( sentence . Example ) ,
793795 Reference = ToRichString ( sentence . Reference ) ,
794- Translation = translation is null ? new ( ) : FromLcmMultiString ( translation ) ,
796+ Translation = translation is null ? [ ] : FromLcmMultiString ( translation ) ,
795797 } ;
796798 }
797799
798800 private MultiString FromLcmMultiString ( ITsMultiString ? multiString )
799801 {
800- if ( multiString is null ) return new MultiString ( ) ;
802+ if ( multiString is null ) return [ ] ;
801803 var result = new MultiString ( multiString . StringCount ) ;
802804 for ( var i = 0 ; i < multiString . StringCount ; i ++ )
803805 {
@@ -852,7 +854,7 @@ private string ToMediaUri(string tsString)
852854 internal string FromMediaUri ( string mediaUriString )
853855 {
854856 //path includes `AudioVisual` currently
855- MediaUri mediaUri = new MediaUri ( mediaUriString ) ;
857+ var mediaUri = new MediaUri ( mediaUriString ) ;
856858 var path = mediaAdapter . PathFromMediaUri ( mediaUri , Cache ) ;
857859 if ( path is null ) throw new NotFoundException ( $ "Unable to find file { mediaUri . FileId } .", nameof ( MediaFile ) ) ;
858860 return Path . GetRelativePath ( Path . Join ( Cache . LangProject . LinkedFilesRootDir , AudioVisualFolder ) , path ) ;
@@ -1175,11 +1177,8 @@ internal void RemoveComplexFormComponent(ILexEntry lexEntry, ComplexFormComponen
11751177 internal void AddComplexFormType ( ILexEntry lexEntry , Guid complexFormTypeId )
11761178 {
11771179 //do the same thing as LCM, use the first when adding if there's more than one
1178- ILexEntryRef ? entryRef = lexEntry . ComplexFormEntryRefs . FirstOrDefault ( ) ;
1179- if ( entryRef is null )
1180- {
1181- entryRef = AddComplexFormLexEntryRef ( lexEntry ) ;
1182- }
1180+ var entryRef = lexEntry . ComplexFormEntryRefs . FirstOrDefault ( )
1181+ ?? AddComplexFormLexEntryRef ( lexEntry ) ;
11831182
11841183 var lexEntryType = ComplexFormTypesFlattened . Single ( c => c . Guid == complexFormTypeId ) ;
11851184 entryRef . ComplexEntryTypesRS . Add ( lexEntryType ) ;
@@ -1429,7 +1428,7 @@ private void ApplySenseToLexSense(Sense sense, ILexSense lexSense)
14291428 return Task . FromResult ( lcmSense is null ? null : FromLexSense ( lcmSense ) ) ;
14301429 }
14311430
1432- public async Task < Sense > CreateSense ( Guid entryId , Sense sense , BetweenPosition ? between = null )
1431+ public Task < Sense > CreateSense ( Guid entryId , Sense sense , BetweenPosition ? between = null )
14331432 {
14341433 if ( sense . Id == default ) sense . Id = Guid . NewGuid ( ) ;
14351434 if ( ! EntriesRepository . TryGetObject ( entryId , out var lexEntry ) )
@@ -1438,7 +1437,7 @@ public async Task<Sense> CreateSense(Guid entryId, Sense sense, BetweenPosition?
14381437 "Remove sense" ,
14391438 Cache . ServiceLocator . ActionHandler ,
14401439 ( ) => CreateSense ( lexEntry , sense , between ) ) ;
1441- return FromLexSense ( SenseRepository . GetObject ( sense . Id ) ) ;
1440+ return Task . FromResult ( FromLexSense ( SenseRepository . GetObject ( sense . Id ) ) ) ;
14421441 }
14431442
14441443 public Task < Sense > UpdateSense ( Guid entryId , Guid senseId , UpdateObjectInput < Sense > update )
@@ -1574,7 +1573,7 @@ public ICmTranslation CreateExampleSentenceTranslation(ILexExampleSentence paren
15741573 return CmTranslationFactory . Create ( parent , freeTranslationType ) ;
15751574 }
15761575
1577- public async Task < ExampleSentence > CreateExampleSentence ( Guid entryId , Guid senseId , ExampleSentence exampleSentence , BetweenPosition ? between = null )
1576+ public Task < ExampleSentence > CreateExampleSentence ( Guid entryId , Guid senseId , ExampleSentence exampleSentence , BetweenPosition ? between = null )
15781577 {
15791578 if ( exampleSentence . Id == default ) exampleSentence . Id = Guid . NewGuid ( ) ;
15801579 if ( ! SenseRepository . TryGetObject ( senseId , out var lexSense ) )
@@ -1583,7 +1582,8 @@ public async Task<ExampleSentence> CreateExampleSentence(Guid entryId, Guid sens
15831582 "Remove example sentence" ,
15841583 Cache . ServiceLocator . ActionHandler ,
15851584 ( ) => CreateExampleSentence ( lexSense , exampleSentence , between ) ) ;
1586- return FromLexExampleSentence ( senseId , ExampleSentenceRepository . GetObject ( exampleSentence . Id ) ) ;
1585+ return Task . FromResult (
1586+ FromLexExampleSentence ( senseId , ExampleSentenceRepository . GetObject ( exampleSentence . Id ) ) ) ;
15871587 }
15881588
15891589 public Task < ExampleSentence > UpdateExampleSentence ( Guid entryId ,
@@ -1672,7 +1672,7 @@ public Task<ReadFileResponse> GetFileStream(MediaUri mediaUri)
16721672 if ( mediaUri == MediaUri . NotFound ) return Task . FromResult ( new ReadFileResponse ( ReadFileResult . NotFound ) ) ;
16731673 var pathFromMediaUri = mediaAdapter . PathFromMediaUri ( mediaUri , Cache ) ;
16741674 if ( pathFromMediaUri is not { Length : > 0 } ) return Task . FromResult ( new ReadFileResponse ( ReadFileResult . NotFound ) ) ;
1675- string fullPath = Path . Combine ( Cache . LangProject . LinkedFilesRootDir , pathFromMediaUri ) ;
1675+ var fullPath = Path . Combine ( Cache . LangProject . LinkedFilesRootDir , pathFromMediaUri ) ;
16761676 if ( ! File . Exists ( fullPath ) ) return Task . FromResult ( new ReadFileResponse ( ReadFileResult . NotFound ) ) ;
16771677 return Task . FromResult ( new ReadFileResponse ( File . OpenRead ( fullPath ) , Path . GetFileName ( fullPath ) ) ) ;
16781678 }
0 commit comments