private static List <HxlCompiledTemplateInfo> Search(Assembly assembly) { var result = new List <HxlCompiledTemplateInfo>(); var checksForDups = new Dictionary <TemplateKey, HxlCompiledTemplateInfo>(); foreach (var t in assembly.GetTypesHelper()) { if (typeof(HxlTemplate).IsAssignableFrom(t)) { string name, type; HxlTemplateAttribute.NameOrDefault(t, out name, out type); var item = new HxlCompiledTemplateInfo(name, type, t); var existing = checksForDups.GetValueOrDefault(item.Key); if (existing != null) { Traceables.ReflectedTemplateFactoryDuplicatedTemplate( assembly, t, name, existing.CompiledType); continue; } result.Add(item); checksForDups.Add(item.Key, item); } } return(result); }
static IHxlTemplateFactory FromAssemblyInternal(Assembly assembly) { var d = assembly.GetCustomAttributes(typeof(HxlTemplateFactoryAttribute)) .Cast <HxlTemplateFactoryAttribute>(); if (d.Any()) { Traceables.HxTemplateFactoryFromAssemblyExplicit(assembly, d); var all = d.Select(t => (IHxlTemplateFactory)Activator.CreateInstance(t.FactoryType)); return(Compose(all)); } // Default slow implementation // Don't scan App_Web assemblies for templates // HACK Using the name of the generated assembly (might be better to check for [GeneratedCode] if this works with Mono) if (Utility.IsHxlAssembly(assembly) && !assembly.GetName().Name.StartsWith("App_Web_", StringComparison.Ordinal)) { var result = new ReflectedTemplateFactory(assembly); Traceables.HxTemplateFactoryFromAssemblySlow(assembly, result); return(result); } else { Traceables.HxTemplateFactoryFromAssemblySkip(assembly); return(HxlTemplateFactory.Null); } }
public override string ToString() { var sb = new StringBuilder(); if (_value is Enum) { sb.Append(ConvertToClass((Enum)_value)); } foreach (PropertyInfo pd in Utility.ReflectGetProperties(_value.GetType())) { try { if (typeof(bool) == pd.PropertyType) { var boolStr = ConvertToClass((bool)pd.GetValue(_value), pd.Name); if (boolStr.Length > 0) { sb.AppendSeparator(" ").Append(boolStr); } } else if (typeof(Enum).IsAssignableFrom(pd.PropertyType)) { sb.AppendSeparator(" ").Append(ConvertToClass((Enum)pd.GetValue(_value))); } } catch (Exception ex) { Traceables.HandleComponentModelReflection(pd, ex); } } sb.AppendSeparator(" "); sb.Append(Hyphenate(_value.GetType().Name)); return(sb.ToString()); }
private void Convert(string text) { try { valueCache = Activation.FromText(_pd.PropertyType, text); } catch (Exception ex) { Traceables.HandleComponentModelReflection(_pd, ex); } }
void GetElementData() { var elementData = _templateContext.GetElementData(true); var props = HxlAttributeFragmentDefinition.ForComponent(this).ElementDataProperties; foreach (var prop in props) { try { elementData[prop.Name] = prop.GetValue(this); } catch (Exception ex) { Traceables.HandleComponentModelReflection(prop, ex); } } }
// TODO Error handling could be more robust private void ConvertBack(object value) { try { if (value == null) { textCache = null; return; } textCache = value.ToString(); } catch (Exception ex) { Traceables.HandleComponentModelReflection(_pd, ex); } }
public HxlTemplate CreateTemplate(string templateName, string templateType, IServiceProvider serviceProvider) { if (templateName == null) { throw new ArgumentNullException("templateName"); } if (string.IsNullOrEmpty(templateName)) { throw Failure.EmptyString("templateName"); } var info = RequireMap().FindTemplate(templateName, templateType); HxlTemplate result = null; Type type = null; if (info != null) { type = info.CompiledType; try { result = (HxlTemplate)Activator.CreateInstance(type); } catch (Exception ex) { Traceables.ReflectedTemplateFactoryCreateTemplateError( assembly, type, templateName, ex); throw; } } Traceables.ReflectedTemplateFactoryCreateTemplate( assembly, type, templateName, result != null); return(result); }
public HxlTemplate CreateTemplate(string templateName, string templateType, IServiceProvider serviceProvider) { if (templateName == null) { throw new ArgumentNullException("templateName"); } if (string.IsNullOrEmpty(templateName)) { throw Failure.EmptyString("templateName"); } Type type = GetTemplateType(templateName, templateType, serviceProvider); Traceables.HxlTemplateFactoryCreateTemplate(templateName, templateType, type); if (type == null) { return(null); } else { return((HxlTemplate)Activator.CreateInstance(type)); } }