-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: Clouds
Message 2 in Discussion
If you have msdn documentation installed on ur machine plz check this link
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpref/html/frlrfSystemWebServi
cesProtocolsLogicalMethodInfoClassGetCustomAttributeTopic.htm
(mind well its a link from msdn 2003 collection)
for you reference i m pasting the code as it is..
using System;
using System.Reflection;
using System.Web.Services.Protocols;
// Define a custom attribute with one named parameter.
[AttributeUsage(AttributeTargets.Method | AttributeTargets.ReturnValue,
AllowMultiple=true)]
public class MyAttribute : Attribute
{
private string myName;
public MyAttribute(string name)
{
myName = name;
}
public string Name
{
get
{
return myName;
}
}
}
public class MyService
{
[MyAttribute("This is the first sample attribute")]
[MyAttribute("This is the second sample attribute")]
[return: MyAttribute("This is the return sample attribute")]
public int Add(int xValue, int yValue)
{
return (xValue + yValue);
}
}
public class LogicalMethodInfo_GetCustomAttribute
{
public static void Main()
{
Type myType = typeof(MyService);
MethodInfo myMethodInfo = myType.GetMethod("Add");
// Create a synchronous 'LogicalMethodInfo' instance.
LogicalMethodInfo myLogicalMethodInfo =
(LogicalMethodInfo.Create(new MethodInfo[] {myMethodInfo},
LogicalMethodTypes.Sync))[0];
// Display the method for which the attributes are being displayed.
Console.WriteLine("\nDisplaying the attributes for the method : {0}\n",
myLogicalMethodInfo.MethodInfo);
// Displaying a custom attribute of type 'MyAttribute'
Console.WriteLine("\nDisplaying attribute of type 'MyAttribute'\n");
object attribute =
myLogicalMethodInfo.GetCustomAttribute(typeof(MyAttribute));
Console.WriteLine(((MyAttribute)attribute).Name);
// Display all custom attribute of type 'MyAttribute'.
Console.WriteLine("\nDisplaying all attributes of type
'MyAttribute'\n");
object[] attributes =
myLogicalMethodInfo.GetCustomAttributes(typeof(MyAttribute));
for(int i = 0; i < attributes.Length; i++)
Console.WriteLine(((MyAttribute)attributes[i]).Name);
// Display all return attributes of type 'MyAttribute'.
Console.WriteLine("\nDisplaying all return attributes of type
'MyAttribute'\n");
ICustomAttributeProvider myCustomAttributeProvider =
myLogicalMethodInfo.ReturnTypeCustomAttributeProvider;
if(myCustomAttributeProvider.IsDefined(typeof(MyAttribute), true))
{
attributes = myCustomAttributeProvider.GetCustomAttributes(true);
for(int i = 0; i < attributes.Length; i++)
if(attributes[i].GetType().Equals(typeof(MyAttribute)))
Console.WriteLine(((MyAttribute)attributes[i]).Name);
}
// Display all the custom attributes of type 'MyAttribute'.
Console.WriteLine("\nDisplaying all attributes of type
'MyAttribute'\n");
myCustomAttributeProvider =
myLogicalMethodInfo.CustomAttributeProvider;
if(myCustomAttributeProvider.IsDefined(typeof(MyAttribute), true))
{
attributes = myCustomAttributeProvider.GetCustomAttributes(true);
for(int i = 0; i < attributes.Length; i++)
if(attributes[i].GetType().Equals(typeof(MyAttribute)))
Console.WriteLine(((MyAttribute)attributes[i]).Name);
}
}
}
Regds
Badal
-----Original Message-----
From: Deepblue21281 [mailto:[EMAIL PROTECTED]
Sent: Sun 04/07/2004 13:51
To: BDOTNET
Cc:
Subject: Fetching the Custom Attribute Name
<http://c.msn.com/c.gif?NC=9523&NA=34131&PS=&PI=26283&DI=416&TP=http://groups
.msn.com>
<http://sc.groups.msn.com/themes/R9c/pby/img/mail/mlstar.gif> New Message
on BDOTNET <http://groups.msn.com/BDOTNET>
<http://sc.groups.msn.com/img/R9c/c.gif>
Fetching the Custom Attribute Name
<http://groups.msn.com/BDOTNET/_notifications.msnw?type=msg&action=showdiscus
sion&parent=1&item=18113>
Reply
<mailto:[EMAIL PROTECTED]
ibute%20Name>
<http://sc.groups.msn.com/img/R9c/c.gif> Reply to Sender
<mailto:[EMAIL PROTECTED]
ttribute%20Name> Recommend
<http://groups.msn.com/BDOTNET/_notifications.msnw?type=msg&action=recommend&
parent=1&item=18113> Message 1 in Discussion
From: Deepblue21281
<http://groups.msn.com/BDOTNET/profile?user=Deepblue21281%E2%9C%93>
Dear Friend,
I have small problem, as in my program i have created custom attribute. and i
put this in a dll file and in the another file where i have set the
refereance to this dll file.
But finding problem in fetching the name of the custom attribute. Pls help me
. I am adding the code :-
This is the dll file code
=================
using System;
using System.Diagnostics ;
namespace CustomAttribute1
{
[AttributeUsage(AttributeTargets.Method)]
public class AuthorAttribute : Attribute
{
private string name;
public AuthorAttribute(string aName)
{
this.name = aName;
}
}
class CustomAttribute
{
[Author("Mr. Pankaj")]
public static string show()
{
return " Microsoft";
}
}
}
View other groups in this category.
<http://groups.msn.com/Browse?CatId=26>
Also on MSN:
Start Chatting <http://g.msn.com/2GRENUS/2_8085_01> | Listen to Music
<http://g.msn.com/2GRENUS/2_8085_02> | House & Home
<http://g.msn.com/2GRENUS/2_8085_03> | Try Online Dating
<http://g.msn.com/2GRENUS/2_8085_04> | Daily Horoscopes
<http://g.msn.com/2GRENUS/2_8085_05>
<http://sc.groups.msn.com/img/R9c/c.gif>
To stop getting this e-mail, or change how often it arrives, go to
your E-mail Settings <http://groups.msn.com/BDOTNET/_emailsettings.msnw> .
Need help? If you've forgotten your password, please go to Passport
Member Services <http://groups.msn.com/_passportredir.msnw?ppmprop=help> .
For other questions or feedback, go to our Contact Us
<http://groups.msn.com/contact> page.
If you do not want to receive future e-mail from this MSN group, or
if you received this message by mistake, please click the "Remove" link
below. On the pre-addressed e-mail message that opens, simply click "Send".
Your e-mail address will be deleted from this group's mailing list.
Remove my e-mail address from BDOTNET.
<mailto:[EMAIL PROTECTED]>
DISCLAIMER:
This message (including attachment if any) is confidential and may be privileged.
Before opening attachments please check them for viruses and defects. MindTree
Consulting Private Limited (MindTree) will not be responsible for any viruses or
defects or any forwarded attachments emanating either from within MindTree or outside.
If you have received this message by mistake please notify the sender by return
e-mail and delete this message from your system. Any unauthorized use or dissemination
of this message in whole or in part is strictly prohibited. Please note that e-mails
are susceptible to change and MindTree shall not be liable for any improper, untimely
or incomplete transmission.
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/BDOTNET/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you received
this message by mistake, please click the "Remove" link below. On the pre-addressed
e-mail message that opens, simply click "Send". Your e-mail address will be deleted
from this group's mailing list.
mailto:[EMAIL PROTECTED]