コード例 #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));
     }
 }
コード例 #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));
        }
コード例 #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);
        }
コード例 #4
0
ファイル: TemplateKey.cs プロジェクト: Carbonfrost/f-hxl
 public bool Equals(TemplateKey other)
 {
     return(string.Equals(_templateName, other._templateName, StringComparison.OrdinalIgnoreCase) &&
            string.Equals(_templateType, other._templateType, StringComparison.OrdinalIgnoreCase));
 }