小编Tob*_*ler的帖子

angular 2包括html模板

在角度2我需要创建一个带有冗余部分的大型html模板.因此,我想创建多个html模板,并将它们包含在主html文件中(如angular1中的ng-include)

但是如何在主模板中包含子模板?

例:

<!-- test.html -->

<div>
    this is my Sub-Item
    <!-- include sub1.html here-->
</div>
<div>
    this is second Sub-Item
    <!-- include sub2.html here-->
</div>
Run Code Online (Sandbox Code Playgroud)

-

<!-- sub1.html -->
<div>
    <button>I'am sub1</button>
</div>
Run Code Online (Sandbox Code Playgroud)

-

<!-- sub2.html -->
<div>
    <div>I'am sub2</div>
</div>
Run Code Online (Sandbox Code Playgroud)

html angular

20
推荐指数
1
解决办法
3万
查看次数

Visual Studio 2015,Resharper冻结调试UnitTests

我正在使用Visual Studio 2015社区版(Windows 10)并启用了resharper-extension(包括调试选项).

当我开始调试我的c#-Test类时,Visual Studio会冻结,我必须最小化并最大化VS以获得刷新的屏幕(对于每个调试步骤).

当我禁用Resharper的debugging-Option并使用内置VS调试时,一切正常.

我想使用Resharper因为它更舒服.

有没有人知道这只是一个我必须设置的选项?

编辑:VS只在我调试单元测试时冻结.

c# debugging resharper visual-studio-2015

15
推荐指数
2
解决办法
2220
查看次数

VSCode c#添加对自定义程序集的引用

在Visual Studio代码中我只想添加对自定义c#程序集的引用

"../libs/mylib.dll"

我该如何添加这种依赖?

我试图添加路径到依赖,但无法编译,因为它只是错误的:)

"dependencies": {
    "myassembly" : "../libs/Common.dll"
  },
Run Code Online (Sandbox Code Playgroud)

要么

"dependencies": {
    "log4net" : { "assembly":"../libs/log4net.dll" }
  },
Run Code Online (Sandbox Code Playgroud)

c# visual-studio-code

9
推荐指数
2
解决办法
1万
查看次数

angular 2命名空间模型

如何在角度2中使用模型类?

这是一个例子

模型

namespace model.car {
    export class CoolCar {
        Id: string;
        Name: string;

        constructor(){
        }
    }

    export class NiceCar {
        Id: string;
        Name: string;

        constructor(){
        }
    }
}

namespace model.bike {
    export class AwesomeBike {
        Id: string;
        Name: string;

