是否可以添加构造函数扩展方法?我想添加一个List <T>构造函数来接收给定部分填充的缓冲区中的特定字节数(没有复制相关字节的开销等等):
...
public static List<T>(this List<T> l, T[] a, int n)
{
for (int i = 0; i < n; i++)
l.Add(a[i]);
}
...
Run Code Online (Sandbox Code Playgroud)
所以用法是:
List<byte> some_list = new List<byte>(my_byte_array,number_of_bytes);
Run Code Online (Sandbox Code Playgroud)
我已经添加了AddRange扩展方法:
public static void AddRange<T>(this List<T> l, T[] a, int n)
{
for (int i = 0; i < n; i++)
l.Add(a[i]);
}
Run Code Online (Sandbox Code Playgroud)
我也想把它作为构造函数.可能吗 ?如果是 - 怎么样?
我有这个:
<TabControl Margin="0,24,0,0">...</TabControl>
Run Code Online (Sandbox Code Playgroud)
我想只绑定"Top"
TabControl 的一部分,直觉上我会这样做:
<TabControl Margin="0,{Binding ElementName=TheMenu, Path=Height},0,0">
...
</TabControl>
Run Code Online (Sandbox Code Playgroud)
我该怎么做 ?
JSON.stringify(eventObject);
得到:
TypeError: Converting circular structure to JSON
dojox.json.ref.toJson(eventObject);
得到:
TypeError: Accessing selectionEnd on an input element that cannot have a selection.
是否有一些库/代码可以用来完成它?
我的数据绑定版本号如下所示:
<Window <!-- ... --> DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Grid>
<TextBlock>
Version is:
<Run Text="{Binding Version, Mode=OneWay}"></Run>
and advancing...
</TextBlock>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
它在运行期间正在运行.
如何在Visual Studio 2012的XAML编辑器中在设计时看到它?我只看到:
Version is: and advancing...
Run Code Online (Sandbox Code Playgroud)
代替:
Version is: 5.2.2 and advancing...
Run Code Online (Sandbox Code Playgroud)
下面的Jure的答案有效,但我最终使用了虚拟视图模型静态代码技术,这对我来说更好,因为数据是真实视图模型类型的模拟:
d:DataContext="{Binding Source={StaticResource DesignViewModel}}" ...
Run Code Online (Sandbox Code Playgroud) 如何使用提供Cat的组件创建Dog实例.
public final class Dog {
private final Cat mCat;
public final static String TAG = "Dog";
@Inject public Dog(Cat cat) {
mCat = cat;
Log.e(TAG, "Dog class created");
}
}
Run Code Online (Sandbox Code Playgroud)
在尝试使用Dagger 2一段时间后,我不知道如何使用构造函数注入 - 一个提示会很好,谢谢.
编辑:
这个问题怎么了?在使用Dagger 2之后,按照几个教程并阅读官方文档,我不知道如何使用构造函数注入功能,这就是我在这里问的原因.而不是使用@Inject将Cat依赖项注入Dog中,我可以编写一个提供Dog对象的DogModule,但是Dog将只是一个普通的Java类.现场注入效果很好(有很多示例显示如何使用它)但是我需要做什么才能使用构造函数注入?
在尝试创建$disconnect
为 API 网关命名的路由键时,我运行下面的代码片段,同时var.route_name
应该收到字符串“disconnect”:
resource "aws_apigatewayv2_route" "route" {
api_id = var.apigw_api.id
route_key = "$${var.route_name}"
# more stuff...
}
Run Code Online (Sandbox Code Playgroud)
但它并没有正确地转义它。我找不到正确的方法来发出 a $
,后跟var.route_name
s 的内容。
怎么做?
我希望以递归方式获取路径中的文件列表(实际上是文件数),不包括某些类型:
Get-ChildItem -Path $path -Recurse | ? { $_.Name -notlike "*.cs" -and $_.Name -notlike "*.tt" }
Run Code Online (Sandbox Code Playgroud)
但是我有很多排除列表(仅举几例):
@("*.cs", "*.tt", "*.xaml", "*.csproj", "*.sln", "*.xml", "*.cmd", "*.txt")
Run Code Online (Sandbox Code Playgroud)
如何使用此表单获取列表:
Get-ChildItem -Path $path -Recurse | ? { <# what to put here ?#> }
Run Code Online (Sandbox Code Playgroud)
?
我的代码隐藏的一部分:
object _sync = new object();
private async void OnKeyDown(object sender, KeyEventArgs e) {
if (!Monitor.TryEnter(_sync)) return;
Trace.Write("taken...");
await Task.Delay(TimeSpan.FromSeconds(5));
Trace.WriteLine(" done");
Monitor.Exit(_sync);
}
Run Code Online (Sandbox Code Playgroud)
输出(在不到5秒的时间内按下几次):
taken...taken...taken... done
done
done
Run Code Online (Sandbox Code Playgroud)
怎么会??该_sync
锁是永远不会上当受骗,为什么呢?
我知道我在这里有危险,但在 SO/Google 中找不到:
使用字符串插值,如何填充给定字符?例如:
foreach (var p in people) {
Console.WriteLine($"{p.Name,-10}: {p.Age}");
}
Run Code Online (Sandbox Code Playgroud)
将导致(例如):
Joe : 26
Dan : 52
Run Code Online (Sandbox Code Playgroud)
如何通过字符串插值更改带点的空格?要得到:
Joe.......: 26
Dan.......: 52
Run Code Online (Sandbox Code Playgroud)
(我知道我可以做到p.Name.PadRight(10,'.')
,但我很确定有一种方法可以使用字符串插值参数,例如填充长度)。
System.Windows.Markup.XamlParseExceptionoccurred
A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll
Additional information: 'Set property 'System.Windows.ResourceDictionary.Source' threw an exception.' Line number '21' and line position '6'.
"Could not load file or assembly 'ResourceLibrary, Culture=neutral' or one of its dependencies. The system cannot find the file specified.":"ResourceLibrary, Culture=neutral"
=== Pre-bind state information ===
LOG: DisplayName = ResourceLibrary, Culture=neutral
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: ResourceLibrary, Culture=neutral | Domain ID: 2
WRN: A partial bind …
Run Code Online (Sandbox Code Playgroud) c# ×4
wpf ×4
binding ×1
c#-6.0 ×1
constructor ×1
dagger-2 ×1
data-binding ×1
design-time ×1
hcl ×1
javascript ×1
json ×1
margin ×1
powershell ×1
stringify ×1
terraform ×1
using ×1
xaml ×1