简体   繁体   English

C#“使用”我做对了吗? (由于保护级别而无法访问)

[英]C# 'using' Am I doing this right? (Inaccessable due to protection level)

http://www.dscredstorm.com/getisbninfo.aspx http://www.dscredstorm.com/getisbninfo.aspx

I'm trying to use Amazon's api. 我正在尝试使用Amazon的api。 I downloaded their example code, which is a C# windows form app but I figured it should work for a C# website also, correct? 我下载了他们的示例代码,这是一个C#Windows窗体应用程序,但我认为它也适用于C#网站,对吗?

SignedRequestHelper.cs is a file that appears to have some functionality that I need to send a signed request. SignedRequestHelper.cs是一个文件,该文件似乎具有一些需要发送已签名请求的功能。 It's namespace is AmazonProductAdvtApi. 它的名称空间是AmazonProductAdvtApi。 I put the file in App_Code/Csharp and I added 'using AmazonProductAdvtApi;' 我将文件放在App_Code / Csharp中,并添加了“ using AmazonProductAdvtApi;”。 to my page. 到我的页面。

But I get this error: 'AmazonProductAdvtApi.SignedRequestHelper' is inaccessible due to its protection level 但我收到此错误:由于其保护级别,无法访问“ AmazonProductAdvtApi.SignedRequestHelper”

Why? 为什么?

More info: SignedRequestHelper helper = new SignedRequestHelper(accessKeyId, secretKey, destination); 更多信息:SignedRequestHelper helper = new SignedRequestHelper(accessKeyId,secretKey,destination);

See: http://www.dscredstorm.com/getisbninfo.aspx 请参阅: http//www.dscredstorm.com/getisbninfo.aspx

Here is the class declaration for SignedRequestHelper.cs: 这是SignedRequestHelper.cs的类声明:

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Security.Cryptography;

namespace AmazonProductAdvtApi
{
    class SignedRequestHelper
    ...
    ... some private consts and vars...

    public SignedRequestHelper(string awsAccessKeyId, string awsSecretKey, string destination)
    {
        this.endPoint = destination.ToLower();
        this.akid = awsAccessKeyId;
        this.secret = Encoding.UTF8.GetBytes(awsSecretKey);
        this.signer = new HMACSHA256(this.secret);
    }

The class isn't marked public; 该课程未标记为公开; therefore, it's inaccessible from other namespaces. 因此,无法从其他名称空间访问它。

Most likely the other Amazon classes that use it are also in the AmazonProductAdvtApi namespace, so they don't have problems (a class with no explicit visibility gets internal by default). 最有可能使用它的其他Amazon类也在AmazonProductAdvtApi命名空间中,因此它们没有问题(默认情况下, internal没有显式可见性的类)。

If you want to use that class, change its declaration to public class SignedRequestHelper . 如果要使用该类, public class SignedRequestHelper其声明更改为public class SignedRequestHelper Just be aware that the class may not be intended for public consumption, ie may lack certain types of error-checking that you'd normally expect in a public API. 请注意,该类可能不适合公共使用,即可能缺少通常在公共API中期望的某些类型的错误检查。

Perhaps this is not the public interface they want you to use. 也许这不是他们希望您使用的公共接口。 Maybe there is a public class that wraps this class. 也许有一个公共课程来包装这个课程。

"inaccessible due to its protection level" means you're trying to reference an item outside its intended scope, ie creating an instance of a private class from another unrelated class. “由于其保护级别而无法访问”表示您正在尝试引用其预期范围之外的项目,即从另一个不相关的类创建一个私有类的实例。 the using statement doesn't appear to be the problem here. using语句在这里似乎不是问题。

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

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