-1

如果这个问题不是很清楚,我很抱歉,如果是,请告诉我我需要更新/详细说明,谢谢!

当我更新另一个字符串时,我的字符串似乎不会自行更新。对不起,但这很难用文字解释,尤其是对我来说,我的英语不是很好,所以我很抱歉。这是我目前的代码:

public class Paths
{
    /// <summary>
    /// The current selected server.
    /// </summary>
    public static string SelectedServer { get; set; }

    /// <summary>
    /// The location of the current selected server.
    /// </summary>
    public static string SelectedServerLocation { get; set; }

    /// <summary>
    /// The path of the application itself.
    /// </summary>
    public static string Root { get; set; }

    /// <summary>
    /// The path of the Microcraft folder.
    /// </summary>
    public static string MicrocraftFolder { get; set; }

    /// <summary>
    /// The path of the Server Files folder.
    /// </summary>
    public static string ServersFolder { get; set; }

    /// <summary>
    /// The location of the minecraft.jar file.
    /// </summary>
    public static string MinecraftJar { get; set; }

    /// <summary>
    /// The location of the bukkit.jar file.
    /// </summary>
    public static string BukkitJar { get; set; }

    /// <summary>
    /// The location of the bukkit.yml file.
    /// </summary>
    public static string BukkitYml { get; set; }

    /// <summary>
    /// The location of the server.properties file.
    /// </summary>
    public static string ServerProperties { get; set; }

    /// <summary>
    /// The location of the root xml file.
    /// </summary>
    public static string XmlRoot { get; set; }

    /// <summary>
    /// The location of the server xml file.
    /// </summary>
    public static string XmlServer { get; set; }

    public Paths()
    {
        if (string.IsNullOrEmpty(SelectedServer))
        {
            Xml.Setting.path = Environment.CurrentDirectory + "\\microcraft\\settings.xml";
            SelectedServer = Xml.Setting.GetSetting("Servers/Current", "T4G Demo");
        }

        Root = string.Format("{0}\\", Environment.CurrentDirectory);
        MicrocraftFolder = string.Format("{0}microcraft\\", Root);
        ServersFolder = string.Format("{0}servers\\", MicrocraftFolder);
        SelectedServerLocation = string.Format("{0}{1}", ServersFolder, SelectedServer);
        MinecraftJar = string.Format("{0}{1}\\minecraft.jar", ServersFolder, SelectedServer);
        BukkitJar = string.Format("{0}{1}\\bukkit.jar", ServersFolder, SelectedServer);
        BukkitYml = string.Format("{0}{1}\\bukkit.yml", ServersFolder, SelectedServer);
        ServerProperties = string.Format("{0}{1}\\server.properties", ServersFolder, SelectedServer);
        XmlRoot = string.Format("{0}settings.xml", MicrocraftFolder);
        XmlServer = string.Format("{0}{1}\\settings.xml", MicrocraftFolder, SelectedServer);
    }
}

这就是我编辑/调用字符串的方式:

Servers.Paths.SelectedServer = SelectedServer;
Xml.Setting.path = Servers.Paths.XmlServer;  

但是Servers.Paths.XmlServer新的不是更新SelectedServer:(。

4

2 回答 2

1

这是因为您实际上没有任何代码可以SelectedServer在修改后更新任何内容。

SelectedServer在构造函数中设置,构造函数在实际构建对象之前被调用。

如果您想在SelectedServer更改后更新其他内容,则需要执行以下操作:

private static string _selectedServer;
public static string SelectedServer
{
   get { return _selectedServer; }
   set
   {
      _selectedServer = value;
      // Update other fields here.
   }
} 

此外,我会推荐类似的东西:

public class Paths
{
    private static string _selectedServer;
    /// <summary>
    /// The current selected server.
    /// </summary>
    public static string SelectedServer
    {
        get { return _selectedServer; }
        set
        {
            _selectedServer = value;
            _updateFields();
        }
    }

    /// <summary>
    /// The location of the current selected server.
    /// </summary>
    public static string SelectedServerLocation { get; set; }

    /// <summary>
    /// The path of the application itself.
    /// </summary>
    public static string Root { get; set; }

    /// <summary>
    /// The path of the Microcraft folder.
    /// </summary>
    public static string MicrocraftFolder { get; set; }

    /// <summary>
    /// The path of the Server Files folder.
    /// </summary>
    public static string ServersFolder { get; set; }

    /// <summary>
    /// The location of the minecraft.jar file.
    /// </summary>
    public static string MinecraftJar { get; set; }

    /// <summary>
    /// The location of the bukkit.jar file.
    /// </summary>
    public static string BukkitJar { get; set; }

    /// <summary>
    /// The location of the bukkit.yml file.
    /// </summary>
    public static string BukkitYml { get; set; }

    /// <summary>
    /// The location of the server.properties file.
    /// </summary>
    public static string ServerProperties { get; set; }

    /// <summary>
    /// The location of the root xml file.
    /// </summary>
    public static string XmlRoot { get; set; }

    /// <summary>
    /// The location of the server xml file.
    /// </summary>
    public static string XmlServer { get; set; }

    public Paths(string selectedServer)
    {
        // Set any default values here
        SelectedServer = selectedServer;
    }

    private static void _updateFields()
    {
        if (string.IsNullOrEmpty(SelectedServer))
        {
            Xml.Setting.path = Environment.CurrentDirectory + "\\microcraft\\settings.xml";
            SelectedServer = Xml.Setting.GetSetting("Servers/Current", "T4G Demo");
        }

        Root = string.Format("{0}\\", Environment.CurrentDirectory);
        MicrocraftFolder = string.Format("{0}microcraft\\", Root);
        ServersFolder = string.Format("{0}servers\\", MicrocraftFolder);
        SelectedServerLocation = string.Format("{0}{1}", ServersFolder, SelectedServer);
        MinecraftJar = string.Format("{0}{1}\\minecraft.jar", ServersFolder, SelectedServer);
        BukkitJar = string.Format("{0}{1}\\bukkit.jar", ServersFolder, SelectedServer);
        BukkitYml = string.Format("{0}{1}\\bukkit.yml", ServersFolder, SelectedServer);
        ServerProperties = string.Format("{0}{1}\\server.properties", ServersFolder, SelectedServer);
        XmlRoot = string.Format("{0}settings.xml", MicrocraftFolder);
        XmlServer = string.Format("{0}{1}\\settings.xml", MicrocraftFolder, SelectedServer);
    }
}

我已经让构造函数需要选定的服务器,以便您可以设置它,因为其他一切似乎都取决于该值。

我会建议修改类的结构,删除静态等,只是真正考虑你需要什么。

于 2013-04-04T17:39:00.557 回答
0

当您a = b在 C# 中说时,您并不是在说“从现在开始,a两者b都是point相同的东西,改变一个会改变另一个。” 您的意思是,“取b 这一秒的正确值并将值设置为该a值。执行这行代码后,更改bis 对 没有影响a,更改a将没有任何影响关于里面的内容b

这就是为什么在给定代码的情况下更改其中一个属性不会影响另一个属性的原因。

也就是说,由于您还没有真正描述您实际尝试做的事情,因此很难说您应该如何正确解决您真正的问题是什么。

于 2013-04-04T17:53:49.623 回答