473,804 Members | 4,128 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Attribute to inject code for a property?


Hi,

Is there any why I could use attribute or something else
to instruct the compiler to inject a specific code for a property?

for example i have the following property and i would like that 3 lines of
code will be running
for the set function,note that i am not taking about code generation!

public virtual System.String TelephoneNumber
{
get
{
return m_TelephoneNumb er;
}
set
{
//Line1
//Line2
//Line3+ m_TelephoneNumb er
}
}

thanks in advance.
Nov 16 '05 #1
4 4476
what do you mean by injecting a specific code for a property? Can you be
more specific about your three lines?

"Julia" <co********@012 .net.il> wrote in message
news:uh******** ******@tk2msftn gp13.phx.gbl...

Hi,

Is there any why I could use attribute or something else
to instruct the compiler to inject a specific code for a property?

for example i have the following property and i would like that 3 lines of
code will be running
for the set function,note that i am not taking about code generation!

public virtual System.String TelephoneNumber
{
get
{
return m_TelephoneNumb er;
}
set
{
//Line1
//Line2
//Line3+ m_TelephoneNumb er
}
}

thanks in advance.

Nov 16 '05 #2

"Julia" <co********@012 .net.il> wrote in message
news:uh******** ******@tk2msftn gp13.phx.gbl...

Hi,

Is there any why I could use attribute or something else
to instruct the compiler to inject a specific code for a property?


There is no code generator support directly within the MS C# compiler. There
is a third party compiler that does something like this, but I can't
remember the name(or even if it works this way. It might simply have
parameter constraints). And, although I can't say for sure, this sounds like
AOP to me. You may be able to find an AOP framework for C# or perhaps go
totally overboard and use ContextBoundObj ect and write your own
hooks(http://msdn.microsoft.com/msdnmag/is.../default.aspx).
It is obnoxious, but it does work(in the 1.1 framework anyway, I can't say
firsthand about 2.0).

Most of the time you would use code generators(wond erful things, even better
with partial classes) or macros to achieve this. Even a pre-build step that
parses the code, sees the attribute, and injects it would be sufficent in
most cases.

The question really is why you aren't talking about code generation but you
are. I mean, injecting code is *still* generation, even if the generation
step happens to occur during compilation time. Is there some particular
reason you can't use some form of code generation?
Nov 16 '05 #3
I am talking about something like COM+ attribute
AutoComplete for example

Does'nt this attribute execute code before and after a method?

ha....i can see that the article talk about something similar so i am going
to read it now.
thanks.

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:eg******** ******@TK2MSFTN GP15.phx.gbl...

"Julia" <co********@012 .net.il> wrote in message
news:uh******** ******@tk2msftn gp13.phx.gbl...

Hi,

Is there any why I could use attribute or something else
to instruct the compiler to inject a specific code for a property?
There is no code generator support directly within the MS C# compiler.

There is a third party compiler that does something like this, but I can't
remember the name(or even if it works this way. It might simply have
parameter constraints). And, although I can't say for sure, this sounds like AOP to me. You may be able to find an AOP framework for C# or perhaps go
totally overboard and use ContextBoundObj ect and write your own
hooks(http://msdn.microsoft.com/msdnmag/is...nNET/default.a
spx). It is obnoxious, but it does work(in the 1.1 framework anyway, I can't say
firsthand about 2.0).

Most of the time you would use code generators(wond erful things, even better with partial classes) or macros to achieve this. Even a pre-build step that parses the code, sees the attribute, and injects it would be sufficent in
most cases.

The question really is why you aren't talking about code generation but you are. I mean, injecting code is *still* generation, even if the generation
step happens to occur during compilation time. Is there some particular
reason you can't use some form of code generation?

Nov 16 '05 #4

"Julia" <co********@012 .net.il> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
I am talking about something like COM+ attribute
AutoComplete for example

Does'nt this attribute execute code before and after a method?

ha....i can see that the article talk about something similar so i am
going
to read it now.


Yes, it looks like you are basically after the same concept.
AutoCompleteAtt ribute probably plugs into the COM+ architecture allowing
code to execute between calls. ContextBoundObj ect works in a similar
fashion. It isn't as straight forward(you may have to write a reflection
engine within a class level attribute that searches for your attribute on
the properties), but it should work.

This is definatly AOP, you should read about it sometime, ;).

It has its advantages, just not as many as some make it out to be.
Nov 16 '05 #5

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

Similar topics

7
3673
by: svilen | last post by:
hello again. i'm now into using python instead of another language(s) for describing structures of data, including names, structure, type-checks, conversions, value-validations, metadata etc. And i have things to offer, and to request. And a lot of ideas, but who needs them.... here's an example (from type_struct.py):
2
2492
by: tvmaly | last post by:
Due to the restrictions I have at my host, I cannot use smtplib in my email cgi script. They gave me a script they use that calls nullmailer-inject. I am trying to figure out how to add the ability to send attachments via the nullmailer-inject call. I could not find much documentation on google about nullmailer. Has anyone used it before to send attachments? Here is function I have so far that sends a regular email. The variables...
3
2601
by: Robert Mark Bram | last post by:
Howdy all! When do I call something a property and when do I call something an attribute? It has me a little confused at the moment! Any advice would be most appreciated! Rob
4
4618
by: Justine | last post by:
Hi All, I would like to know where & when exactly we would have a need for attributes. A realistic example. Thanz in Advance, Justine
2
3537
by: Harry F. Harrison | last post by:
I get 2 compile errors on assembly attributes after creating a custom attribute. If I comment out the attribute, the errors go away. I don't get it because my attribute specifies class usage, not assembly usage. Assembly attribute 'System.Runtime.InteropServices.GuidAttribute' is not valid: Assembly custom attribute 'System.Runtime.InteropServices.GuidAttribute' was specified multiple times with different values Attribute...
4
1649
by: Theo | last post by:
Hi, i created a custom attribute that accepts an argument in the constructor to fill a property. The constructor is supposed to be called when then attribute is set but that doesn't seem to happen. Sample code: <System.AttributeUsage(System.AttributeTargets.All, AllowMultiple:=True)_ Public Class CustomAtt Inherits System.Attribute Public Sub New(ByVal Arg As String) Me.Arg = Arg
5
1333
by: Joel Andres Granados | last post by:
Hi list: I have googled quite a bit on this matter and I can't seem to find what I need (I think Im just looking where I'm not suppose to :). I'm working with code that is not of my authorship and there is a class attribute that is changes by directly referencing it (object.attr = value) instead of using a getter/setter (object.setAttr(Value) ) function. The thing is that I have no idea when the change occurs and I would REALLY like...
1
3491
by: =?Utf-8?B?SkhpbGJDUk0=?= | last post by:
I am trying to write a httpmodule to inject javascript includes on some of the aspx pages we have. For instance, I want to inject into the resulting IIS response something like... response.Write("<script language='javascript'>"); response.Write("alert('tt');"); response.Write(@"</script>");
2
8763
by: Nathan Sokalski | last post by:
I am attempting to create icons for controls I have created using VB.NET by using the System.Drawing.ToolboxBitmap attribute. I have managed to do this in C# by specifying the path to the *.ico file, but I have been unable to get any of the overloads to work in VB.NET. I would like to store the *.ico files in a *.resx file so that users do not need anything other than the *.dll, but at the moment I am just trying to get any of the overloads...
0
9706
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
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10320
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10077
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...
1
7620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5521
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
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4299
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.