Created
September 6, 2020 01:01
-
-
Save SQL-MisterMagoo/49c676aa24c24e2068692aa20896b578 to your computer and use it in GitHub Desktop.
Provide content from a base component that is not overridden
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyBase : ComponentBase | |
{ | |
string someValue = "test"; | |
public MyBase() | |
{ | |
var rf = typeof(ComponentBase).GetField("_renderFragment", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); | |
var pqr= typeof(ComponentBase).GetField("_hasPendingQueuedRender", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); | |
var nr= typeof(ComponentBase).GetField("_hasNeverRendered", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); | |
rf.SetValue(this, (RenderFragment)(builder => | |
{ | |
pqr.SetValue(this, false); | |
nr.SetValue(this, false); | |
builder.OpenComponent<CascadingValue<string>>(1); | |
builder.AddAttribute(2, "Value", someValue); | |
builder.AddAttribute(3, "ChildContent", (RenderFragment)( builder2 => BuildRenderTree(builder2))); | |
builder.CloseComponent(); | |
})); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will automatically include a CascadingValue for "someValue" to all child components.
If you don't want to use reflection, you can create your own base component that implements everything ComponentBase does, then modify the constructor in a similar way, but directly referencing the fields instead of using reflection.