Exemplo n.º 1
0
 public override string ToString()
 {
     if (TemplateKey.IsDefaultTemplateType(_templateType))
     {
         return(string.Format("{0} => {1}", Name, CompiledType));
     }
     else
     {
         return(string.Format("{0} ({2}) => {1}", Name, CompiledType, Type));
     }
 }
Exemplo n.º 2
0
        public HxlCompiledTemplateInfo FindTemplate(string name, string type)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (string.IsNullOrEmpty(name))
            {
                throw Failure.EmptyString("name");
            }

            var candidates = _templates[name];

            Func <HxlCompiledTemplateInfo, bool> predicate = t => t.Type == type ||
                                                             TemplateKey.IsDefaultTemplateType(t.Type);

            return(candidates.FirstOrDefault(predicate));
        }
Exemplo n.º 3
0
        public HxlTemplate CreateTemplate(string templateName, string templateType, IServiceProvider serviceProvider)
        {
            if (templateName == null)
            {
                throw new ArgumentNullException("templateName");
            }
            if (string.IsNullOrEmpty(templateName))
            {
                throw Failure.EmptyString("templateName");
            }

            // Optimize by reusing previous factory by name
            IHxlTemplateFactory previous;
            var key = new TemplateKey(templateName, templateType);

            if (previousCache.TryGetValue(key, out previous))
            {
                var result = previous.CreateTemplate(templateName, templateType, serviceProvider);
                if (result != null)
                {
                    return(result);
                }
            }

            foreach (var f in values)
            {
                var template = f.CreateTemplate(templateName, templateType, serviceProvider);
                if (template != null)
                {
                    previousCache[key] = f;
                    return(template);
                }
            }

            return(null);
        }
Exemplo n.º 4
0
 public bool Equals(TemplateKey other)
 {
     return(string.Equals(_templateName, other._templateName, StringComparison.OrdinalIgnoreCase) &&
            string.Equals(_templateType, other._templateType, StringComparison.OrdinalIgnoreCase));
 }