Я разрабатываю приложение для Windows на C # с использованием VS2005.
Предположим, мне нужно вызвать нестатический метод (Method1), который находится в классе (Class1) из другого класса (Class2). Чтобы вызвать метод, мне нужно создать объект для этого класса.
Но мой класс 'Class1' содержит более 1000 переменных. Поэтому каждый раз, когда я создаю объект для «Class1», создаются все переменные, но мой метод «Method1» использует очень мало из этих переменных. Так что излишне все остальные переменные становятся экземплярами.
Как я могу оптимизировать этот код, так как это накладные расходы на создание переменных, которые не нужны для конкретного метода, который должен быть вызван.
Или есть какой-то другой стандарт кодирования, с помощью которого я могу преодолеть это?
Заранее спасибо.
вот список моих переменных.
Редактирование:
private string m_sPath = String.Empty;
private string m_sModule = String.Empty;
private string m_sType = String.Empty;
public static string strFileSave;
private string fileName = "", strFactoryXML = "", strPriorityXml = "", strTempXml = "";
private string selMethod = "";
private string selClass = "";
private string selMethodName = "";
private string str, str1, str2;
public static string strFolder;
public static string strFilePath = "";
public static string sel1, sel2;
private string strSetPrFileName = "";
private string results;
private string strClassCompare, strMethodCompare, strTestResultCompare;
public static string CurrWorkingDirectory = Environment.CurrentDirectory;
private System.Threading.ThreadStart m_CummulativeTimeThreadStart = null;
private System.Threading.Thread m_CummulativeTimeThread;
private string[] OuterDelim = null;
private string[] InnerDelim = null;
public static ArrayList alObjectsNotDefined;
public static ArrayList alSystemObjUnDefined = null;
public static string objFileName = "";
public static string XmlFileName = "";
//Integers
private int nMethodCount, index = 0;
private static int nClearFlag, nExp = 0, cell;
public static int flag;
private static int nMemberCount, nPrevMemberCount;
private static int classIndex, methodIndex;
private static int[,] arrIndex = new int[100, 100];
private int indexThread;
private int bFlag = 0;
//private int nIndexClass=0,nIndexMethod=0;
frmCreateProject cp = new frmCreateProject();
//Boolean
private bool crFlag = false, tvAfter = true;
private bool bSetPriority = false;
private bool bFilter = false;
private bool bCr = false;
private bool snapShotFlag = false, factoryFlag = false, tvSel = false;
private bool bResultsFlag = false, bSummaryFlag = false;
public static bool bClick = true, rightMouse = false;
private bool dataError = false;
private bool bClassFilter = false, bMethodFilter = false;//,bTestResultFilter=false;
private bool tvFact = false;
//private bool bAssignFactory=false;
//private bool factoryChanges=false;
private bool bEntered = false;
public static bool bAssign = false;
private bool bChangeMethFactory = false;
private bool bExecution = false;
public bool bModule = false;
public bool bClass = false;
public bool bMethod = false;
public bool bAssemLoaded = false; public bool bLoadClicked = false; public static bool bAssignCustom = false;
public static string strPath;
// public static int intRowCount;
public bool bTestGen = false;
//Others
private Module[] mdls = null;
private Assembly oAssembly;
private DataTable dtSnapshot;
private DataTable dtFactory;
private DataTable dtFactoryGV private DataTable dtExceptions = new DataTable();
private DataTable dtResults = new DataTable();
private DataTable dtSummary = new DataTable();
private DataRow dr;
private DataRow drGV;
private DataColumn dc, dc1;
private DataColumn dcGV;
private Type m_Type;
private Type[] types = new Type[100];
private XmlDocument doc = new XmlDocument();
//private XmlDocument docTemp=new XmlDocument();
private DataGridTextBoxColumn TextCol;
private DataGridTextBoxColumn TextColGV;
private object[] arguments = new object[20];
public static bool bSupport = false;
DataGridTableStyle ts1 = null;
DataGridTableStyle ts2 = null DateTime gridMouseDownTime;
XmlElement gridElement = null;
XmlNodeList gridList = null, gridCustom = null;
public string testAssem;
public string strXmlTestCase;
public string Gen_dll_path;
public static string curClass = "";
public static string curMethod = "";
public static string curTestResult = "";
public static bool comdll = false;
public static bool bIncludeNullValue;
public static string strMainExcep;
public static string cmbFactoryClassSel = "";
public static string cmbFactoryMethodSel = "";
public static string dataGridParameter = "";
private static string strReferredTable = "";
public static string strExePath = "";
public static string strProjPath = "";
public static string strFactoryType = "";
public static string strParameterName = "", strParameterType = "";
public static string checkFactoryClass = "";
public static string strFileXml = "";
public static bool bEdit = false;
public static bool bNumArr = false;
public string checkType = "";
public static bool bThread = true;
public static bool bObjectsDefined = false;
public static bool bSystemObjDefined = false;
public static string cmbFactoryNewMethodSel = "";
public static bool editAuto = false;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem mnuFile;
public System.Windows.Forms.MenuItem mnuTest; private System.Windows.Forms.MenuItem mnuExit;
private System.Windows.Forms.MenuItem mnuHelp;
private System.Windows.Forms.MenuItem mnuAbout;
public System.Windows.Forms.ToolBar toolBar1; private System.Windows.Forms.TabControl tcResults;
private System.Windows.Forms.TabPage tpSummary;
private System.Windows.Forms.TabPage tpExceptions;
private System.Windows.Forms.DataGrid dataGridSummary;
private System.Windows.Forms.RichTextBox rtbOutput;
private System.Windows.Forms.DataGrid dataGridExceptions;
private System.Windows.Forms.Splitter splitterDown;
private System.Windows.Forms.Splitter splitterTV;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.ImageList imageList1;
private System.Windows.Forms.ToolBarButton toolBarOpen;
private System.Windows.Forms.ToolBarButton toolBarTest;
private System.Windows.Forms.Panel panelResults;
private System.Windows.Forms.TabPage tpProblems;
private System.Windows.Forms.RichTextBox rtbProblems;
private System.Windows.Forms.MenuItem mnuCreateProject;
private System.Windows.Forms.MenuItem mnuOpenProject;
private System.Windows.Forms.ToolBarButton toolBarNew;
private System.Windows.Forms.PictureBox pictureBox1;
protected System.Windows.Forms.ContextMenu contextMenuTest;
private System.Windows.Forms.ToolTip toolTip1;
private System.Windows.Forms.MenuItem mnuAssignFactory;
private System.Windows.Forms.ContextMenu contextMenuFactory;
private System.Windows.Forms.MenuItem mnuViewAutoFactory;
private System.Windows.Forms.ContextMenu contextMenu1;
private System.Windows.Forms.MenuItem mnuEditCustomFactory;
private System.Windows.Forms.MenuItem mnuDeleteCustomFactory;
private System.Windows.Forms.ToolBarButton toolBarPriority;
private System.Windows.Forms.MenuItem mnuSetPriority;
private System.Windows.Forms.ContextMenu contextMenuResults;
private System.Windows.Forms.MenuItem mnuPerformance;
private System.ComponentModel.IContainer components;
public static System.Windows.Forms.TreeView tempTV public static string classNameGV;
public string strAppPath = "";
public string strTempPath = "";
public bool bDllExists;
public string smTemp1 = "";
public string strTestFolder = "";
public static bool bReloadNewDll = false;
private string dllUnderTest = "";
private System.Threading.ThreadStart m_UpdateDBTimeThreadStart = null;
private System.Threading.Thread m_UpdateDBTimeThread;
private TabPage tabPage2;
private TreeView tvTestAssemb;
private TabPage tabPage1;
private TreeView tv;
private TabControl tabControl1;
public static string Output;
private MenuItem menuItem3;
private MenuItem menuItem4;
private MenuItem menuItem5;
private MenuItem menuItem1;
private MenuItem menuItem2;
private TabPage tpTestGen;
public StatusBar statusBar1;
private TextBox txtTestGen;
private TabPage tpTestCaseTable;
private DataGrid dataGrid2;
private Panel panel1;
private Button btnGenerate;
private Button btnSave;
private Button btnTestCase;
private Label label5;
private ComboBox cmbTestCase;
private DataGrid dataGrid1;
private TabPage tpGlobalVariable;
public DataGrid dataGridFactoryGV;
private Panel panelGlobalVariable;
private ComboBox cmbMethodNameGV;
private Label label2;
private Label label1;
private ComboBox cmbClassNameGV;
private TabPage tpFactorySettings;
private Panel panelFactory;
public DataGrid dataGridFactory;
private Panel panelClassDetails;
private Label lblClassName;
private ComboBox cmbClassName;
private Label lblMethodName;
private ComboBox cmbMethodName;
private TabPage tpSnapshot;
private Panel panelUpdateMsg;
private PictureBox pictureBox2;
private Label label4;
private DataGrid datagridSnapshot;
public TabControl tcSnapshot;
public StatusBar statBar;
public ArrayList alMultiLevelTableName = new ArrayList();
public ArrayList alExpRes;
public ArrayList alParVal;
public ArrayList alTestCaseID
public ArrayList alClassName;
private MenuItem menuItem6
public ArrayList alMethSig;
public ArrayList alComments;