예제 #1
0
 private void BindContext(object target, TagHelperContext context)
 {
     foreach (var propertyInfo in target.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).Where(pi => pi.HasCustomAttribute <BindTagHelperContextAttribute>()))
     {
         var attr = propertyInfo.GetCustomAttribute <BindTagHelperContextAttribute>();
         if (string.IsNullOrEmpty(attr.Key))
         {
             var contextItem = context.GetContextItem(propertyInfo.PropertyType, attr.UseInherited);
             if (contextItem != null)
             {
                 propertyInfo.SetValue(target, contextItem);
             }
             if (attr.RemoveContext)
             {
                 context.RemoveContextItem(propertyInfo.PropertyType, attr.UseInherited);
             }
         }
         else
         {
             propertyInfo.SetValue(target, context.GetContextItem(propertyInfo.PropertyType, attr.Key));
             if (attr.RemoveContext)
             {
                 context.RemoveContextItem(attr.Key);
             }
         }
     }
 }
예제 #2
0
 public static void SetContexts(object target, TagHelperContext context)
 {
     if (target == null)
     {
         throw new ArgumentNullException(nameof(target));
     }
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     foreach (var propertyInfo in target.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).Where(pI => pI.HasCustomAttribute <ContextAttribute>()))
     {
         var attr = propertyInfo.GetCustomAttribute <ContextAttribute>();
         if (string.IsNullOrEmpty(attr.Key))
         {
             var contextItem = context.GetContextItem(propertyInfo.PropertyType, attr.UseInherited);
             if (contextItem != null)
             {
                 propertyInfo.SetValue(target, contextItem);
             }
             if (attr.RemoveContext)
             {
                 context.RemoveContextItem(propertyInfo.PropertyType, attr.UseInherited);
             }
         }
         else
         {
             propertyInfo.SetValue(target, context.GetContextItem(propertyInfo.PropertyType, attr.Key));
             if (attr.RemoveContext)
             {
                 context.RemoveContextItem(attr.Key);
             }
         }
     }
 }
예제 #3
0
 protected override void BootstrapProcess(TagHelperContext context, TagHelperOutput output)
 {
     output.Attributes.Add("role", "group");
     if (context.HasContextItem <InputGroupTagHelper>())
     {
         Size = BootstrapTagHelpers.Size.Default;
         if (!context.HasContextItem <AddonTagHelper>())
         {
             output.TagName = "span";
             output.AddCssClass("input-group-btn");
         }
         context.RemoveContextItem <InputGroupTagHelper>();
     }
     else
     {
         output.TagName = "div";
         if (this.Vertical)
         {
             output.AddCssClass("btn-group-vertical");
         }
         else
         {
             output.AddCssClass("btn-group");
         }
         if (this.Size.HasValue)
         {
             output.AddCssClass("btn-group-" + this.Size.Value.GetDescription());
         }
         if (this.Justified)
         {
             output.AddCssClass("btn-group-justified");
         }
     }
 }
예제 #4
0
 protected override void BootstrapProcess(TagHelperContext context, TagHelperOutput output)
 {
     if (context.HasContextItem <MediaListTagHelper>())
     {
         output.TagName = "li";
         context.RemoveContextItem <MediaListTagHelper>();
     }
     else
     {
         output.TagName = "div";
     }
     output.AddCssClass("media");
 }