question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Proposal] Is In Range Converter

See original GitHub issue

IsInRangeConverter

  • Proposed
  • Prototype
  • Implementation
    • iOS Support
    • Android Support
    • macOS Support
    • Windows Support
  • Unit Tests
  • Sample
  • Documentation

Summary

The IsInRangeConverter is a converter that allows users to convert a object value into a boolean value, checking if the value is between MinValue and MaxValue, returning true if the value is within the range and false if the value is out of the range

Detailed Design

IsInRangeConverter.shared.cs

public class IsInRangeConverter : ValueConverterExtension, IValueConverter
{
  public static readonly BindableProperty MinValueProperty = BindableProperty.Create(nameof(MinValue), typeof(object), typeof(IsInRangeConverter));

  public static readonly BindableProperty MaxValueProperty = BindableProperty.Create(nameof(MaxValue), typeof(object), typeof(IsInRangeConverter));

  public object? MinValue
  {
	get => GetValue(MinValueProperty);
	set => SetValue(MinValueProperty, value);
  }

  public object? MaxValue
  {
	get => GetValue(MaxValueProperty);
	set => SetValue(MaxValueProperty, value);
  }

  public object Convert(object? value, Type? targetType, object? parameter, CultureInfo? culture)
  {
	if (value is not IComparable comparable)
		throw new ArgumentException("is expected to implement IComparable interface.", nameof(value));

	if (MinValue is not IComparable)
		throw new ArgumentException("is expected to implement IComparable interface.", nameof(MinValue));

	if (MaxValue is not IComparable)
		throw new ArgumentException("is expected to implement IComparable interface.", nameof(MaxValue));

	return comparable.CompareTo(MinValue) >= 0 && comparable.CompareTo(MaxValue) <= 0;
  }

  public object? ConvertBack(object? value, Type? targetType, object? parameter, CultureInfo? culture) => throw new NotImplementedException();
}

Usage Syntax

XAML Usage

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
             xmlns:myEnum="MyLittleApp.Models"
             x:Class="MyLittleApp.MainPage">

    <ContentPage.Resources>
        <ResourceDictionary>
          <xct:IsInRangeConverter
                          x:Key="IsInRangeConverter"
                          MaxValue= "1"
                          MinValue= "3" />
        </ResourceDictionary>
    </ContentPage.Resources>

    <StackLayout>
        <Label IsVisible="{Binding Number, Converter={StaticResource IssueStateConverter } }" />

    </StackLayout>
</ContentPage>

C# Usage

class MyPage : ContentPage
{
  public MyPage()
  {
    Content = new StackLayout
    {
      Children = 
      {
          new Label().Bind(Label.IsVisibleProperty, nameof(ViewModel.Number), converter: new IsInRangeConverter { MinValue = 1, MaxValue = 3 }),
      };
    }
  }
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
GeorgeLeitheadcommented, Apr 24, 2023

@brminnick I think that this proposal an be moved to the Closed project column and Completed project column to close.

2reactions
JoonghyunChocommented, Oct 31, 2022

Hi George! Thanks for your work on this proposal. I will be championing this proposal. I will bring this to a vote to be approved so you can create a pull request. Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Proposal of a DC-DC converter with wide conversion range ...
The proposed converter supports a wide input voltage range that makes it possible to be supplied from 12 V DC to 340 V...
Read more >
Propose Data Types Based on Simulation Ranges
Convert to Fixed Point. The app generates an instrumented MEX function for your entry-point MATLAB function. The app displays compiled information—type, ...
Read more >
A function to convert any range to a container
We propose a function to copy or materialize any range (containers ... //Supports converting associative container to sequence containers.
Read more >
How to Increase Your Proposal Conversion Rate by 25%
We looked at the conversion rates of all proposals that were sent within ... proposal templates on this site from a whole range...
Read more >
Part 15 - Contracting by Negotiation
Communications are exchanges, between the Government and offerors, after receipt of proposals, leading to establishment of the competitive range.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found