2

我遇到了一点问题,似乎无法解决,有人可以帮助我,
这些是错误:

错误 1 ​​可访问性不一致:字段类型“Flashloader.Toepassing”的可访问性低于字段“Flashloader.NewApplication.Toepassing”

错误 2 可访问性不一致:参数类型“Flashloader.toepassinginifile”的可访问性低于方法“Flashloader.NewApplication.NewApplication(Flashloader.toepassinginifile)”

因此,在这种情况下,那些错误但有来源的地方非常有用。

源 1 新应用程序(这是一个 Winform):

namespace Flashloader{

public partial class NewApplication : Form
{
    private toepassinginifile _toepassinginifile;

    //private controllerinifile _controlIniFile;

    public Toepassing toepassing = new Toepassing();

    public NewApplication(toepassinginifile iniFile)
    {
        _toepassinginifile = iniFile;

        InitializeComponent();
    }

    private void button4_Click(object sender, EventArgs e)
    {
        this.Close();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        openFileDialog1.Filter = "Srec Files (.a20; .a21; .a26; .a44)|*.a20; *.a21; *.a26; *.a44|All files (*.*)|*.*";

        openFileDialog1.Title = ("Choose a file");
        openFileDialog1.InitialDirectory = Path.Combine(Directory.GetCurrentDirectory());
        openFileDialog1.RestoreDirectory = true;
        if (openFileDialog1.ShowDialog() == DialogResult.OK)
        {
            fileBox.Text = (System.IO.Path.GetFileName(openFileDialog1.FileName));
        }
    }

    private void button3_Click(object sender, EventArgs e)
    {
        toepassing.Name = nameBox.Text;
        toepassing.Controller = controllerComboBox.SelectedItem;
        toepassing.TabTip = descBox.Text;
        toepassing.Lastfile = openFileDialog1.FileName;
        fileBox.Text = openFileDialog1.FileName;


        if (nameBox.Text == "")
            MessageBox.Show("You haven't assigned a Name");
        else if (controllerComboBox.Text == "")
            MessageBox.Show("You haven't assigned a Controller");
        else if (descBox.Text == "")
            MessageBox.Show("You haven't assigned a Desciption");
        else if (fileBox.Text == "")
            MessageBox.Show("You haven't assigned a Applicationfile");
        _toepassinginifile.ToePassingen.Add(toepassing);
        _toepassinginifile.Save();

        MessageBox.Show("Save Succesfull");



        this.Close();
    }

}}

源 2 flashloader.toepassing 文件(这是一个类):

namespace Flashloader{
class Toepassing
{
    private String _name;

    public String Name
    {
        get { return _name; }
        set { _name = value; }
    }

    public Controller Controller = null;
    public String TabTip = "";
    public String Lastfile = "";

  [Obsolete]
  public String Baudrate = "";

  [Obsolete]
  public String Port = "";

  public String Useboot = "";

    public Toepassing()
    {
        Name = "";
    }

    public Toepassing(String naam)
    {
        Name = naam;
    }

    public override String ToString()
    {
        return Name + " :" + TabTip;
    }
}
}

最后是 source 3 flashloader.toepassinginifile(另一个类):

namespace Flashloader
{
class toepassinginifile
{
    private const String FILE_NAME = "flash.ini";
    private Controllerlist _controllers;
    public Toepassinglist ToePassingen { get; private set; }
    public Settings Settings { get; private set; }


    public toepassinginifile( Controllerlist controllers)
    {
        _controllers = controllers;

        // TODO Startup class maken en laden
        ToePassingen = LoadToepassingen();
    }

