小编kog*_*oia的帖子

使用反射在内部类中使用参数实例化构造函数

我有类似的东西:

object[] parameter = new object[1];
parameter[0] = x;
object instantiatedType =
Activator.CreateInstance(typeToInstantiate, parameter);
Run Code Online (Sandbox Code Playgroud)

internal class xxx : ICompare<Type>
{
    private object[] x;

    # region Constructors

    internal xxx(object[] x)
    {
        this.x = x;
    }

    internal xxx()
    {
    }

    ...
}
Run Code Online (Sandbox Code Playgroud)

我得到:

抛出异常:System.MissingMethodException:找不到类型为"xxxx.xxx"的构造函数..

有任何想法吗?

c# reflection

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

如何为所有项目更改Visual Studio 2017默认语言版本?

如何在C#7.0上为所有项目设置语言版本?

项目/属性/构建/高级... /高级构建设置屏幕

默认参数来自哪里,我想更改默认值

PS:我不是指UI语言

c# visual-studio

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

哪些术语对应于类别理论中的Map,Filter,Foldable,Bind等?

我开始感兴趣,并没有在一个地方找到相应术语的列表:

Map <-> Morphism

Foldable <-> Catamorphism

...

谁可以补充术语列表

math functional-programming lambda-calculus category-theory

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

F#List.collect与C#List.SelectMany中的相同吗?

List.collect是LINQ List.SelectMany的等价物吗?

[1;2;3;4] |> List.collect (fun x -> [x * x]) // [1;4;9;16]
Run Code Online (Sandbox Code Playgroud)

在LINQ

new List<int>() { 1, 2, 3, 4 }
       .SelectMany(x => new List<int>() { x * x }); // 1;4;9;16
Run Code Online (Sandbox Code Playgroud)

编辑:

更合适的例子

let list1 = [1;2;3;4]
let list2 = [2;4;6]

// [2; 4; 6; 4; 8; 12; 6; 12; 18; 8; 16; 24]
list1 |> List.collect (fun a -> list2 |> List.map (fun b -> a * b)) 
Run Code Online (Sandbox Code Playgroud)

...

var list1 = new List<int>() { 1, 2, …
Run Code Online (Sandbox Code Playgroud)

c# linq f#

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

从c#调用Windows身份验证的WCF服务

我们有一个经过Windows身份验证的WCF服务.绑定配置如下.

<basicHttpBinding>
    <binding textEncoding="utf-8" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
        <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows" />            
        </security>
    </binding>
</basicHttpBinding>
Run Code Online (Sandbox Code Playgroud)

我试图从测试应用程序调用该服务,因为,

try
{
    BasicHttpBinding binding = new BasicHttpBinding();
    binding.ReceiveTimeout = new TimeSpan(10, 10, 00);
    binding.SendTimeout = new TimeSpan(10, 10, 00);
    binding.MaxReceivedMessageSize = Int32.MaxValue;
    binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
    binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
    EndpointAddress endpoint = new EndpointAddress("ServiceUrl");

    ChannelFactory<ICRMConnectorService> channelFactory = new ChannelFactory<ICRMConnectorService>(binding, endpoint);
    channelFactory.Credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
    var service = channelFactory.CreateChannel();

    service.TestMethod();
}
catch (Exception ex)
{
    throw ex;
}
Run Code Online (Sandbox Code Playgroud)

该调用返回错误,因为远程服务器返回错误:(401)未经授权.

有人可以帮忙吗?

c# wcf windows-authentication

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

无法将泛型类型的对象强制转换为通用接口C#

我有两个接口:

public interface IDbModel {}
public interface IDmModel {}
Run Code Online (Sandbox Code Playgroud)

和派生自这的类:

public class DbModel : IDbModel {}
public class DmModel : IDmModel {}
public class Middle { }
Run Code Online (Sandbox Code Playgroud)

另外我有两个限制接口:

public interface IRule { }
public interface IRule<in TInput, out TOutput> : IRule
    where TInput : IDmModel
    where TOutput : IDbModel
{
    TOutput Apply(TInput elem);
}
Run Code Online (Sandbox Code Playgroud)

从这个接口派生出一个抽象类:

public abstract class Rule<TDmModel, TMiddle, TDb> : IRule<TDmModel, TDb>
    where TDmModel : IDmModel
    where TDb : IDbModel
{
    private readonly Func<TDmModel, TMiddle> _rule;
    protected Rule(Func<TDmModel, …
Run Code Online (Sandbox Code Playgroud)

c# generics inheritance multiple-inheritance

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

C#接口和Haskell类型类的区别

我知道这里有一个类似的问题,但我希望看到一个例子,它清楚地表明,你不能做什么,interface可以使用Type Class

为了比较,我将给你一个示例代码:

class Eq a where 
    (==) :: a -> a -> Bool
instance Eq Integer where 
    x == y  =  x `integerEq` y
Run Code Online (Sandbox Code Playgroud)

C#代码:

interface Eq<T> { bool Equal(T elem); }
public class Integer : Eq<int> 
{
     public bool Equal(int elem) 
     {
         return _elem == elem;
     }
}
Run Code Online (Sandbox Code Playgroud)

如果没有正确理解,请纠正我的例子

c# haskell interface typeclass

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

多个linq"from"和变量可见性

我试图理解为什么这个linq不编译(fundInvoices不可见):

Dictionary<Fund, IEnumerable<Invoice>> paidfundInvoices;
...
from fundInvoices in paidfundInvoices
from p in fundInvoices.Value
group p by p.VendorId into ps
select new Payment
{
    FundId = fundInvoices.Key.FundId, // ERROR here
    Value = ps.Sum(p => p.Amount)
}
Run Code Online (Sandbox Code Playgroud)

所以我继续将其更改为匿名类型用法,并且基金发票在这里神奇可见:

from fundInvoices in paidfundInvoices
select new
{
    Fund = fundInvoices.Key,
    Payments = from p in fundInvoices.Value
               group p by p.VendorId into ps
               select new Payment
               {
                   FundId = fundInvoices.Key.FundId,  // NO ERROR                                                                                                                                    
                   Value = ps.Sum(p => p.Amount)
               }
};
Run Code Online (Sandbox Code Playgroud)

但是这种匿名类型似乎是多余的,我没有使用它.我只需要一个 …

c# linq grouping

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

如何在F#中按字母顺序排序字符串?

我有string"DBCA"并希望在F#中对它进行排序

let sortedString str =
    ...

printfn "%A" <| sortedString "DBCA" // "ABCD"
Run Code Online (Sandbox Code Playgroud)

C#上的代码示例

String
    .Concat(
        _str
            .OrderBy(ch => ch)
    );
Run Code Online (Sandbox Code Playgroud)

arrays sorting string f# char

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

F#中的Haskell应用函数

在Haskell中,我们可以编写如下代码:

// (<*>) :: Applicative f => f (a -> b) -> f a -> f b
// const :: a -> b -> a
// id :: b -> b
let id = const <*> const
Run Code Online (Sandbox Code Playgroud)

如何在F#中做同样的事情?

我尝试编写类似这样的代码,但它不一样

let ( <*> ) f v =
    match v with
    | Some v' -> 
        match f with 
        | Some f' -> Some (f' v')
        | _ -> None
    | _ -> None
let cnst a _ = a
let id = …
Run Code Online (Sandbox Code Playgroud)

f# haskell functional-programming functor applicative

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