Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions Src/xWorks/ConfiguredLcmGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -744,9 +744,19 @@ private static bool GetPropValueForModelField(object fieldOwner, ConfigurableDic
}
// Convert the contents to IEnumerable<T>
var objects = contents.Select(id => cache.LangProject.Services.GetObject(id));
var type = objects.FirstOrDefault()?.GetType() ?? typeof(object);
var castMethod = typeof(Enumerable).GetMethod("Cast").MakeGenericMethod(type);
propertyValue = castMethod.Invoke(null, new object[] { objects });
var firstObjType = objects.FirstOrDefault()?.GetType();
// check that each item in objects can be cast to firstObjType
if (firstObjType != null && objects.All(o => firstObjType.IsInstanceOfType(o)))
{
var castMethod = typeof(Enumerable).GetMethod("Cast").MakeGenericMethod(firstObjType);
propertyValue = castMethod.Invoke(null, new object[] { objects });
}
else
{
var castMethod = typeof(Enumerable).GetMethod("Cast").MakeGenericMethod(typeof(object));
propertyValue = castMethod.Invoke(null, new object[] { objects });

}
break;
}
case (int)CellarPropertyType.ReferenceAtomic:
Expand Down Expand Up @@ -1575,7 +1585,7 @@ private static IFragment GenerateContentForCollection(object collectionField, Li
else
{
bool first = true;
foreach (var item in collection)
foreach (object item in collection)
{
frag.Append(GenerateCollectionItemContent(nodeList, pubDecorator, item, collectionOwner, settings, first));
first = false;
Expand Down
32 changes: 22 additions & 10 deletions Src/xWorks/xWorksTests/ConfiguredXHTMLGeneratorTestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -430,21 +430,33 @@ internal static ILexExampleSentence AddExampleToSense(ILexSense sense, string co
return example;
}

private IMoForm AddAllomorphToEntry(ILexEntry entry)
private IMoForm AddAllomorphToEntry(ILexEntry entry, bool stem = true)
{
var morphFact = Cache.ServiceLocator.GetInstance<IMoStemAllomorphFactory>();
var morph = morphFact.Create();
entry.AlternateFormsOS.Add(morph);
morph.Form.set_String(m_wsFr, TsStringUtils.MakeString("Allomorph", m_wsFr));

// add environment to the allomorph
const int stringRepresentationFlid = 5097008;
var env = Cache.ServiceLocator.GetInstance<IPhEnvironmentFactory>().Create();
Cache.LangProject.PhonologicalDataOA.EnvironmentsOS.Add(env);
morph.PhoneEnvRC.Add(env);
Cache.MainCacheAccessor.SetString(env.Hvo, stringRepresentationFlid, TsStringUtils.MakeString("phoneyEnv", m_wsEn));

return morph;
if (stem)
{
var morphFact = Cache.ServiceLocator.GetInstance<IMoStemAllomorphFactory>();
var morph = morphFact.Create();
entry.AlternateFormsOS.Add(morph);
morph.Form.set_String(m_wsFr, TsStringUtils.MakeString("StemAllomorph", m_wsFr));
// add environment to the stem allomorph (PhoneEnvRC is not in the common base class between stem and affix allomorphs)
morph.PhoneEnvRC.Add(env);
return morph;
}
else
{
// if not stem, then it is an affix allomorph
var morphFact = Cache.ServiceLocator.GetInstance<IMoAffixAllomorphFactory>();
var morph = morphFact.Create();
entry.AlternateFormsOS.Add(morph);
morph.Form.set_String(m_wsFr, TsStringUtils.MakeString("AffixAllomorph", m_wsFr));
// add environment to the allomorph
morph.PhoneEnvRC.Add(env);
return morph;
}
}

internal static ICmPicture CreatePicture(LcmCache cache, bool exists = true, string caption = "caption", string ws = "en")
Expand Down
7 changes: 5 additions & 2 deletions Src/xWorks/xWorksTests/ConfiguredXHTMLGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3580,15 +3580,18 @@ public void GenerateContentForEntry_EnvironmentsAndAllomorphsAreGenerated()

var mainEntry = CreateInterestingLexEntry(Cache);
AddAllomorphToEntry(mainEntry);
AddAllomorphToEntry(mainEntry, false);

var settings = new ConfiguredLcmGenerator.GeneratorSettings(Cache, m_propertyTable, false, false, null);
//SUT
var result = ConfiguredLcmGenerator.GenerateContentForEntry(mainEntry, mainEntryNode, null, settings).ToString();
const string xPathThruAllomorph = "/div[@class='lexentry']/span[@class='alternateformsos']/span[@class='alternateformso']";
AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(
xPathThruAllomorph + "/span[@class='form']/span[@lang='fr' and text()='Allomorph']", 1);
xPathThruAllomorph + "/span[@class='form']/span[@lang='fr' and text()='StemAllomorph']", 1);
AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(
xPathThruAllomorph + "/span[@class='form']/span[@lang='fr' and text()='AffixAllomorph']", 1);
AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(xPathThruAllomorph +
"/span[@class='allomorphenvironments']/span[@class='allomorphenvironment']/span[@class='stringrepresentation']/span[@lang='en' and text()='phoneyEnv']", 1);
"/span[@class='allomorphenvironments']/span[@class='allomorphenvironment']/span[@class='stringrepresentation']/span[@lang='en' and text()='phoneyEnv']", 2);
}

[Test]
Expand Down
Loading