473,513 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

adding custom keywords to c#

Dan
Hi everybody,

is it possible to add new keywords in c#, in order to improve functionality?
just as
(using IDisposableImplementer = new IDisposableImplementer())
{
// use the IDisposableImplementer
}
first thing that pops in my mind - even though may seem trivial - is for
automatically setting the cursor to busy before a lengthy operation and
resetting to default afterwards; just using a construct similar to "using".

Thank you,
Daniel
Apr 11 '06 #1
4 4450

"Dan" <Da*@discussions.microsoft.com> wrote in message
news:45**********************************@microsof t.com...
Hi everybody,

is it possible to add new keywords in c#, in order to improve
functionality?
just as
(using IDisposableImplementer = new IDisposableImplementer())
{
// use the IDisposableImplementer
}
first thing that pops in my mind - even though may seem trivial - is for
automatically setting the cursor to busy before a lengthy operation and
resetting to default afterwards; just using a construct similar to
"using".


You can't add keywords, no, but you can abuse using to do this(although I'm
not sure if it is a good idea or not...)

Simply create a disposable class that sets the cursor to busy in its
constructor(you'd have to pass the form you want to change the cursor on of
course) and unsets it in its Dispose method. Then when you use it in a using
block you get the effect you want.
Apr 11 '06 #2
Dan wrote:
is it possible to add new keywords in c#, in order to improve functionality?
No. You could get hold of the sources for the Mono C# compiler and
modify those, of course - but you'd have a job getting Visual Studio to
use that!
just as
(using IDisposableImplementer = new IDisposableImplementer())
{
// use the IDisposableImplementer
}
first thing that pops in my mind - even though may seem trivial - is for
automatically setting the cursor to busy before a lengthy operation and
resetting to default afterwards; just using a construct similar to "using".


That *certainly* shouldn't be part of the language - but you can easily
"fake" it with your own class which implements IDisposable anyway:

using (new CursorChanger())
{
.....
}

Just make your CursorChanger change the cursor to busy, and then reset
it in Dispose.

Jon

Apr 11 '06 #3
Dan
The example with "using" was just an example;
I meant a more generic way to extend either the .NET Framework or C#...

AFAIK, in .NET 3.0 it will be possible to extend primitive types, like int,
with new functionality - much like in Smaltalk...

"Jon Skeet [C# MVP]" wrote:
Dan wrote:
is it possible to add new keywords in c#, in order to improve functionality?


No. You could get hold of the sources for the Mono C# compiler and
modify those, of course - but you'd have a job getting Visual Studio to
use that!
just as
(using IDisposableImplementer = new IDisposableImplementer())
{
// use the IDisposableImplementer
}
first thing that pops in my mind - even though may seem trivial - is for
automatically setting the cursor to busy before a lengthy operation and
resetting to default afterwards; just using a construct similar to "using".


That *certainly* shouldn't be part of the language - but you can easily
"fake" it with your own class which implements IDisposable anyway:

using (new CursorChanger())
{
.....
}

Just make your CursorChanger change the cursor to busy, and then reset
it in Dispose.

Jon

Apr 11 '06 #4
Dan wrote:
The example with "using" was just an example;
Yes, but it shows that often there's already a way of achieving a
desired effect without changing the language at all.
I meant a more generic way to extend either the .NET Framework or C#...

AFAIK, in .NET 3.0 it will be possible to extend primitive types, like int,
with new functionality - much like in Smaltalk...


Well, not really. It will be possible to *pretend* that a type (any
type) has a method, by effectively redirecting calls to that method to
a static method. It's only syntactic sugar for what's already
available.

However, that's not going to allow you to add your own keywords etc.
Personally, I'm glad about that - it means that when I see some C#, I
know what it means, rather than everyone having their own subtly
different dialect.

Jon

Apr 11 '06 #5

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

Similar topics

0
1017
by: George C | last post by:
Is there any way to add or change syntax keywords in visual studio .NET ? for example, the word "for" turns blue when you type it. I wanted to add some more keywords to the list. thanks, ...
2
18546
by: RobG | last post by:
I am trying to dynamically add an onclick to an element, however I just can't get the syntax right. consider the following function: function doClick (evt,x) { // do things with evt and x } ...
3
1564
by: RajSurisetti | last post by:
Hi, Can anyone help me to build custom control for the following <HEAD> <LINK href="~/Styles/Blah.css" rel="stylesheet" type="text/css"> <meta name="GENERATOR" Content="Microsoft Visual...
10
3258
by: Jon | last post by:
I'm investiging multi-threaded GUI applications; specifically the technique used to ensure that controls are only modified under the correct thread. The standard technique is to use ...
1
3488
by: asnowfall | last post by:
I am creating MailMessage out of already existing email message. My existing message has few custom properties. I wan to add them to System.Net.Mail.MailMessage How to add custom properties? ...
3
3134
by: Fao, Sean | last post by:
I have a DataGrid that I'm adding CheckBox controls to at runtime (in the code behind) and I'm not sure if I'm doing it correctly. First of all, I noticed that the MyDataGrid.Columns.Add() method...
11
18075
by: Pete Kane | last post by:
Hi All, does anyone know how to add TabPages of ones own classes at design time ? ideally when adding a new TabControl it would contain tab pages of my own classes, I know you can achieve this with...
7
3377
by: Maximus Decimus | last post by:
HI all, I am using python v2.5 and I am an amateur working on python. I am extending python for my research work and would like some help and guidance w.r.t this matter from you experienced...
3
2123
by: jeddiki | last post by:
Hi, I am using this script which is nearly working correctly, but not quite! When a user selects some text from the web-page and copies it, the script is supposed to pick up the current...
0
7267
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,...
0
7391
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
7553
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...
1
7120
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5697
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3247
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...
0
3235
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
466
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...

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.