    private Toepassinglist LoadToepassingen()
    {
        StringList input = new StringList().FromFile( FILE_NAME );
        Toepassinglist output = new Toepassinglist();

        Settings settings = null;
        Toepassing toepassing = null;

        foreach (var item in input)
        {
            String line = item.Trim();

            if (line.StartsWith("[") && line.EndsWith("]"))
            {
                settings = null;
                toepassing = null;

                String name = line.Substring(1, line.Length - 2);

                if (name.ToUpper().Equals("STARTUP"))
                {
                    Settings = settings = new Settings();
                    continue;
                }
                // TODO kan weg in de toekomst
                if ( name.ToUpper().Equals("DRAG && DROP"))
                {
                    toepassing = null;
                    continue;
                } // */

                toepassing = new Toepassing(name);
                output.Add(toepassing);
            }
            else if (settings != null)
            {
                int index = line.IndexOf('=');
                if (index < 0)
                    continue;

                String key = line.Substring(0, index).Trim();
                String value = line.Substring(index + 1).Trim();

                if (Utils.EqualsIgnoreCase(key, "Baudrate"))
                    Settings.Baudrate = value;
                else if (Utils.EqualsIgnoreCase(key, "Port"))
                    Settings.Port = value;
            }
            else if (toepassing != null)
            {
                int index = line.IndexOf('=');
                if (index < 0)
                    continue;

                String key = line.Substring(0, index).Trim();
                String value = line.Substring(index + 1).Trim();

                if (Utils.EqualsIgnoreCase(key, "TabTip"))
                    toepassing.TabTip = value;
                else if (Utils.EqualsIgnoreCase(key, "Controller"))
                    toepassing.Controller = _controllers.FindByName(value);
                else if (Utils.EqualsIgnoreCase(key, "Lastfile"))
                    toepassing.Lastfile = value;
                else if (Utils.EqualsIgnoreCase(key, "Useboot"))
                    toepassing.Useboot = value;
            }
        }
        return output;
    }

    public void Save()
    {
        StringList list = new StringList();

        Toepassing settings = new Toepassing("[Startup]");

        list.Add("["+settings.Name+"]");
        list.Add("LastUsed=");
        list.Add("Port=" +settings.Port);
        list.Add("Baudrate=" +settings.Baudrate);

        foreach (Toepassing item in ToePassingen)
        {
            list.Add( "[" + item.Name + "]" );
            list.Add( "Controller=" + item.Controller.Name );
            list.Add( "TabTip="+ item.TabTip );
            list.Add("LastFile="+ item.Lastfile);
            list.Add("UseBoot="+ item.Useboot);
        }

        Toepassing dragndrop = new Toepassing("[Drag && Drop]");

            list.Add("["+dragndrop.Name+"]");
            list.Add("Autostart=");
            list.Add("Baudrate="+ dragndrop.Baudrate);
            list.Add("Port="+ dragndrop.Port);
            list.Add("Lasfile="+ dragndrop.Lastfile);

        list.ToFile(FILE_NAME);
    }
}
}

如果我能得到一些帮助,解决错误会容易得多。

修复

4

3 回答 3

8

由于toepassinginifile用于public一种类型的方法public,它本身必须由public(它当前是internal)。改变:

class toepassinginifile

到:

public class toepassinginifile

甚至更好;p

public class ToePassingIniFile

同样对于另一个,因为Toepassing用作类型public上的字段,所以它本身必须是.publicToepassingpublic

最后的想法:public字段很少是一个好主意;一个public 属性会更好:

private Toepassing toepassing = new Toepassing();
public Toepassing Toepassing  {get { return toepassing; } }
于 2013-06-21T06:58:26.573 回答
1

在您的班级声明之前添加 public 。你的第一堂课是公开的,所以 Toepassinginifile 和 Toepassing 也必须是公开的。

于 2013-06-21T06:58:52.250 回答
1

您得到的错误是说您将无法使用您的类中的公共方法,因为该类被标记为私有

默认情况下,类是内部的

class ClassName
{
public void Method()

以上将出错,因为您永远无法调用方法,因为该类的可访问性低于该方法

private bool Property {get; public set;}

可能也会出错

看到这个

于 2013-06-21T07:09:11.693 回答