        constructor(){
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我想在我的课堂上使用它们

var car=new model.car.CoolCar();
Run Code Online (Sandbox Code Playgroud)

但是当我在浏览器中运行它时,我收到一个错误

"ReferenceError: 'model' is undefined"
Run Code Online (Sandbox Code Playgroud)

我试着像这样导入模型类

import {CoolCar} from '../model/car/CoolCar'
Run Code Online (Sandbox Code Playgroud)

但后来我在VS2015中遇到错误:

File "c:/...../model/car/CoolCar.ts is" no module
Run Code Online (Sandbox Code Playgroud)

有人可以帮我吗?

托比亚斯

typescript angular

7
推荐指数
1
解决办法
1万
查看次数

SQL Update非常慢(大约20-50秒),Select只需不到1秒

我有一个SQL Tabe"文档",其中包含很多行(最多几百万).

当我执行Select-Statement时,大约需要0.5秒.但是当我使用完全相同的WHERE子句执行更新时,大约需要20到50秒,具体取决于受影响的行数.

这是我的声明.

//选择

SELECT * FROM Document 
WHERE (State=20 OR State=23) AND 
LetterClosed IS NOT NULL AND 
TYPE=0 AND
SendLetter=1
Run Code Online (Sandbox Code Playgroud)

//更新

UPDATE Document set State=32 
WHERE (State=20 OR State=23) AND 
LetterClosed IS NOT NULL AND 
TYPE=0 AND
SendLetter=1
Run Code Online (Sandbox Code Playgroud)

OR-Mapper在内部将此update-statement发送到数据库:

exec sp_executesql N'Update
Document
SET
    State=@p4
WHERE
(
  (
    (
      (Document.State = @p0 OR Document.State = @p1) 
      AND Document.LetterClosed IS NOT NULL
    ) 
    AND Document.Type = @p2
  ) 
  AND Document.SendLetter = @p3
)'
,N'@p0 int,@p1 int,@p2 int,@p3 bit,@p4 int',@p0=20,@p1=23,@p2=0,@p3=1,@p4=32 …
Run Code Online (Sandbox Code Playgroud)

sql sql-server select timeout lightspeed

6
推荐指数
1
解决办法
2万
查看次数

等待动态创建的任务,直到完成

我的程序正在创建一些任务来完成一些工作.现在我想在退出程序之前等待所有任务完成.

我知道Task.WaitAll(...)方法,但在我的情况下,我想动态创建一些任务 - > Task.WaitAll()调用时它们不存在.

我现在的问题是:如何完成所有正在运行的任务?

这就是我现在正在做的事情.

它有效,但我想确保这也是一个很好的方法.

public class Test
{
    public ConcurrentBag<Task> RunningTasks { get; set; } 

    public Test()
    {
        RunningTasks = new ConcurrentBag<Task>();
    }

    public void RunIt(){

        //...create some Tasks asynchronously so they may be created in a few seconds and add them to the list like
        //RunningTasks.Add(...);


        //Just wait until all tasks finished.
        var waitTask = Task.Run(() =>
        {
            while (true)
            {
                if (RunningTasks.All(t => t.IsCompleted))
                    break;

                Thread.Sleep(1000);
            }
        });

        waitTask.Wait();

    }
}
Run Code Online (Sandbox Code Playgroud)

c# multithreading task

6
推荐指数
1
解决办法
1153
查看次数

将静态变量(超出范围)绑定到Angular/typescript中的html

我创建了一个小测试typescript/angularjs网站.

我有一个静态变量的模块,我想绑定到html文档,以便我可以看到当前登录的用户.

module mytest.constants {

    export class CurrentSession {

        public static CURRENT_USER: string = "Tobi";

    }
}
Run Code Online (Sandbox Code Playgroud)

问题是:当前作用域是一个与我的CurrentSession类分开的控制器.

我想做点什么

<div class="label" style="color:green">
  Logged in as: {{mytest.constants.CurrentSession.CURRENT_USER}}
</div>
Run Code Online (Sandbox Code Playgroud)

我可以做的另一种方法是将一个类成员添加到控制器并在构造函数中设置它:

this.CurrentUSer = mytest.constants.CurrentSession.CURRENT_USER
Run Code Online (Sandbox Code Playgroud)

但我更喜欢将静态变量直接绑定到html文件.

这可能吗?

angularjs typescript

5
推荐指数
2
解决办法
6688
查看次数

带接口的 JsonConverter

我有一个来自客户端并自动从 Web Api 2 反序列化的对象。

现在我的模型的一个属性有问题。此属性“CurrentField”属于 IField 类型,此接口有 2 种不同的实现。

这是我的模型(只是一个假人)

public class MyTest
{
    public IField CurrentField {get;set;}
}

public interface IField{
    string Name {get;set;}
}

public Field1 : IField{
    public string Name {get;set;}
    public int MyValue {get;set;}
}

public Field2 : IField{
    public string Name {get;set;}
    public string MyStringValue {get;set;}
}
Run Code Online (Sandbox Code Playgroud)

我试图创建一个自定义 JsonConverter 来找出我的客户端对象是什么类型(Field1 或 Field2),但我不知道如何。

我的转换器被调用,当我调用 var obj = JObject.load(reader); 时我可以看到对象。

但我怎样才能知道它是什么类型呢?我不能做类似的事情

if(obj is Field1) ...
Run Code Online (Sandbox Code Playgroud)

这是我应该检查的方法吗?

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer …
Run Code Online (Sandbox Code Playgroud)

c# json asp.net-web-api2

5
推荐指数
1
解决办法
4547
查看次数

C#动态添加属性以接口

我有一个asp.net核心Web服务,它需要正确处理对象的接口属性(必须找出用于对JSON字符串反序列化的实现)。

因此,我创建了一个从interface-Attribute调用的类,例如:

[JsonConverter(typeof(InterfaceJsonConverter<IInputFormat>))]
public interface IInputFormat
{
    // ...
}
Run Code Online (Sandbox Code Playgroud)

定义InterfaceJsonConverter的模型类必须是不支持程序集加载的.NET Standard 1.4。但是,该技术用于找出哪个程序集具有Interface的实现,以及哪个实现最接近json-object。(我当然可以将接口直接添加到类中,而不用读取程序集,但我想要一个动态解决方案,我将永远不会错过任何实现)

(最初,我是在.net 4.6中开发的,在那儿效果很好)。

所以我现在想做的是:

  1. 创建一个新的.NET Standard 1.6库
  2. 将InterfaceJsonConverter放入该库中
  3. 从接口中删除属性
  4. 在运行时添加接口属性...

有什么办法可以存档吗?还是有更好的方法来处理ASP.NET Core中的接口?

出于完整性考虑,我将发布InterfaceJsonConverter的代码

public class InterfaceJsonConverter<T> : Newtonsoft.Json.JsonConverter
{

    public InterfaceJsonConverter()
    {
        this.DerivedTypes = GetTypesOfImplementedInterfaces(typeof(T));

    }
    readonly HashSet<Type> derivedTypes = new HashSet<Type>();

    public InterfaceJsonConverter(params Type[] types)
    {
        this.DerivedTypes = types;
    }

    public InterfaceJsonConverter(System.Reflection.Assembly assembly, string @namespace)
    {
        this.DerivedTypes = GetTypesInNamespace(assembly, @namespace);
    }

    private Type[] GetTypesOfImplementedInterfaces(Type type)
    {
        var parts = type.AssemblyQualifiedName.Split(',');
        var assemblyName = parts[1].Trim();
        var assemblies = …
Run Code Online (Sandbox Code Playgroud)

c# .net-core asp.net-core .net-standard

5
推荐指数
0
解决办法
498
查看次数

MongoDB动态注册类类型

在MongoDB中我需要动态注册类映射,我不需要自己注册所有当前和未来类.

有一个叫做的方法

BsonClassMap.RegisterClassMap<T> 
Run Code Online (Sandbox Code Playgroud)

但有了这个,我需要知道Class(T),而不能使用Type.

我想迭代这样的程序集类型来注册类映射:

var assemblyTypes = AppDomain.CurrentDomain.GetAssemblies().SelectMany(t => t.GetTypes()).Where(t => t.IsClass);
        foreach (var type in assemblyTypes)
        {
            //Register classmap for type
        }
Run Code Online (Sandbox Code Playgroud)

有没有办法做到这一点?

mongodb c#-4.0

2
推荐指数
1
解决办法
1097
查看次数

在 UWP 中将 Ui 事件绑定到命令

我想将任何 UI 事件直接绑定到我的 ViewModel 中的命令。有没有办法在UWP 中做到这一点?

我正在使用 UWP 社区工具包,并希望将 Hamburger-Menu-Item-Click 绑定到一个命令。

谢谢托比亚斯

c# mvvm uwp windows-community-toolkit

1
推荐指数
1
解决办法
5074
查看次数