Skip to content

CssBuilder.SetPrefix Method

Ed Charbeneau edited this page Jun 14, 2021 · 3 revisions

SetPrefix(string value)

Sets the prefix value to be appended to all classes added following the this statement. When SetPrefix is called it will overwrite any previous prefix set for this instance. Prefixes are not applied when using AddValue.

var result = CssBuilder
      .Default("MessageBar")
      // Prefixes are evaluated immediately (not lazily)
	  .AddClass("DontPrefixMe")
	  .SetPrefix("MessageBar-")
      // MessageBar-* is added to the classes below
      .AddClass($"info", Type == MessageBarType.Info /*true*/)
      .AddClass($"error", Type == MessageBarType.Error /*false*/)
      .AddClass($"blocked", Type == MessageBarType.Blocked /*false*/)
      .AddClass($"severeWarning", Type == MessageBarType.SeverWarning /*false*/)
      .AddClass($"warning", Type == MessageBarType.Warning /*false*/)
      .AddClass($"success", Type == MessageBarType.Success /*false*/)
      // Clear the prefix so additional attributes aren't affected
      .SetPrefix(String.Empty) 
      .AddClassFromAttributes(attributes)
      .Build();

// result => "MessageBar DontPrefixMe MessageBar-info additional-attributes"