小编see*_*per的帖子

GitHub页面和相对路径

gh-pages为GitHub正在开发的项目创建了一个分支.

我使用Sublime文本在本地创建网站,我的问题是当它被推送到GitHub时,所有到javascrips,images和css文件的链接都是无效的.

例如,我在脑海中有这个.

<link href="assets/css/common.css" rel="stylesheet">
Run Code Online (Sandbox Code Playgroud)

这在本地工作得很好,但它不适用于GitHub,因为链接未使用存储库名称作为URL的一部分进行解析.

它要求:

http://[user].github.io/assets/css/common.css
Run Code Online (Sandbox Code Playgroud)

什么时候应该要求:

http://[user].github.io/[repo]/assets/css/common.css.
Run Code Online (Sandbox Code Playgroud)

我当然可以将repo名称作为URL的一部分,但这会阻止我的站点在开发期间在本地工作.

知道怎么处理这个吗?

html github

65
推荐指数
4
解决办法
3万
查看次数

垃圾收集异步方法

我刚刚注意到有关垃圾收集的一些非常奇怪的事情.

WeakRef方法按预期收集对象,而异步方法报告对象仍然存活,即使我们已强制进行垃圾回收.有什么想法吗?

class Program
{
    static void Main(string[] args)
    {
        WeakRef();
        WeakRefAsync().Wait();
    }

    private static void WeakRef()
    {
        var foo = new Foo();
        WeakReference fooRef = new WeakReference(foo);
        foo = null;
        GC.Collect();
        Debug.Assert(!fooRef.IsAlive);
    }

    private static async Task WeakRefAsync()
    {
        var foo = new Foo();
        WeakReference fooRef = new WeakReference(foo);
        foo = null;
        GC.Collect();
        Debug.Assert(!fooRef.IsAlive);
    }
}


public class Foo
{

}
Run Code Online (Sandbox Code Playgroud)

c# async-await

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

使用Activator.CreateInstance创建Func <T>实例

有人知道如何动态创建Func<T>实例吗?

//Create the Func type

Type funcType = typeof(Func<>).MakeGenericType(typeof(string)); 

//How do I pass a reference to the anonymous method? 

Activator.CreateInstance(funcType, () => "test");
Run Code Online (Sandbox Code Playgroud)

这不编译:

无法将lambda表达式转换为type,object[]因为它不是委托类型

任何人?

c#

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

功能与自定义委托的性能

我正在研究一些对性能至关重要的代码,并且发现使用委托调用匿名方法比通过Func委托调用相同的代码更糟糕。

public class DelegateTests
{
    public delegate int GetValueDelegate(string test);

    private Func<string, int> getValueFunc;

    private GetValueDelegate getValueDelegate;

    public DelegateTests()
    {
        getValueDelegate = (s) => 42;
        getValueFunc = (s) => 42;                        
    }

    [Benchmark]
    public int CallWithDelegate()
    {
        return getValueDelegate.Invoke("TEST");
    }

    [Benchmark]
    public int CallWithFunc()
    {
        return getValueFunc.Invoke("TEST");
    }
}
Run Code Online (Sandbox Code Playgroud)

BenchmarkDotNet 给出:

// * Summary *

BenchmarkDotNet=v0.10.4, OS=Windows 10.0.14393
Processor=Intel Core i7-4770HQ CPU 2.20GHz (Haswell), ProcessorCount=2
Frequency=10000000 Hz, Resolution=100.0000 ns, Timer=UNKNOWN
  [Host]    : Clr 4.0.30319.42000, 32bit LegacyJIT-v4.6.1637.0
  RyuJitX64 : Clr 4.0.30319.42000, 64bit …
Run Code Online (Sandbox Code Playgroud)

c# performance jit

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

Xamarin.iOS上的MakeGenericMethod/MakeGenericType

我试图找出从Xamarin部署iOS时的限制真正意义.

http://developer.xamarin.com/guides/ios/advanced_topics/limitations/

我的印象是你没有JIT,因此任何MakeGenericMethod或MakeGenericType都不会起作用,因为这需要JIT编译.

另外我明白,当在模拟器上运行时,这些限制不适用,因为模拟器没有在完整的AOT(Ahead of Time)模式下运行.

在设置我的Mac以便我可以部署到我的手机之后,除了以下测试在实际设备(iPhone)上运行时失败.

    [Test]
    public void InvokeGenericMethod()
    {
        var method = typeof(SampleTests).GetMethod ("SomeGenericMethod");

        var closedMethod = method.MakeGenericMethod (GetTypeArgument());

        closedMethod.Invoke (null, new object[]{42});

    }

    public static void SomeGenericMethod<T>(T value)
    {
    }


    private Type GetTypeArgument()
    {
        return typeof(int);
    }
Run Code Online (Sandbox Code Playgroud)

问题是成功完成,我无法理解为什么.这段代码不需要JIT编译吗?

为了"打破它",我还使用MakeGenericType进行了测试.

    [Test]
    public void InvokeGenericType()
    {
        var type = typeof(SomeGenericClass<>).MakeGenericType (typeof(string));

        var instance = Activator.CreateInstance (type);

        var method = type.GetMethod ("Execute");

        method.Invoke (instance, new object[]{"Test"});

    }


public class SomeGenericClass<T>
{
    public void Execute(T value)
    {

    }
}
Run Code Online (Sandbox Code Playgroud)

当没有JIT时,它如何工作? …

c# iphone xamarin.ios ios xamarin

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

将路径转换为 ​​VS Code 代码片段中的命名空间

我正在尝试创建一个 VS 代码片段,该代码片段根据项目中的当前文件夹构建命名空间。

变量提供的当前路径TM_DIRECTORY可能是这样的。

/Users/bernhardrichter/GitHub/heatkeeper2000/src/HeatKeeper.Server/Mapping

我最终想要的结果是namespace HeatKeeper.Server.Mapping基于我的根源文件夹src

所以我需要去掉之前的所有内容,包括在内,src这样我们就只剩下HeatKeeper.Server/Mapping. 然后我需要将 替换(转换)/为,.以便最终结果为HeatKeeper.Server.Mapping

是否可以通过一次转换来完成此操作?如果没有的话是否可以进行多次变换?

这就是我到目前为止所拥有的

"namespace ${TM_DIRECTORY/(.*src.)(.*).*$/$2/}"

这输出namespace HeatKeeper.Server/Mapping几乎就是我想要的。我只需要全部替换/.

问题是我不知道把这个变换放在哪里。

变换看起来像这样。

"${TM_DIRECTORY/[\\/]/./g}"

这给了我

.Users.bernhardrichter.GitHub.heatkeeper2000.src.HeatKeeper.Server.Mapping

我只是不知道如何将这两者结合起来?

regex code-snippets visual-studio-code

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