/// <summary> /// Uses the template property attributes to assign values to properties. /// </summary> /// <param name="pEntry">Target template to work on</param> /// <param name="prop">Base WZ property node</param> protected void AssignProviderAttributes(AbstractTemplate pEntry, WzProperty prop) { var pTypeInfo = pEntry.GetType(); var pClassMembers = pTypeInfo.GetMembers(); foreach (var templateMember in pClassMembers) { var apCustomAttributes = System.Attribute.GetCustomAttributes(templateMember); if (apCustomAttributes.Any(t => t is ProviderIgnoreAttribute)) { continue; } foreach (var attribute in apCustomAttributes) { if (attribute is ProviderPropertyAttribute paa) { var pi = pEntry.GetType().GetProperty(templateMember.Name); // if pi is null: throw -- should not happen SetProviderPropertyValue(pEntry, pi, prop, paa); } else if (attribute is ProviderListAttribute pla) { ; // TODO var pi = pEntry.GetType().GetProperty(templateMember.Name); ; } } } }
public void TestAbstractTemplate() { using (Foo foo = new Foo()) using (AbstractTemplate <int> abstractTemplate = foo.AbstractTemplate) { Assert.That(abstractTemplate.Property, Is.EqualTo(55)); Assert.That(abstractTemplate.CallFunction(), Is.EqualTo(65)); } }
protected void UpdateInfo(XPathNavigator nav, AbstractTemplate template) { if (!template.IdentifierTemplate.IsNullOrEmpty) { Identifier = template.IdentifierTemplate.Execute(nav); } Title = template.TitleTemplate.Execute(nav, MaxChars); Text = template.TextTemplate.Execute(nav, MaxChars); IconUrl = template.IconUrlTemplate.Execute(nav); MediaUrl = template.MediaUrlTemplate.Execute(nav); BrowserUrl = template.BrowserUrlTemplate.Execute(nav); if (IsNewBehavior == IsNewPropertyGets.OldOnRefresh) { IsNew = false; } }
private void SetProviderPropertyValue(AbstractTemplate pEntry, PropertyInfo pi, WzProperty dataProp, ProviderPropertyAttribute paa) { WzProperty realPropDir = dataProp; var propNameSplit = paa.AttributePath.Split('/'); string attributeName; for (var i = 0; i < propNameSplit.Length - 1; ++i) { attributeName = propNameSplit[i]; if (realPropDir is null) { continue; // cant find path } realPropDir = realPropDir.GetChild(attributeName) as WzProperty; } attributeName = propNameSplit[propNameSplit.Length - 1]; // should always be last of the split if (realPropDir is null) { return; // cant find path } var val = realPropDir.GetImgPropVal(pi.PropertyType, attributeName); if (val.IsNullOrDefault() || val is string s && s.Length <= 0) { foreach (var attrName in paa.AltPaths) { val = realPropDir.GetImgPropVal(pi.PropertyType, attrName); if (!val.IsNullOrDefault() || val is string ss && ss.Length <= 0) { break; } } } pi.SetValue(pEntry, val); }
public IStatementResult Query(AbstractTemplate template, ISession session) { var result = session.Run(template.Query, template.Parameters); return(result); }
public CodeWriter Append(AbstractTemplate abstractTemplate) { abstractTemplate.Generate(this); return(this); }
public Template(AbstractTemplate parent, string templateName) : base(parent) { _TemplateName = templateName; }