WPF IsEditable=true ComboBox filled with objects displays the ToString() as the selected item

You can do this entirely within Xaml <ComboBox IsTextSearchEnabled=”True” IsEditable=”True” ItemsSource=”{Binding MyObjectCollection}” TextSearch.TextPath=”MyObjectName”> <ComboBox.ItemTemplate> <DataTemplate> <TextBlock Text=”{Binding MyObjectName}” /> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox> The upside is that you can define and change this however you want in your XAML without any code-behind. You bind the ItemsSource to your collection of objects, and then you set the … Read more

Creating String representation of lambda expression [duplicate]

The simplest thing I could come up with is creating a “named predicate” that gives your predicates a name or description, basically anything that will be useful as a toString: public class NamedPredicate<T> implements Predicate<T> { private final String name; private final Predicate<T> predicate; public NamedPredicate(String name, Predicate<T> predicate) { this.name = name; this.predicate = … Read more

C# Converting 20 digit precision double to string and back again

Use the “R” numeric format string: double d = 0.00034101243963859839; string s = d.ToString(“R”); //… double d2 = double.Parse(s); if(d == d2) { //– Success } The R stands for “round-trip”. From the linked document: This format is supported only for the Single and Double types. The round-trip specifier guarantees that a numeric value converted … Read more

How does ToString on an anonymous type work?

With anonymous objects… The compiler generates an internal sealed class that models the anonymous type. The anonymous type is immutable; all the properties are read only. That class contains overrides of Equals() and GetHashCode() that implement value semantics. In addition, the compiler generates an override of ToString() that displays the value of each of the … Read more