小编flq*_*flq的帖子

将属性应用于返回值 - 在F#中

在C#中,可以将一个属性应用于方法的返回:

[return: DynamicAttribute]
public object Xyz() {
  return new ExpandoObject();
}
Run Code Online (Sandbox Code Playgroud)

这可能在F#中吗?

背景:

我想要一个用F#编写的库的方法,它将以类似C#的语言使用,以从方法返回"动态".如果我查看从C#编译的类似定义的方法,似乎返回类型是对象,DynamicAttribute应用于对象的返回值.

c# f# dynamic .net-4.0

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

将NUnit与PCL结合使用

我似乎遇到了各种各样的问题,试图让NUint与PCL库玩得很好.我的PCL库面向.NET 4.5,Silverlight 4及更高版本,Windows Phone 7.5,Windows Store,Mono for Android和MonoTouch(最后两个与Xamarin).但是,当我尝试通过NuGet将NUnit添加到项目时,看起来它被添加(nunit.framework被添加到引用中)但是NUnit命名空间不可用.如果我尝试添加一个using NUnit.Framework,Visual Studio强调它,如果我尝试构建,我得到一个关于NUnit命名空间的错误与此警告一起找不到:

Warning 2   The primary reference "nunit.framework" could not be resolved because it has an indirect dependency on the framework assembly "mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETPortable,Version=v4.0,Profile=Profile104". To resolve this problem, either remove the reference "nunit.framework" or retarget your application to a framework version which contains "mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".
Run Code Online (Sandbox Code Playgroud)

NUnit可以与PCL一起使用吗?该MVVM交叉教程似乎肯定来管理它.

我尝试创建一个单独的测试项目(常规类库),我可以添加NUnit,但是我似乎无法添加对我的PCL库(我要测试的那个)的引用,所以这样做帮助.

有任何想法吗?

nunit visual-studio-2010 portable-class-library

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

为什么打字稿不会抱怨某些未定义的变量

我有以下示例:

class Uncle {
  constructor(public name : string) { }

  talk() {
    return "Hello my name is " + name;
  }
}

let p : Uncle = new Uncle("Jo");
console.log(p.talk());
Run Code Online (Sandbox Code Playgroud)

对于某些变量名称,typescript(现在版本2.1.4)不会抱怨它们没有在您的程序中定义(在方法talk中,名称正在使用而没有这个.).name就是其中之一.

如果我将变量重命名为,比方说,firstName编译器正确地抱怨......

错误TS2663:找不到名称'firstName'.你的意思是实例成员'this.firstName'吗?

同样适用于例如窗口,显然假设存在.

我的问题是:

  • 假设存在哪些变量名称,为什么?
  • 是否可以改变这种行为(例如,在某些短语中,您可以说明您期望全局可用的变量)?

javascript typescript tsc

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

具有membus和ioc容器的SetHandlerInterface()的多个类型

此处查看演示CQRS代码,命令和事件处理程序分别连接如下:

public interface CommandHandler<in T>
{
    void Handle(T command);
}

public interface EventHandler<in T>
{
    void Handle(T @event);
}

bus = BusSetup.StartWith<Conservative>()
       .Apply<FlexibleSubscribeAdapter>(a =>
       {
           a.ByInterface(typeof(IHandleEvent<>));
           a.ByInterface(typeof(IHandleCommand<>));
       })
       .Construct();
Run Code Online (Sandbox Code Playgroud)

我正在使用一个与membus挂钩的IoC容器,它通过实现IEnumerable<object> GetAllInstances(Type desiredType)与容器的接口实现梦想,但是与使用这种注册方法的演示不同,我无法拆分单独命令和事件的接口:

this.Bus = BusSetup.StartWith<Conservative>()
    .Apply <IoCSupport>(c =>
        {
            c
            .SetAdapter(SimpleInjectorWiring.Instance)
            .SetHandlerInterface(typeof(CommandHandler<>))
            /*.SetHandlerInterface(typeof(EventHandler<>))*/;
            // only CommandHandler or EventHandler can be used - not both
        })
    .Construct();
Run Code Online (Sandbox Code Playgroud)

任何人都可以告诉我,如果有任何方法,所以我们可以注册任意数量的类型?

cqrs membus

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

是否可以通过TypeDescriptor访问对象的索引器?

我很难通过TypeDescriptor获取有关对象索引器的信息 - 只是为了确定,我的意思是:

class ComponentWithIndexer
{
    public string this[int i]
    {
        get { return "hello"; }
    }
}
Run Code Online (Sandbox Code Playgroud)

