valuetuple

Is it possible to bind to a ValueTuple field in WPF with C#7

喜你入骨 提交于 2019-11-28 07:07:53
问题 If I have a viewmodel property public (string Mdf, string MdfPath) MachineDefinition { get; set; } and I try to bind to it in XAML / WPF <Label Content="{Binding Path=MachineDefinition.Item2}" /> or <Label Content="{Binding Path=MachineDefinition.MdfPath}" /> I get the same error I see that ValueTuple fields are really fields not properties . Is this the problem? 回答1: The confusion is that for old style Tuple ( pre C#7 ) all the Items were properties https://msdn.microsoft.com/en-us/library

I can't get parameter names from valuetuple via reflection in c# 7.0

爱⌒轻易说出口 提交于 2019-11-28 03:31:40
问题 I want to Map a ValueTuple to a class using reflection. Documentation says that there is a Attribute attached to ValueTuple with parameters names (others than Item1, Item2, etc...) but I can't see any Attribute. Disassembly shows nothing. What's happens? Example: public static T ToStruct<T, T1,T2>(this ValueTuple<T1,T2> tuple) where T : struct Via reflection can't get Item1, Item2 names to match with T fields via reflection. 回答1: You should have the TupleElementNames attribute on the method