Show / Hide Table of Contents

Class LambdaGridView<T>

Class implementing IGridView<T>, by providing the "get" functionality via a function that is passed in at construction. For a version that implements ISettableGridView<T>, see LambdaSettableGridView<T>.

Inheritance
Object
GridViewBase<T>
LambdaGridView<T>
Implements
IGridView<T>
Inherited Members
GridViewBase<T>.Count
GridViewBase<T>.Item[Int32, Int32]
GridViewBase<T>.Item[Int32]
Namespace: SadRogue.Primitives.GridViews
Assembly: TheSadRogue.Primitives.dll
Syntax
public sealed class LambdaGridView<T> : GridViewBase<T>, IGridView<T>
Type Parameters
Name Description
T

The type of value being returned by the indexer functions.

Constructors

LambdaGridView(Func<Int32>, Func<Int32>, Func<Point, T>)

Constructor. Takes functions that retrieve the width and height of the grid, and the function used to retrieve the value for a location.

Declaration
public LambdaGridView(Func<int> widthGetter, Func<int> heightGetter, Func<Point, T> valueGetter)
Parameters
Type Name Description
Func<Int32> widthGetter

A function/lambda that retrieves the width of the grid being represented.

Func<Int32> heightGetter

A function/lambda that retrieves the height of the grid being represented.

Func<Point, T> valueGetter

A function/lambda that returns the value of type T associated with the location it is given.

Remarks

This constructor is useful if the width and height of the grid being represented may change -- one can provide lambdas/functions that retrieve the width and height of the grid being represented, and these functions will be called any time the Width and Height properties are retrieved.

LambdaGridView(Int32, Int32, Func<Point, T>)

Constructor. Takes the width and height of the grid, and the function to use to retrieve the value for a location.

Declaration
public LambdaGridView(int width, int height, Func<Point, T> valueGetter)
Parameters
Type Name Description
Int32 width

The (constant) width of the map.

Int32 height

The (constant) height of the map.

Func<Point, T> valueGetter

A lambda/function that returns the value of type T associated with the location it is given. This function is called each time the grid view's indexers are called upon to retrieve a value from a location.

Remarks

This constructor is useful if the width and height of the underlying representation do not change, so they can safely be passed in as constants.

Properties

Height

The height of the grid being represented.

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

Item[Point]

Given a position, returns the "value" associated with that position, by calling the valueGetter function provided at construction.

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

Location to retrieve the value for.

Property Value
Type Description
T

The "value" associated with the provided location, according to the valueGetter function provided at construction.

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

Width

The width of the grid being represented.

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

Methods

ToString()

Returns a string representation of the grid view's values.

Declaration
public override string ToString()
Returns
Type Description
String

A string representation of the map view.

ToString(Func<T, String>)

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

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

Function determining the string representation of each element.

Returns
Type Description
String

A string representation of the grid view's values.

ToString(Int32, Func<T, String>)

Returns a string representing the grid view's values, using the function specified to turn elements into strings, and using the "field length" specified.

Declaration
public string ToString(int fieldSize, Func<T, 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<T, 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 view's 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.

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