由于您可以通过自定义Typedescript来影响WPF中的绑定,并且因为您可以绑定到WPF中的索引器(例如{Binding [12]),我想知道索引器的信息是否也可以通过类型描述符获得.那么,信息隐藏在哪里,如果它没有隐藏,那么WPF绑定索引器的工作原理是什么?

.net data-binding wpf typedescriptor

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

GraphQL中的代数数据类型

有没有一种技术可以让我在GraphQL中这样声明ADT?

// TypeScript
type SomeAlgebraicDataType = 
  | { state: 'A', subState1: string }
  | { state: 'B', subState2: string, subState3: number }
  | { state: 'C', subState4: string, subState5: string, subState6: number }
Run Code Online (Sandbox Code Playgroud)

注意如何基于state鉴别符来推断结构的其余部分。

下面是一些伪造的代码,说明了这个想法:

union AlgebraicDataType = StateA | StateB | StateC

type StateA {state: StateDiscriminator.A, subState1: String }
type StateB {state: StateDiscriminator.B, subState2: String, subState3: Int }
type StateC {state: StateDiscriminator.C, subState4: String, subState5: String, subState6: Int}

enum StateDiscriminator { A B C }
Run Code Online (Sandbox Code Playgroud)

algebraic-data-types graphql graphql-js

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

Oracle 11g的NHibernate TransactionScope问题

以下代码片段适用于SQL Server 2008(SP1),但对于Oracle 11g,对session.BeginTransaction()的调用会抛出异常,并显示消息"Connection已经是本地或分布式事务的一部分"(下面显示的堆栈跟踪) .使用'"NHibernate.Driver.OracleDataClientDriver".

有没有其他人遇到这个?

using (var scope = new TransactionScope())
{
   using (var session = sessionFactory.OpenSession())
   using (var transaction = session.BeginTransaction())
   {
      // do what you need to do with the session
      transaction.Commit();
    }
    scope.Complete();
}
Run Code Online (Sandbox Code Playgroud)
     Exception at:    at NHibernate.Transaction.AdoTransaction.Begin(IsolationLevel isolationLevel)
           at NHibernate.Transaction.AdoTransaction.Begin()
           at NHibernate.AdoNet.ConnectionManager.BeginTransaction()
           at NHibernate.Impl.SessionImpl.BeginTransaction()
           at MetraTech.BusinessEntity.DataAccess.Persistence.StandardRepository.SaveInstances(List`1& dataObjects) in S:\MetraTech\BusinessEntity\DataAccess\Persistence\StandardRepository.cs:line 3103

        Inner error message was: Connection is already part of a local or a distributed transaction
        Inner exception at:    at Oracle.DataAccess.Client.OracleConnection.BeginTransaction(IsolationLevel isolationLevel)
           at Oracle.DataAccess.Client.OracleConnection.BeginDbTransaction(IsolationLevel isolationLevel)
           at …

oracle nhibernate transactionscope

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

WPF:我可以通过样式定义/设置附加属性吗?

有没有办法通过Style设置附加属性?

我有一个按钮,其上设置了交互内容(来自System.Windows.Interactivity)

<Button>
  <i:Interaction.Triggers>
    ...
  </i:Interaction.Triggers>
</Button>
Run Code Online (Sandbox Code Playgroud)

现在我想创建一个设置了Interaction.Triggers属性的样式,从而通过必须在每个Button实例上指定该属性来替换冗余.这可能在WPF中吗?

<Style Target={x:Type Button}>
  <!-- ??? -->
  <Setter PropertyName="i.Interaction.Triggers">
  ...
Run Code Online (Sandbox Code Playgroud)

不知怎的,我怎么看不清楚,但是我在网上看到了其他的例子,其中附加的属性似乎可以从一个样式中访问...

更新

所以基本上这是一个与Interaction.Triggers没有办法"设置"某事的问题.我该如何重用一组交互定义?

.net silverlight wpf

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

如何在TypeScript中获取类方法的返回类型

在较新的TypeScript版本中(我认为2.8以后?),我可以轻松获得函数的返回类型:

function f() { return "hi"; }
type MyType = ReturnType<typeof f>; //MyType is string
Run Code Online (Sandbox Code Playgroud)

但我无法想出从类方法中获取相同的信息......

class MyClass {
  foo() { return "hi"; }
}
Run Code Online (Sandbox Code Playgroud)

我如何获得返回类型(new MyClass()).foo()

typescript typescript3.0

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

c#中可读的良好可读名称

我在FsUnit中读到以下是F#中有效的方法/类名:

[<TestFixture>] 
type ``Given a LightBulb that has had its state set to true`` ()=
   let lightBulb = new LightBulb(true)

   [<Test>] member test.
    ``when I ask whether it is On it answers true.`` ()=
       lightBulb.On |> should be True
Run Code Online (Sandbox Code Playgroud)

有没有办法在c#中使用这样的方法或类名?

c# f# unit-testing naming

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