在下面的示例中(仅用于演示目的),如果T不受类约束,则此转换:
var ret = objectA as T;
Run Code Online (Sandbox Code Playgroud)
..会导致以下编译错误:
类型参数"T"不能与"as"运算符一起使用,因为它没有类类型约束或"类"约束.
我不明白为什么我不能这样做.由于我已经限制T为接口IObject,编译器应该知道T必须是接口类型并且as操作应该是有效的.
public interface IObject
{
string Id { get; set; }
}
public class ObjectA : IObject
{
public string Id { get; set; }
}
public class ObjectFactory
{
public T CreateObject<T>(string id) where T : IObject
{
ObjectA objectA = new ObjectA();
var x = objectA as IObject; // this is good
var ret = objectA as T; // …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序来处理文件并将其分成多个段,然后将结果保存到sql server数据库中.有许多重复文件(可能具有不同的文件路径),因此首先我浏览所有这些文件并为每个文件计算Md5哈希,并使用[Duplicated]列标记重复文件.
然后每天,我将运行此应用程序并将结果保存到[Result]表中.db模式如下:
CREATE TABLE [dbo].[FilePath]
(
[FilePath] NVARCHAR(256) NOT NULL PRIMARY KEY,
[FileMd5Hash] binay(16) NOT NULL,
[Duplicated] BIT NOT NULL DEFAULT 0,
[LastRunBuild] NVARCHAR(30) NOT NULL DEFAULT 0
)
CREATE TABLE [dbo].[Result]
(
[Build] NVARCHAR(30) NOT NULL,
[FileMd5Hash] binay(16) NOT NULL ,
[SegmentId] INT NOT NULL,
[SegmentContent] text NOT NULL
PRIMARY KEY ([FileMd5Hash], [Build], [SegmentId])
)
Run Code Online (Sandbox Code Playgroud)
我要求在FileMd5Hash上加入这两个表.
由于[Result]的行数非常大,我想添加一个int Identity列来将这些连接到表中,如下所示:
CREATE TABLE [dbo].[FilePath]
(
[FilePath] NVARCHAR(256) NOT NULL PRIMARY KEY,
[FileMd5Hash] binay(16) NOT NULL,
**[Id] INT NOT NULL IDENTITY,**
[Duplicated] …Run Code Online (Sandbox Code Playgroud) 我尝试了以下语句,但因编译错误而失败.
declare @myValue int NULL
我正在尝试使用合并单元格创建类似数据网格的视图。一切都很好,除了我不能ShareSizeScope在标题行和其余行之间。您可以在下面的屏幕截图中看到,除了第一列之外,列没有对齐。有人可以指出我的代码有什么问题吗?提前致谢。

我的 XAML:
<Grid Grid.Row ="0" Grid.Column="0" Margin="0,0,2,0" Grid.IsSharedSizeScope="True">
<Grid.RowDefinitions>
<RowDefinition Height="35" MaxHeight="35" MinHeight="35"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Height="35" VerticalAlignment="Top" Background="{StaticResource customBlueBrush}">
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="Col_A" />
<ColumnDefinition SharedSizeGroup="Col_B" />
<ColumnDefinition SharedSizeGroup="Col_C" />
<ColumnDefinition SharedSizeGroup="Col_D" />
<ColumnDefinition SharedSizeGroup="Col_E" />
</Grid.ColumnDefinitions>
<Border BorderThickness="0,0,1,0" BorderBrush="Black" Margin="-1" Grid.Column="0"></Border>
<Border BorderThickness="0,0,1,0" BorderBrush="Black" Margin="-1" Grid.Column="1"></Border>
<Border BorderThickness="0,0,1,0" BorderBrush="Black" Margin="-1" Grid.Column="2"></Border>
<Border BorderThickness="0,0,1,0" BorderBrush="Black" Margin="-1" Grid.Column="3"></Border>
<TextBlock Text="Col 1" FontSize="14" FontFamily="Segoe Ui Dark" Foreground="White" SnapsToDevicePixels="True" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Column="0" ></TextBlock>
<TextBlock Text="Col 2" FontSize="14" FontFamily="Segoe …Run Code Online (Sandbox Code Playgroud) 使用path-to-regexp时,如何匹配所有不以开头的路径/api/?
通过使用本机JavaScript,RegExp /^(?!\/api\/).*/将匹配/x/y/z。从这里查看测试结果

但是,它不适用于正则表达式路径。从那里查看测试结果
那么,实现正则表达式路径的正确方法是什么?
[更新1]
更多详细信息:实际情况是我正在使用angular2 + koajs。并且在angular2中,浏览器可能会向服务器发布客户端路由url。请参阅我对此的另一个问题。
为了解决这个问题,正如@mxii所建议的那样,我正在尝试使用koa-repath将所有不以开头的请求重定向/api/到根url:http://localhost:3000/除了它是静态资产(js / json / html / png / ...)要求。
并koa-repath用于path-to-regexp匹配路径。这就是为什么我问这个问题。
我正在尝试创建 WPF GUI 应用程序来托管已经存在的 QT GUI 应用程序作为主 UI 的一部分。
QT 应用程序不需要处理鼠标/键盘输入。
我已经尝试过这个SO Post 中提到的方法。似乎所有这些方法都不适用于 QT 应用程序。
我熟悉WPF和MVVM模式。现在,我正在尝试使用Autofac在我的新WPF应用中练习依赖注入模式。我想弄清楚如何将依赖项注入MVVM View Model类。
如下面的代码所示,我有一个根视图模型类MainViewModel,它可以MonitorPageViewModel在需要时创建其他视图模型(例如)实例。在中MonitorPageViewModel,还需要在需要时创建其他子视图模型(例如MonitorDashboardViewModel)实例。而所有这些视图模型可能有几个依赖(ILogger,IRepository<RawMessage>,IParsingService,等)。
在我以前的WPF项目中,没有使用任何IoC容器,我总是new在需要时在父视图模型中使用子视图模型,并使用ServiceLocator提供所需的服务。现在,我想找出一种更多的依赖注入方式来执行此操作。
我有几种方法(在下面的代码中演示),但是我对其中任何一种都不满意。
MainViewModel;并将IoC容器实例注入到MainViewModel; 然后,使用IoC容器实例解析子视图模型构造函数所需的每个对象。如果子视图模型类需要解析其他类,则将IoC注入其中。[ 听起来另一个ServiceLocator ]。MainViewModel视图模型及其后代视图模型所需的所有服务,并沿视图模型链传递服务。以及需要new的视图模型实例。[ 需要注入大量服务,并将其传递给 ]我不想Caliburn.Micro在该项目中使用MVVM框架。有没有简单而优雅的解决方案?
public interface ILogger
{
// ...
}
public interface IRepository<T>
{
// ...
}
public interface IStatisticsService
{
// ...
}
public class RawMessage
{
// ...
}
public class Device
{
// ...
}
public class Parser …Run Code Online (Sandbox Code Playgroud) 为什么C#不能将long var隐式转换为对象var然后转换为ulong?
long a = 0;
Object c = a;
ulong b = (ulong)c; // throw exception here
Run Code Online (Sandbox Code Playgroud) 我是 node 和 typescript 的新手,在编译 typescript 项目时遇到了麻烦。我已经阅读了关于 SO 的 serval 帖子,但仍然无法解决我的问题。
有人可以帮我解决这个问题吗?
tsconfig.json:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"noLib": false
},
"files": [
"typings/index.d.ts"
]
}
Run Code Online (Sandbox Code Playgroud)
打字/index.d.ts:
/// <reference path="globals/angular-protractor/index.d.ts" />
/// <reference path="globals/core-js/index.d.ts" />
/// <reference path="globals/jasmine/index.d.ts" />
/// <reference path="globals/koa/index.d.ts" />
/// <reference path="globals/node/index.d.ts" />
/// <reference path="globals/require/index.d.ts" />
/// <reference path="globals/selenium-webdriver/index.d.ts" />
/// <reference path="globals/sequelize/index.d.ts" />
/// <reference path="globals/typescript/index.d.ts" />
Run Code Online (Sandbox Code Playgroud)
报告的错误: …
c# ×3
wpf ×3
node.js ×2
qt ×2
sql ×2
sql-server ×2
autofac ×1
casting ×1
database ×1
generics ×1
hash ×1
javascript ×1
mvvm ×1
qtabwidget ×1
regex ×1
routes ×1
t-sql ×1
tsc ×1
wpf-interop ×1
xaml ×1