Show / Hide Table of Contents

Class TranslationGridView<T1, T2>

Class implementing IGridView<T> by providing a function that translates values from one grid view with complex data types, to a grid view with simple data types. For a version that provides "set" functionality, see SettableTranslationGridView<T1, T2>.

Inheritance
Object
GridViewBase<T2>
TranslationGridView<T1, T2>
LambdaTranslationGridView<T1, T2>
Implements
IGridView<T2>
Inherited Members
GridViewBase<T2>.Count
GridViewBase<T2>.Item[Int32, Int32]
GridViewBase<T2>.Item[Int32]
Namespace: SadRogue.Primitives.GridViews
Assembly: TheSadRogue.Primitives.dll
Syntax
public abstract class TranslationGridView<T1, T2> : GridViewBase<T2>, IGridView<T2>
Type Parameters
Name Description
T1

The type of your underlying data.

T2

The type of the data being exposed by the grid view.

Remarks

This class is useful if the underlying representation of the data you are creating a grid view for is complex, and you simply need to map a complex data type to a simpler one. For example, you might implement the TranslateGet(Point, T1) function to extract a property from a more complex structure. If your mapping is very simple, or you do not wish to create a subclass, see LambdaTranslationGridView<T1, T2>.

Constructors

TranslationGridView(IGridView<T1>)

Constructor. Takes an existing grid view to create a view from.

Declaration
protected TranslationGridView(IGridView<T1> baseGrid)
Parameters
Type Name Description
IGridView<T1> baseGrid

A grid view exposing your underlying data.

Properties

BaseGrid

The underlying grid data, exposed as a grid view.

Declaration
public IGridView<T1> BaseGrid { get; }
Property Value
Type Description
IGridView<T1>

Height

The height of the grid.

Declaration
public override int Height { get; }
Property Value
Type Description
Int32
Overrides
SadRogue.Primitives.GridViews.GridViewBase<T2>.Height

Item[Point]

Given a position, translates and returns the "value" associated with that position.

Declaration
public override T2 this[Point pos] { get; }
Parameters
Type Name Description
Point pos

Location to get the value for.

Property Value
Type Description
T2

The translated "value" associated with the provided location.

Overrides
SadRogue.Primitives.GridViews.GridViewBase<T2>.Item[SadRogue.Primitives.Point]

Width

The width of the grid.

Declaration
public override int Width { get; }
Property Value
Type Description
Int32
Overrides
SadRogue.Primitives.GridViews.GridViewBase<T2>.Width

Methods

ToString()

Returns a string representation of the exposed grid values.

Declaration
public override string ToString()
Returns
Type Description
String

A string representation of the exposed grid values.

ToString(Func<T2, String>)

Returns a string representation of the grid values, using elementStringifier to determine what string represents each value.

Declaration
public string ToString(Func<T2, string> elementStringifier)
Parameters
Type Name Description
Func<T2, String> elementStringifier

Function determining the string representation of each element.

Returns
Type Description
String

A string representation of the grid values.

ToString(Int32, Func<T2, String>)

Returns a string representation of the grid values, using the function specified to turn elements into strings, and using the "field length" specified.

Declaration
public string ToString(int fieldSize, Func<T2, string> elementStringifier = null)
Parameters
Type Name Description
Int32 fieldSize

The size of the field to give each value. A positive-number right-aligns the text within the field, while a negative number left-aligns the text.

Func<T2, String> elementStringifier

Function to use to convert each element to a string. null defaults to the ToString function of type T.

Returns
Type Description
String

A string representation of the grid values.

Remarks

Each element of type T will have spaces added to cause it to take up exactly fieldSize characters, provided fieldSize is less than the length of the element's string representation.

TranslateGet(T1)

Translates your actual data into the view type using just the data value itself. If you need the location as well to perform the translation, implement TranslateGet(Point, T1) instead.

Declaration
protected virtual T2 TranslateGet(T1 value)
Parameters
Type Name Description
T1 value

The data value from the base grid view.

Returns
Type Description
T2

A value of the mapped data type.

TranslateGet(Point, T1)

Translates your actual data into the view type using the position and the data value itself. If you need only the data value to perform the translation, implement TranslateGet(T1) instead.

Declaration
protected virtual T2 TranslateGet(Point position, T1 value)
Parameters
Type Name Description
Point position

The position of the given data value.

T1 value

The data value from your underlying grid view.

Returns
Type Description
T2

A value of the mapped data type.

Implements

IGridView<T>

Extension Methods

PropertyChangedEventHelpers.SafelySetProperty<TObject, TProperty>(TObject, ref TProperty, TProperty, EventHandler<ValueChangedEventArgs<TProperty>>)
PropertyChangedEventHelpers.SafelySetProperty<TObject, TProperty>(TObject, ref TProperty, TProperty, EventHandler<ValueChangedEventArgs<TProperty>>, EventHandler<ValueChangedEventArgs<TProperty>>)
In This Article
Back to top Generated by DocFX