【问题标题】:'Internal' is inaccessible due to its protection level“内部”因其保护级别而无法访问
【发布时间】:2017-02-04 11:41:36
【问题描述】:

我正在尝试为 Load 创建一个方法,但是当我在该方法中使用 Internal 时,它告诉我 Internal 由于其保护级别而无法访问。这是一个例子:

public class Internals
{

    // ---- PROPERTIES ---------------------------------------------

    /// <summary>
    /// Gets or sets internal data not required to edit a <see cref="Mdl0VertexData"/> instance.
    /// </summary>
    public Internals Internal { get; set; }

    /// <summary>
    /// Gets or sets the size of one full element in the raw data array, in bytes.
    /// </summary>
    public uint Length { get; set; }

    /// <summary>
    /// Gets or sets the raw data as a byte array.
    /// </summary>
    public uint Mdl0Offset { get; set; }

    /// <summary>
    /// Gets or sets the raw data as a byte array.
    /// </summary>
    public uint DataOffset { get; set; }

    /// <summary>
    /// Gets or sets the raw data as a byte array.
    /// </summary>
    public uint NameOffset { get; set; }

    /// <summary>
    /// Gets or sets the raw data as a byte array.
    /// </summary>
    public uint Index { get; set; }

    /// <summary>
    /// Gets or sets the raw data as a byte array.
    /// </summary>
    public uint ComponentCount { get; set; }

    /// <summary>
    /// Gets or sets the raw data as a byte array.
    /// </summary>
    public uint Format { get; set; }

    /// <summary>
    /// Gets or sets the raw data as a byte array.
    /// </summary>
    public Byte Divisor { get; set; }

    /// <summary>
    /// Gets or sets the raw data as a byte array.
    /// </summary>
    public Byte Stride { get; set; }

    /// <summary>
    /// Gets or sets the raw data as a byte array.
    /// </summary>
    public UInt16 VertexCount { get; set; }

    /// <summary>
    /// Gets or sets the raw data as a byte array.
    /// </summary>
    public UInt32 minimum1 { get; set; }

    public UInt32 minimum2 { get; set; }
    public UInt32 minimum3 { get; set; }
    public UInt32 maximum1 { get; set; }
    public UInt32 maximum2 { get; set; }
    public UInt32 maximum3 { get; set; }
    public UInt32 LayerCount { get; set; }
    public UInt32 LayerSize { get; set; }
    public UInt32 Padding1 { get; set; }
    public UInt32 Padding2 { get; set; }
    public UInt32 Padding3 { get; set; }
    public UInt32 Padding4 { get; set; }
    public UInt32 Padding5 { get; set; }
    public UInt32 Padding6 { get; set; }
        /// <summary>
        /// Gets or sets the offset to the first byte of the vertex buffer data.
        /// </summary>
        public Brres.BrresOffset Offset {
            get;
            set;
        }
    }
    private void Load(BrresLoaderContext context)
    {
        Internal = new Internals();

        Internal.Length = context.Reader.ReadUInt32();
        Internal.Mdl0Offset = context.Reader.ReadUInt32();
        Internal.DataOffset = context.Reader.ReadUInt32();
        Internal.Index = context.Reader.ReadUInt16();
        Internal.ComponentCount = context.Reader.ReadUInt16();
        Internal.Format = context.Reader.ReadUInt32();
        Internal.Divisor = context.Reader.ReadByte();
        Internal.Stride = context.Reader.ReadByte();
        Internal.VertexCount = context.Reader.ReadUInt16();
        Internal.minimum1 = context.Reader.ReadUInt32();
        Internal.minimum2 = context.Reader.ReadUInt32();
        Internal.minimum3 = context.Reader.ReadUInt32();
        Internal.maximum1 = context.Reader.ReadUInt32();
        Internal.maximum2 = context.Reader.ReadUInt32();
        Internal.maximum3 = context.Reader.ReadUInt32();
        Internal.LayerCount = context.Reader.ReadUInt32();
        Internal.LayerSize = context.Reader.ReadUInt32();
        Internal.Padding1 = context.Reader.ReadUInt32();
        Internal.Padding2 = context.Reader.ReadUInt32();
        Internal.Padding3 = context.Reader.ReadUInt32();
        Internal.Padding4 = context.Reader.ReadUInt32();
        Internal.Padding5 = context.Reader.ReadUInt32();
        Internal.Padding6 = context.Reader.ReadUInt32();
    }

显然,课程是公开的,我该怎么办?

【问题讨论】:

  • BrresLoaderContext 公开吗?
  • BrresLoaderContext 是一个内部类。这能公开吗?我对 c# 有点陌生
  • 它们是不同的。看这里:stackoverflow.com/questions/4182015/…
  • @iSYan 这可能是问题所在。您已将属性Offset 标记为public(在同样为public 的类中),但类型为internal。你也可以公开那堂课吗? (或者将该属性更改为internal。)
  • 看起来 Internal 是一个属性的名称,因为您没有在 Load 方法期间声明它。它有一个公共二传手吗?是遗传的吗?

标签: c#


【解决方案1】:

您没有正确声明 Internal。您需要使用正确的类型声明它:

 Internals  Internal = new Internals();

或使用var,以便编译器可以决定哪个是正确的类型。

 var  Internal = new Internals();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-13
    • 1970-01-01
    • 1970-01-01
    • 2015-09-26
    • 2011-09-01
    相关资源
    最近更新 更多