473,385 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Writing stuff

Hi all,

I would consider myself a fairly intermediate level programmer in C#, having
come from an ASP background, though there are still big gaps in my
knowledge.

One such gap is writing stuff such as...

HttpContext.Current.Application.Contents etc. etc. etc.

Now, there are two parts to this.
1. Say I want to write something like...
MyApp
In my app, I have a class, ThisClass
This would give me something like
MyApp.ThisClass

Next, as the example httpcontext above, how do I go further, such as
MyApp.ThisClass.NextLevel.DeeperLevel etc.

Also, what do you call this? (All the dots, and the intellisense picking up
sub items.)

2. In the HttpContext item above, when I get to Contents and type a dot, I
get Contents, then another dot I get Contents again (seemingly endless.)
How can I do that? What is this called?

Anyone have any URLs that area fairly straightforward to read and use?

There are other areas that I am lacking on, such as inheritance,
multithreading, etc. but they will save for another time.

The reason I am asking is that I want to construct a menu system, similar to
the way Microsoft CMS builds it... This looks like....

CmsHttpContext.Current.Channel.Url
CmsHttpContext.Current.Channel.Name
CmsHttpContext.Current.Channel.Parent.Parent.Paren t.Url

etc. etc. (note how the last example has parent.parent.parent (ad
infinitum).

Thanks for any help...

Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
Feb 16 '06 #1
5 1399
this is called Namespaces.

Namespaces are mainly used for organizing, it also allows you to use
two classes that are named the same, in the same piece of code:

the "using System.IO;" at the top of every file "imports" that
namespace. what that means is if you want to access a class in that
namespace, you dont have to type the full namespace path:

i.e.:

without "using System.IO;":
System.IO.File myFile = whatever;

with "using System.IO;":
File myFile = whatever;

get the drift?

heres an article on msdn that helped me out originally:
http://msdn2.microsoft.com/en-us/lib.../dfb3cx8s.aspx

Feb 16 '06 #2
Hi David

In .Net each . represents the relationship between an object and its members.

Take
HttpContext.Current.Application.Contents

The HttpContext class has a static Current property which is a HttpContext reference.

The HttpContext class also has an Application property which is a HttpApplicationState reference.

The HttpApplicationState has a Contents property which is a HttpApplicationState reference.

HttpContext.Current.Application.Contents is just a shorter way of writing

HttpContext cur = HttpContext.Current;
HttpApplicationState appstate = cur.Application;
HttpApplicationState cont = appstate.Contents;

Similarly you can do fun stuff with strings.

string A = "one";
string B = "two";
string C = (A + B).Substring(B.IndexOf(B[0]) + A.Length, (A + B).Length - (A.Length + B.Length - B.IndexOf(B[1]))).Insert(1, "hr").PadRight(5, A[2]);

The . doesn't care about where in the line it is, as all it knows is the object immediatly to the left and right.

To go further in MyApp.ThisClass, simply add a public member to ThisClass

class ThisClass
{
private ThisClass myparent = null;
private string myurl = "http://url";

public ThisClass Parent
{
get{ return myparent; }
}

public string Url
{
get{ return myurl; }
}

public ThisClass()
{
myparent = this;
}
}

The above will let you write

ThisClass myclass = new Thisclass();
myClass.Parent.Parent.Parent.Parent.Url

Usually Parent would point to something else than itself though.

I would read up on inheritance before much else as .Net is full of it. For instance, everything inherits from System.Object (The Object class in the System namespace), which means that no matter what object you can trust it has the GetType and ToString methods.

--
Happy coding!
Morten Wennevik [C# MVP]
Feb 16 '06 #3
SP

"David" <da*****************@revilloc.REMOVETHIS.com> wrote in message
news:Oj**************@tk2msftngp13.phx.gbl...
Hi all,

I would consider myself a fairly intermediate level programmer in C#,
having come from an ASP background, though there are still big gaps in my
knowledge.

One such gap is writing stuff such as...

HttpContext.Current.Application.Contents etc. etc. etc.

Now, there are two parts to this.
1. Say I want to write something like...
MyApp
In my app, I have a class, ThisClass
This would give me something like
MyApp.ThisClass

Next, as the example httpcontext above, how do I go further, such as
MyApp.ThisClass.NextLevel.DeeperLevel etc.

Also, what do you call this? (All the dots, and the intellisense picking
up sub items.)

2. In the HttpContext item above, when I get to Contents and type a dot, I
get Contents, then another dot I get Contents again (seemingly endless.)
How can I do that? What is this called?

Anyone have any URLs that area fairly straightforward to read and use?

There are other areas that I am lacking on, such as inheritance,
multithreading, etc. but they will save for another time.

The reason I am asking is that I want to construct a menu system, similar
to the way Microsoft CMS builds it... This looks like....

CmsHttpContext.Current.Channel.Url
CmsHttpContext.Current.Channel.Name
CmsHttpContext.Current.Channel.Parent.Parent.Paren t.Url

etc. etc. (note how the last example has parent.parent.parent (ad
infinitum).

Thanks for any help...

Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available


That is known as the Composite pattern. Your objects contain objects that
contain objects and so on. For example if class A has a property B of type B
and class B has a property C of type C and class C has a property D of type
D then you can get to D from your instance of A with MyA.B.C.D = 5;

HTH

SP
Feb 16 '06 #4
Heres some links to read up on wikipedia.org

Inheritance:
http://en.wikipedia.org/wiki/Inherit...ter_science%29
Abstract Classes (the base class invloving inheritance) :
http://en.wikipedia.org/wiki/Abstrac...ncrete_classes
Polymorphism:
http://en.wikipedia.org/wiki/Polymor...ter_science%29
Compisition/Aggregation (Object relationships):
http://en.wikipedia.org/wiki/Aggrega...programming%29
Delegates : http://en.wikipedia.org/wiki/Delegat...programming%29

Hope that helps!!

sean

Feb 17 '06 #5
Thank you DKode, Morten and SP for your help. I didn't quite follow SPs
example though.

This example I am replying to seems to demonstrate exactly what I am asking
about, though as yet, I am still a little unsure. I am sure though that
there will be a switch in the very near future where everything becomes so
apparent.

I will definately read the URLs that have been posted here. The project I
have got on is a large project (I am no stranger to large projects, just
look at the first URL in my signature) and I want to ensure that it will be
easy for the next programmer to just use the objects I have created.

I think my next step will be learning about IEnumerable and multithreading
(a particular app I have needs threading). I will ask about those when the
time comes if I need to.

Once again, thanks for your help.

Best regards,
Dave Colliver.
http://www.LiverpoolFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:op.s426wibkklbvpo@stone...
Hi David

In .Net each . represents the relationship between an object and its
members.

Take
HttpContext.Current.Application.Contents

The HttpContext class has a static Current property which is a HttpContext
reference.

The HttpContext class also has an Application property which is a
HttpApplicationState reference.

The HttpApplicationState has a Contents property which is a
HttpApplicationState reference.

HttpContext.Current.Application.Contents is just a shorter way of writing

HttpContext cur = HttpContext.Current;
HttpApplicationState appstate = cur.Application;
HttpApplicationState cont = appstate.Contents;

Similarly you can do fun stuff with strings.

string A = "one";
string B = "two";
string C = (A + B).Substring(B.IndexOf(B[0]) + A.Length, (A + B).Length -
(A.Length + B.Length - B.IndexOf(B[1]))).Insert(1, "hr").PadRight(5,
A[2]);

The . doesn't care about where in the line it is, as all it knows is the
object immediatly to the left and right.

To go further in MyApp.ThisClass, simply add a public member to ThisClass

class ThisClass
{
private ThisClass myparent = null;
private string myurl = "http://url";

public ThisClass Parent
{
get{ return myparent; }
}

public string Url
{
get{ return myurl; }
}

public ThisClass()
{
myparent = this;
}
}

The above will let you write

ThisClass myclass = new Thisclass();
myClass.Parent.Parent.Parent.Parent.Url

Usually Parent would point to something else than itself though.

I would read up on inheritance before much else as .Net is full of it.
For instance, everything inherits from System.Object (The Object class in
the System namespace), which means that no matter what object you can
trust it has the GetType and ToString methods.

--
Happy coding!
Morten Wennevik [C# MVP]

Feb 17 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

48
by: Joseph | last post by:
Hi I'm writing a commercial program which must be reliable. It has to do some basic reading and writing to and from files on the hard disk, and also to a floppy. I have foreseen a potential...
40
by: post400 | last post by:
Hi, there is another famous book 'Writing solid code' but does it apply to Python ? Or it's usable only by Microsoft C programmers ? The author seems to be an ex-Microsoft guy ! Thanks ,...
385
by: Xah Lee | last post by:
Jargons of Info Tech industry (A Love of Jargons) Xah Lee, 2002 Feb People in the computing field like to spur the use of spurious jargons. The less educated they are, the more they like...
17
by: Eric Lindsay | last post by:
Is learning to write CSS a better use of time than finding and using a package that produces complete web pages? I've moved to a new platform (Macintosh), taking with me about 400 personal web...
10
by: Jason Curl | last post by:
Dear C group, I'm very interested in writing portable C, but I only have GNU, Sparc and Cygwin to compile on. What I find is the biggest problem to writing portable C is what headers to...
13
by: jay.dow | last post by:
I want to write to the pins of an RS232 without using the serial protocol. The use would be every pin could act to complete a circuit in customized hardware. I could use python to communicate...
30
by: mellyshum123 | last post by:
I'm wanting to write an int to a file, and so far I have written: const char buff; int num = 256 //for the sake of the example sprintf(buff, "%d", num); Now my question is what to do next. I...
18
by: Zytan | last post by:
I have multiple threads writing to WebBrowser (using a function that checks InvokedRequired, and if so, invokes itself on the WebBrowser thread) and they are getting deadlocked. They only...
59
by: riva | last post by:
I am developing a compression program. Is there any way to write a data to file in the form of bits, like write bit 0 then bit 1 and then bit 1 and so on ....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.