简体   繁体   English

将 ServiceClientCredentials 作为参数传递给 C# 中的构造函数

[英]Passing ServiceClientCredentials as a paramater to a constructor in C#

I'm trying to implement a REST API client in C# where the constructor takes a parameter off Microsoft.Rest.ServiceClientCredentials.我正在尝试在 C# 中实现一个 REST API 客户端,其中构造函数从 Microsoft.Rest.ServiceClientCredentials 中获取一个参数。 Since it's an abstract class I can't instantiate it and pass it on.由于它是一个抽象类,我无法实例化它并传递它。

The abstract class is a template.抽象类是一个模板。 You can't instantiate a template since there is missing functionlity in it, rendering it incomplete.您无法实例化模板,因为其中缺少功能,使其不完整。 You can instantiate derived class though.不过,您可以实例化派生类。

Check the documentation here for derived credential classes and pick the one that's fitting to your case.检查此处的文档以获取派生凭证类并选择适合您的情况的凭证类。

If you are looking for a username/password case, the BasicAuthenticationCredentials is the concrete class for you.如果您正在寻找用户名/密码案例, BasicAuthenticationCredentials是您的具体类。

You can instantiate it你可以实例化它

var bauthCredentials = new BasicAuthenticationCredentials();
functionThatTakesServiceClientCredentials(bauthCredentials);

And the function is something like this:功能是这样的:

public void functionThatTakesServiceClientCredentials(ServiceClientCredentials bauthCredentials) {
    // Do stuff
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM