public override void Modify(object templateInstance, MemberInfo info, TemplateContext ctx)
        {
            base.Modify(templateInstance, info, ctx);
            string strRegex = @"_(?<name>[a-zA-Z0-9]+)_";
            bool   replaced = false;
            var    newName  = Regex.Replace(info.Name, strRegex, _ =>
            {
                var name = _.Groups["name"].Value;
                try
                {
                    replaced = true;
                    return((string)ctx.GetTemplateProperty(templateInstance, name));
                }
                catch (TemplateException ex)
                {
                    return(ctx.Item.Name);
                }
            });

            if (!replaced && NameFormat != null)
            {
                ctx.CurrentMember.Name = string.Format(NameFormat, ctx.Item.Name.Clean());
            }
            else
            {
                ctx.CurrentMember.Name = newName.Clean();
            }
        }
 public override bool CanGenerate(object templateInstance, MemberInfo info, TemplateContext ctx)
 {
     try
     {
         var condition = (bool)ctx.GetTemplateProperty(templateInstance, ConditionMemberName);
         return(condition);
     }
     catch (InvalidCastException ex)
     {
         throw new TemplateException(string.Format("Condition {0} is not a valid condition, make sure it is of type boolean.", ConditionMemberName), ex);
     }
 }
Beispiel #3
0
 public override bool CanGenerate(object templateInstance, MemberInfo info, TemplateContext ctx)
 {
     ctx.AddMemberIterator(info.Name, _ => ctx.GetTemplateProperty(templateInstance, IteratorMemberName) as IEnumerable);
     //CreateIterator(templateInstance, IteratorMemberName, _));
     return(true);
 }