/// <summary>
///
/// </summary>
/// <remarks
///
/// </remarks>
Run Code Online (Sandbox Code Playgroud)
如何在上面的注释中添加xaml代码,避免代码解析器创建不存在的链接(CTRL + Click消息)?
我有以下布局(简化):
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition MaxWidth="400" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<!-- Code for Column=0 -->
<ScrollViewer Grid.Column="1">
<Grid x:Name="layoutGrid">
<Grid.ColumnDefinitions>
<Grid.ColumnDefinition Width="Auto" />
<Grid.ColumnDefinition MinWidth="100" MaxWidth="400" />
<Grid.ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<!-- Code for Row=0 and Row=1 -->
<GroupBox Grid.ColumnSpan="3" Grid.Row=2>
<TextBlock Text="{Binding ...}" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Top" />
</GroupBox>
</Grid>
</ScrollViewer>
</Grid>
Run Code Online (Sandbox Code Playgroud)
我怎样才能在xaml中实现这一目标?似乎只要插入ScrollViewer,TextBlock就不再包装了.
我有一个ISomeType列表,其中T包含至少一个IConvertibleProperty类型的属性.例:
IConvertibleProperty
{
string PropertyA { get; set; }
string PropertyB { get; set; }
// etc
}
public class SomeTypeA : ISomeType
{
public ConvertibleProperty PropertyX { get; set; }
// etc
}
Run Code Online (Sandbox Code Playgroud)
我需要创建一个泛型函数,我可以通过以下方式调用它:
CustomMethod(list, x => x.PropertyX);
Run Code Online (Sandbox Code Playgroud)
并且将能够在其中实现下一个排序:
protected void CustomMethod<T, TKey>(IList<T> list, Func<T, TKey> expr) where T : ISomeType where TKey : IConvertibleProperty
{
// example of non-generic sorting (in this case expr = x.PropertyX)
var sortedList = list.OrderBy(x => x.PropertyX.PropertyA).ThenBy(x => x.PropertyX.PropertyB).ToList();
// rest of the …Run Code Online (Sandbox Code Playgroud) 在很多情况下我们必须做这样的事情:
if (someVariable == value1 || someVariable == value2 || someVariable == value1...)
Run Code Online (Sandbox Code Playgroud)
如果我们能够以下列方式做到这一点会不会很好:
if (someVariable in {value1, value2, value3...}
Run Code Online (Sandbox Code Playgroud)
我们做得到
int[] arr = {value1, value2, value3....};
if (arr.Contains(someVariable)) ...
Run Code Online (Sandbox Code Playgroud)
但就我而言,它仍然势不可挡.为什么没有对这种语法的支持,或者有但我不知道呢?
我对下一种情况下的编译器效率感到好奇:
double total = list.Sum(x => x.Value) ?? 0;
Run Code Online (Sandbox Code Playgroud)
问:编译器会生成一次或两次执行Sum函数的代码吗?
它可以生成如下内容:
double total = list.Sum(x => x.Value) == null ? 0 : (double)list.Sum(x => x.Value);
Run Code Online (Sandbox Code Playgroud)
要么
double temp = list.Sum(x => x.Value);
total = temp == null ? 0 : (double)temp;
Run Code Online (Sandbox Code Playgroud)