public static TemplateTranslation Translated(TemplateTranslation baseTranslation, TemplateTranslation through, ref bool translated) { if (baseTranslation == null || through == null) { throw new ArgumentNullException(); } if (baseTranslation.table.Count == 0 || through.table.Count == 0) { return(baseTranslation); } var dict = Later.Create(() => baseTranslation.table.ToDictionary(it => it.Key, it => it.Value)); foreach (KeyValuePair <TemplateParameter, IEntityInstance> entry in baseTranslation.table) { if (entry.Value != null) { bool trans = false; IEntityInstance entityInstance = entry.Value.TranslateThrough(ref trans, through); if (trans) { dict.Value[entry.Key] = entityInstance; } } else if (through.Translate(entry.Key, out IEntityInstance value)) { dict.Value[entry.Key] = value; } } if (dict.HasValue) { translated = true; return(new TemplateTranslation(baseTranslation.parametersProvider, dict.Value)); } else { return(baseTranslation); } }
public IEntityInstance TranslateThrough(ref bool translated, TemplateTranslation translation) { // consider: // Coll<T,A> implements IColl<A> // and then you have Coll<Int,String> (closedTemplate) -- so how does IColl looks now? // IColl<String> (since A maps to String) // and we compute it here // or let's say we have type Foo<T> and one of its methods returns T // then we have instance Foo<String> (closedTemplate), what T is then? (String) if (translation == null || translation == TemplateTranslation.Empty) { return(this); } if (this.TargetsTemplateParameter) { if (translation.Translate(this.TemplateParameterTarget, out IEntityInstance trans)) { if (!this.IsIdentical(trans)) { translated = true; } return(trans); } return(this); } else { TemplateTranslation combo_translation = TemplateTranslation.Translated(this.Translation, translation, ref translated); EntityInstance result = this.Target.GetInstance(this.OverrideMutability, combo_translation, this.Lifetime); return(result); } }