aireq303
2009-01-16, 11:04 PM
I'm trying to figure out a way to save custom properties and objects in between my custom commands. I have be writing to/from a file at the start and end of each command, but I'm wondering if there is a better way.
A static variable in a static class sort of works, but it's scope is too big. After some basic testing it seems that the scope of a static variable is the entire application. However, the values I am saving need to be specific to the current document. I'd want something where if the user switches between two open documents the commands will be using a different set of static variables.
I've added the code I used to check the scope of a static variable below in the comments.
class TestStaticVariable : IExternalCommand
{
public IExternalCommand.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
DialogResult result = MessageBox.Show("SavedStateTest.state = " + SavedStateTest.state, "hi there", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
SavedStateTest.state = "you last choose YES";
}
else
{
SavedStateTest.state = "you last choose NO";
}
return IExternalCommand.Result.Succeeded;
}
}
static public class SavedStateTest
{
public static string state = "Only Instantiated";
}
A static variable in a static class sort of works, but it's scope is too big. After some basic testing it seems that the scope of a static variable is the entire application. However, the values I am saving need to be specific to the current document. I'd want something where if the user switches between two open documents the commands will be using a different set of static variables.
I've added the code I used to check the scope of a static variable below in the comments.
class TestStaticVariable : IExternalCommand
{
public IExternalCommand.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
DialogResult result = MessageBox.Show("SavedStateTest.state = " + SavedStateTest.state, "hi there", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
SavedStateTest.state = "you last choose YES";
}
else
{
SavedStateTest.state = "you last choose NO";
}
return IExternalCommand.Result.Succeeded;
}
}
static public class SavedStateTest
{
public static string state = "Only Instantiated";
}