• 0

[how to]Call functions of one Class from another class


Question

Hello,

I know it may be silly to ask this

but I m stuck with this: so please help

I have two classes in the same namespace

1. Setting_Layers_Path class files
Which helps in establishing connection to the layers(GIS connections). It contains number of functions which return an object of specific datatype

2. Form Class

Now, what I want to do is on Form_Load Event I want to call all the functions present in the Setting_Layer_Path class

One way of doing is by creating object of the Setting_Layer_Path Class and working with the functions within it

Can someone tell me, is there any other way of calling the functions directly without creating object

Attach is the codes

Setting_Layer_Path Class

namespace RELGIS_DT_Load_Calculation
{
	public sealed class Setting_Layers_Path
	{
		#region User Defined Variables 
		IMxDocument pMxDoc;
		IMap pMap;
		#endregion
		public Setting_Layers_Path()
		{		   
		}
		private static IFeatureLayer get_DivsionFeatureLayer()
		{
			return null;
		}			  
		private static IFeatureLayer get_SubStnFeatureLayer()
		{
			return CommonGISFunc.FirstFeatureLayerWithMN(pMap, "AU_SUBSTATION");
		}

		private static IFeatureLayer get_DistributedTransformerFeatureLayer()
		{
			return CommonGISFunc.FirstFeatureLayerWithMN(pMap, "DISTRIBUTIONTRANSFORMER");
		}		  
	}
}

Form frmDT_selection.cs

namespace RELGIS_DT_Load_Calculation
{
	public partial class frmDT_selection : Form
	{
		#region variable declaration
		IMxDocument pMxDoc;
		#endregion

		public frmDT_selection(IApplication m_app)
		{
			InitializeComponent();
		}	   

		private void frmDT_selection_Load(object sender, EventArgs e)
		{
			//This is where i want to call the functions of the Setting_Layers_Path class without creating an object
		}
   }
}

Any help would be deeply appreciated :(

Thanks in advance :)

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

make the functions "public static" instead of "private static" - then you can call them directly without instigating the class.

you could however user the "singleton pattern" - see google about it.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.