Including or importing Source files?

  • Thread starter Thread starter Ryan Knopp
  • Start date Start date
R

Ryan Knopp

Do I have to compile a class to be able to import it into another source?

Can I do something like

include System;
include System.IO;
include Language; <-- language is a Language.cs file. Does this file
need to be a dll or can i just include the source? I get compile errors
doing this but maybe there was a way around it.

thanks
ryan K
 
Hi

You need to include the namespace which contains the .cs file and not the .cs file itself

e.g. Let yuor .cs file be
namespace TEM

class temp

int a



In the document in whcih you want to include, the using header will b
using System.IO
using System.*
using TEMP

Regard
Vipul Pate
Microsoft India Community Star
 
HI

Forgot to add

If the .cs file is inside your DLL/EXE, then compiling will not be required. else, you will need to compile t

Regard
Vipul Pate
MS India Community Star
 
Sounds like ya mixing up 3 different things:
-referencing other class.
-including a namespace
-referencing a dll\project

If in class A you want to reference class B then:
-If class B is in same namespace and same dll\project -> do nothing
-If class B is in other namespace in same dll\project -> include
namespace
-if class B is in other dll\project but same namespace -> Add
reference to dll that contains class B. If also other namespace ->
also include namespace.

Normally you do not compile one single class to a dll, but coherent
set of classes.

Think your case is the simplest one and you don't have to import
anything. You get the compile error because you try to includ a class
(Language), which is neither allowed, nor needed (as long as you are
in same namespace or do not use namespaces at all).
 
I believe the real question Ryan is asking is if can do macro expansion includes (i.e. similar to server side includes in web app development or the way C uses the include <stdio.h> macro. C basically makes a copy of the text in stdio.h and puts it in the place of the line include <stdio.h>. I believe the reason Ryan is probably asking this is to allow him to change the definition of some code and/or resource at runtime. This can't be done this way in .NET. You need to either use Codedom namespace to dynamically generate code, use dynamic binding and a config file (see System.AddDomain for more info) to load dlls at runtime, use config file to store runtime specific info, or use resource files to store locale/environment specific info that can change at runtime. If this is not the reason you were wanting this ability reply with more info about what you're trying to do

FYI - a new feature in the next release of C# is partial classes. This will allow you to split up the definition of a class in multiple files. Check it out it's pretty cool. Whidbey will also be having a realtime refreshed class modeler where updates to the model will be instantly refreshed in the code and vice versa. Pretty cool in deed

As a side note, the splat used in Vipul's first post (System.*) does not work in .NET that's Java. In Java you had to import classes not namespaces (packages) so the splat was used to import all classes in a package. So there isn't really any need for splat in .NET.
 
Back
Top