S&box Wiki

Revision Difference

ui-razor-generics#549878

<cat>UI.Razor</cat>⤶ <title>Generic Components</title>⤶ ⤶ # Generics⤶ ⤶ You can make a generic razor panel class by using the `@typeparam` to define the name of the parameter.⤶ ⤶ ```html⤶ @typeparam T⤶ ⤶ <root>⤶ ⤶ This is my class for @Value⤶ ⤶ </root>⤶ ⤶ ⤶ @code⤶ {⤶ public T Value { get; set; }⤶ }⤶ ```⤶ ⤶ You will then be able to use this like a regular generics class in c#, like `PanelName<string>` etc.⤶ ⤶ # In Razor⤶ ⤶ In Razor you will need to add a `T` attribute to define the type.⤶ ⤶ ```html⤶ <root>⤶ ⤶ <MyPanel T="string"></MyPanel>⤶ ⤶ </root>⤶ ```⤶