473,699 Members | 2,779 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Cur rent.Applicatio n.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.Deep erLevel 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. Parent.Url

etc. etc. (note how the last example has parent.parent.p arent (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 1414
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.Cur rent.Applicatio n.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 HttpApplication State reference.

The HttpApplication State has a Contents property which is a HttpApplication State reference.

HttpContext.Cur rent.Applicatio n.Contents is just a shorter way of writing

HttpContext cur = HttpContext.Cur rent;
HttpApplication State appstate = cur.Application ;
HttpApplication State cont = appstate.Conten ts;

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.P arent.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******** ******@tk2msftn gp13.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.Cur rent.Applicatio n.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.Deep erLevel 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. Parent.Url

etc. etc. (note how the last example has parent.parent.p arent (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.s426wib kklbvpo@stone.. .
Hi David

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

Take
HttpContext.Cur rent.Applicatio n.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
HttpApplication State reference.

The HttpApplication State has a Contents property which is a
HttpApplication State reference.

HttpContext.Cur rent.Applicatio n.Contents is just a shorter way of writing

HttpContext cur = HttpContext.Cur rent;
HttpApplication State appstate = cur.Application ;
HttpApplication State cont = appstate.Conten ts;

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.P arent.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
8482
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 problem. The program may crash unexpectedly while writing to the file. If so, my program should detect this during startup, and then (during startup) probably delete the data added to the file and redo the writing operation.
40
4253
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 , post400
385
17183
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 extraneous jargons, such as in the Unix & Perl community. Unlike mathematicians, where in mathematics there are no fewer jargons but each and every one are
17
7679
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 pages, some dating back so far I probably wrote them in vi. About 4 years ago (thanks in part to hints found in this group) I converted about 80 pages to CSS, and was fairly happy with the result, plain though they are. Since then I've forgotten...
10
2181
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 include. What sites do people know about that are comprehensive in their differences? For example, MacOSX complained about <string.h>. With Solaris I needed
13
6856
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 serially to a BASIC stamp or a Javelin stamp and then use the stamp to set however many pins as 0's or 1's but should it be that hard to do with python. I've looked through how python does serial with the "serial" module but it just uses Java's...
30
2001
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 could use fwrite, but I don't understand how the size works, I'm not sure if it writes out the whole buffer or not, and I definetly only want to write out "256."
18
6854
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 deadlock when I use lock { } around the call to WebBrowser.Write to ensure thread safety! Does any one have experience with such a thing? Zytan
59
3459
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
8704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9192
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9054
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8895
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5879
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2362
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.