?
Solved

How to invoke a cs file in C#?

Posted on 2009-12-31
4
Medium Priority
?
399 Views
Last Modified: 2013-12-17
I have different modules for Business Layer, DataLayer, Business Entities layer.
Business Layer --> Contains cs files that contains the Business Logic
Business entities --> Contains cs files that contains attributes
Data Layer --> Contains the cs files that interacts with the DB. The results from this layer will be used to set the Entities attributes values in the Business Layer cs files
                         Now my requirement is, In the above existing modules{Solution}, I included a new set of independent files in each module. So, I have to invoke the file that I created in Business layer. I have to invoke a method inside the cs file by hardcoding the parameters. Please let me know on how can I implement this.
                         As in java, is there something called as main method in C#, so that I can diredtly execute the cs file, similar to java like, giving "java ClassName Parameters"
0
Comment
Question by:HelpSunny
4 Comments
 
LVL 9

Expert Comment

by:magicdlf
ID: 26157449
In C#, you need to create a new project and put your main there. Then you can include your Business layer by adding reference to your project. This should be very easy for you if your middle layer is a class library project.
Otherwise, you will need to write the csc command line by yourself, which is not integrated with Visual Studio and I dont recommend you to do that.
0
 
LVL 11

Expert Comment

by:ashraf882
ID: 26165229
You can create class in DataLayer, Business Entities layer.
Then call them by putting "using" keyword at the top of the cs file.
0
 
LVL 2

Accepted Solution

by:
alain_tesio earned 1500 total points
ID: 26173026
The clean way to do this is to compile the cs file into an assembly, you get a reference to an instance of Assembly, and you can invoke methods by reflection.
The assembly does not need to be saved as a file.

Have a look at this example:

http://www.codeproject.com/KB/dotnet/DynamicCompileAndRun.aspx

This is a bit complex, but required if you don't know the contents of the cs files (eg. you ship the same binaries for several customers, and they have specific "plugins" implemented cs files)

I'm not sure if this was the requirement, if not you'd better follow the suggestions above.
0
 

Author Closing Comment

by:HelpSunny
ID: 31671741
Thank U
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Screencast - Getting to Know the Pipeline
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question