Click here to Skip to main content
15,886,069 members
Everything / Attributes

Attributes

attributes

Great Reads

by Eddy Vluggen
A few fields to store general information on the provided code
by kr.is
How to create a simple validation attribute using C#
by Raja.Krishnasamy
Attached the test data with method for regression testing by declaring ref type in attribute
by Rion Williams
Applying conditional attributes in ASP.NET MVC Views.

Latest Articles

by V_Cento
A simple way to extend an HTML element
by Jin Vincent Necesario
In this article, we'll explore the world of C# attributes.
by kr.is
How to create a simple validation attribute using C#
by thorssig
html2struct parses HTML code into a simple tree-like structure of objects and provides a little tool-set for extracting data from it

All Articles

Sort by Score

Attributes 

9 May 2011 by Eddy Vluggen
A few fields to store general information on the provided code
21 Jan 2020 by kr.is
How to create a simple validation attribute using C#
20 Jun 2012 by markovl
Your constructor is declared wrong. It should look like:public MyAttributesAttribute(string[] test){ //...}Then when you use it you actually call it's constructor:[MyAttributes(new string[] {"0", "1", "2"})]public void SomeMethod(){ }Also I'd suggest you...
20 Jun 2012 by Sergey Alexandrovich Kryukov
What you are trying to do is not allowed in .NET. For C#, here is the list of allowed attribute parameter types:http://msdn.microsoft.com/en-us/library/aa664615%28v=vs.71%29.aspx[^].Your declaration is also not allowed by syntax, because a parameter itself, when named, should be a property...
28 Jul 2013 by Raja.Krishnasamy
Attached the test data with method for regression testing by declaring ref type in attribute
3 Dec 2013 by Rion Williams
Applying conditional attributes in ASP.NET MVC Views.
2 Aug 2015 by Andreas Gieriet
If debugging goes wrong (as you describe above), I usually go this approach:1) close and restart Visual Studio, rebuild the solution, try debugging again2) if no success, check if the produced PDB file is created every time3) if this is the case, check the debug tab in the project...
8 Jul 2013 by Fredrik Bornander
Something like this might point you in the right direction;using System;using System.Security;using System.Security.Permissions;namespace AccessThingie { [Serializable] [AttributeUsageAttribute(AttributeTargets.Method)] public class IsAuthorized :...
24 Oct 2014 by BillWoodruff
I think you either are willing to put in the effort to learn programming in C# in conjunction with learning how to implement an application in Windows Forms (or another C# framework, like WPF), or, you are wasting your time.For the same amount of time you might put in building some...
27 Aug 2019 by Richard Deeming
The problem seems to be that you don't have a wrapping element, so the array attributes are ignored. If you had: then your code would work. Without the wrapping element, it looks like...
26 Nov 2019 by Afzaal Ahmad Zeeshan
What you are looking for is to be done on the runtime, and these attributed at mapped at compile-time. You will not be able to modify them after your app has been built. One way to solve this would be to use a dynamic route and then process the actual URI on runtime and execute the...
29 Nov 2011 by Sebastian Gruchacz
I have this custom attribute - that defines some values I could use in PropertyGrid to build list of valid values that user can pick from when editing property value, but is not limited to this:/// /// Apply list of valid known values for specific property ///...
23 Dec 2011 by Sergey Alexandrovich Kryukov
One thing are do not understand it: the attribute is not attached to the project. It can be attached to the assembly. When you understand it, you won't have a problem with "different project" — is simply does not matter.You have to isolate two different things: first, accessing of an...
19 Jan 2012 by lukeer
In the mentioned case with multiple objects to be shown in PropertyGrid the parameter type of MyTypeConverter.GetStandardValuesSupported(context) changes to System.Windows.Forms.PropertyGridInternal.MergePropertyDescriptor.This type has a private field private PropertyDescriptor[]...
7 Feb 2012 by Sergey Alexandrovich Kryukov
First, let's look just at the title of this question. It looks you are missing something important.Let's look at all possible targets of the attributes. Please read this: http://msdn.microsoft.com/en-us/library/system.attributetargets.aspx[^].All those targets are classified into...
16 Jan 2013 by __TR__
Take a look at this CP article Attributes in C#[^]More resources here[^]
12 Sep 2013 by Prasad Khandekar
Hello,MP3 file format uses ID3 metadata[^]. It allows information such as the title, artist, album, track number, and other information about the file to be stored in the file itself. The windows OS already has support for this file format and necessary code to retrieve the ID3 metadata....
5 Dec 2013 by Yvan Rodrigues
I don't think this is possible, but I have always hoped it is. When you apply [Obsolete("You really shouldn't use this anymore.")] to a member, it causes the compiler to generate a warning or error, which then appears in the Error List in Visual Studio.It would be amazing to be able to...
10 Oct 2014 by Shekhar Pankaj
New proposed element to be added in W3C Candidate recommendation: 09 September 2014
24 Oct 2014 by Sergey Alexandrovich Kryukov
You can start here: http://msdn.microsoft.com/en-us/library/dd30h2yb%28v=vs.110%29.aspx[^].You see, if you know programming, you don't need any books; the original documentation will tell you enough. If you don't know programming well enough, the book on "Form Programming" won't really help...
1 Mar 2015 by Thomas Daniels
See here:MSDN - Attributes (C# and Visual Basic)[^]
20 Apr 2015 by Abhinav S
You can create your own custom attributes. Generally, data annotations are customized to suit your needs.TryCustom Validation Attribute in ASP.NET MVC3[^]ASP.NET MVC Custom Compare Data Annotation with Client Validation[^]MVC 4: Custom Validation Data Annotation Attribute[^]
18 Feb 2017 by Bryian Tan
have you try clear the browser cache?How do I clear my web browser's cache, cookies, and history?[^]Another alternative is to add a random querystring to the link to the pdf.Let said the link to PDF document is /document?id=2, the new link should be /document?id=2&r=79834234 ,...
6 Jan 2018 by Member 1097736
I have to restrict access to particular action in a controller and so i have created a RestrictAccess attribute which implements ActionFilterAttribute . RestrictAccess public class RestrictAccess : ActionFilterAttribute { public override void...
6 Jan 2018 by Bryian Tan
In the HandleUnauthorizedRequest method try using the following syntax and make sure you register the filter (RestrictAccess) in the FilterConfig filterContext.Result = new RedirectResult("~/Test/RedirectToError");
2 Feb 2018 by Richard Deeming
Try: var newItem = $("").attr("id", item._id).text(item.name); console.log("ID:", newItem.attr("id"), newItem);
20 Feb 2020 by Richard MacCutchan
@ATTRIBUTE sex REAL @DATA M,0.455,0.365,0.095,0.514,0.2245,0.101,0.15,15 You have declared column 1 (Sex) as a REAL type, but your data uses a character type. I have never heard of Weka or ARFF but found the information quite easily at Arff...
13 Jul 2021 by Chris Copeland
The JitIntrinsic attribute is a legacy version of the Intrinsic attribute. My limited understanding of it is that it's used to signal that a method/property/field can be optimized by the JIT. .net - What does the [Intrinsic] attribute in C# do?...
13 Jul 2021 by PIEBALDconsult
I don't know, but maybe try bool cfg ; while (cfg = reader.ReadToFollowing("cfgattr")) instead?
15 Oct 2021 by OriginalGriff
Quote: To write the code its complicated because several python files are imported so it'll be so long for anyone to read. My all problem is that KNN_batch is not available as an attribute of nearest_neighbors so I want to have it but don't know...
3 May 2022 by Graeme_Grant
Html 5 can have custom elements. Have a read of this help: Using custom elements - Web Components | MDN[^] And this article goes into a little bit more detail: Custom Elements: defining new elements in HTML - HTML5 Rocks[^]
3 Oct 2022 by Richard Deeming
To read the value from the input, you need to get a reference to it. For example: function myFunction() { const maxLength = document.getElementsByName("maxLength")[0]; const element = document.getElementById("textarea"); element.maxLength...
27 Aug 2019 by C Pottinger
Hello folks. I can really use some help here. What I am attempting to do is to create an XML serializer that can handle a class that has several derived subtypes. I already know the basics of doing this: I wrote this blog entry to help me remember how. But now, I am diving a little deeper and...
24 May 2011 by ArtificerGM
What's wrong with using built-in collections?Sub CustomControl_PreRender(control As UserControl) Handles CustomControl.PreRender Dim ctrl as UserControl For Each ctrl in UserControl.Controls If Ctrl.Invalidated == True Then Ctrl.Render() End If ...
17 Jan 2012 by lukeer
Hi experts,in an application I have a System.Windows.Forms.PropertyGrid to let user change some business model properties.One of these properties is of an enumerated type that is often used similarly, but for a few properties, some values shall not be displayed. Therefore I created...
17 Jan 2012 by Michel [mjbohn]
I don't know much about attributes but nosy as I am, I did some test.private void button1_Click(object sender, EventArgs e) { propertyGrid1.SelectedObjects = new object[]{_businessObject1}; Type t = _businessObject1.GetType(); PropertyInfo pi =...
6 Feb 2012 by Andreas Gieriet
Hello Sebastian, Why going over attributes? I get the impression that you "abuse" the attribjtes for something you could do straight forward without attributes. Maybe I'm wrong.You seem to load the meta data at runtime, so, use a common data structure that you populate and pass to your...
7 Feb 2012 by VermaManish
My query is related to getting attributes of the instance from within the type of that instance. I can explain it better with an example.Consider a simple class called "MyClass" with just one string type property called "Description". public class MyClass { private...
27 Apr 2012 by John Orendt
The items need to be persisted.seeASP.NET Color DropDown Control[^]
3 Sep 2012 by jim lahey
Hello everyone,I'm using PostSharp to implement logging and security aspects in my application. PostSharp uses attributes to decorate methods with aspects which are then modified at compile time. Does anyone know of a way that I can use dependency injection with these aspects? I'm...
4 Sep 2012 by Martijn Kok
In a book I recently read about dependency injection (Dependency Injection in .NET by Mark Seemann [^]) there is a chapter (chapter 9) that might interest you. The chapter is about interception. Dynamic interception is discussed and compared with using the decorator pattern and using attributes...
8 Oct 2012 by Sergey Alexandrovich Kryukov
This problem has nothing to do with attributes or… it does not have to do with anything. Partial syntax is not very much of syntax; it's something very simple, used to define some type in two or more fragments of text of the code, typically in different files. And nothing else. It does...
30 Dec 2012 by Member 9319288
This is my code:using System;using System.Collections.Generic;using System.Linq;using System.Text;[assembly:CLSCompliant(true)]namespace AttributeCLSComplaint{ class Abc { UInt32 y; [CLSCompliant(true)] public UInt32 meth1() { ...
30 Dec 2012 by Sergey Alexandrovich Kryukov
Basically, it tells you that the use of this attribute for the method meth1() makes no sense. It is invisible to the assembly using your assembly because its declaring class is invisible.You should think about applications of this attribute. Are you sure you really need it? Basically, you...
16 Jan 2013 by iaskalyani45
attrbutes in c#.net,different types of attributes,how we will create attributes in c#.net
16 Jan 2013 by josh-jw
check this link:http://www.c-sharpcorner.com/UploadFile/PatrickSmacchia/attributes02022006132738PM/attributes.aspx[^]
11 Mar 2013 by gouravkaila
Hi all,I am trying to add attributes to my gridview at runtime in rowdatabound as e.Row.Attributes.Add("onclick", "alert('Test')")I want to remove it for the first two columns.I have tried e.Row.Cells(0).Attributes.Remove("onclick")But its not working.Help Please!!
18 Jun 2013 by Christian Graus
You can use the XmlDocument[^]class and XPath[^] to find values, or you can use Linq to XML[^].
18 Jun 2013 by Sergey Alexandrovich Kryukov
There are different ways of XML parsing provided in .NET FCL. This is my short overview of them:Use System.Xml.XmlDocument class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.See...
8 Jul 2013 by Stiaan Jacobs
I would like to check authorization on a method for the current user to check if he/she has the right to perform this action.Here is the example of the attribute I have in place: [AttributeUsageAttribute(AttributeTargets.Method)] public class IsAuthorized : Attribute { ...
21 Aug 2013 by Imran Khan Pathan
Hello FriendsIs that possible to change the value of method parameter by using custom attribute?I want to Url decode string parameter by custom attribute and I don't want to go each and every method to write Url decode code for string value, I want to write one custom attribute to get...
21 Aug 2013 by Gregory Gadow
If I understand what you are asking, no. All attributes do is attach meta data in the Common Intermediate Language (CIL) to a class, method or other block of code; it does not alter how the code is compiled to CIL. A part of this compiling is to "mangle" method names, adding the return type...
12 Sep 2013 by mccaber82
Hi,I am creating my own custom file using a filestream/binary writer and I am looking to write custom details attributes to the file (similar to what you'd see when you go to Details when right click> properties on an MP3). The properties I want to add are Duration (DateTime) and...
12 Sep 2013 by Thomas Barbare
Here is a link about that : http://blog.rodhowarth.com/2008/06/how-to-set-custom-attributes-file.html[^]
2 Oct 2013 by ICEFLOWER2
I Find it:[VB] Private TargetValue As String _ Public Property Target() As String Get Return TargetValue End Get Set(ByVal value...
1 Mar 2015 by RajeeshMenoth
Hi,Refer this..1)Attributes in C#2)Attributes extend classes and types.3)C# - Attributes
13 Apr 2015 by Andrey Golubtsov
Hi to all . I'm looking for advice . I have an XML file , and my task is to change the attribute of node . But when i make this a have an error: "Namespace Manager or XsltContext needed" .My xml file :
19 Apr 2015 by BoySetsFire
Hi,i am binding a class to a propertygrid.Now i will manipulate the propertygrid via attributes.sample:class PDFSettings{ [Range(1,100)] [DefaultValue(85)] public int PDFJPEGQUALITY { get; set; }}The DefaultValue-Attribute works.But the...
20 Apr 2015 by Am Gayathri
MVC validators like required field etc..are they c# attributes?I was learning C# attributes, I have one doubt that whether MVC validators are example of attributes or not ? I think they are.As i learned attributes are for description of element. We can create custom attributes which can...
11 Jul 2015 by Member 11784947
I have a function that uses an instance of stopwatch to measure the time of method by starting and stopping. Can I somehow define that function inside an attribute and just decorate any given method with that attribute to measure time of that method ? That would reduce the LOC. I don't want to...
31 Jul 2015 by Sergey Alexandrovich Kryukov
First, in the line "public AuthAttribute)", brackets are unbalanced.Unfortunately, the question makes little to no sense; and something tells me that you won't add much sense when you answer my question I asked you in my comment to the question. However, it wakes up my curiosity. So, let me...
31 Jul 2015 by goldli88
Thanks for answer.for additional,the sense looks like below public class EmailService : AuthObj { public EmailService() { var mailServer = new MailServer { Host = "", Port = 25, ...
3 Aug 2015 by xszaboj
Custom validation attribute - contains
9 Aug 2015 by Václav 'Annubiz' Kaněra
Hi,I have problem with parsing of specific XML file. I need to extract all of the "sc:Doc number" values and "status" values from this XML.I am not able to read this attribute, can you please help?-
10 Aug 2015 by Václav 'Annubiz' Kaněra
I have just realized my problem :XmlNodeList nodes = xmlDocument.GetElementsByTagName("sc:Doc number");So after change to :XmlNodeList nodes = xmlDocument.GetElementsByTagName("sc:Doc");Everything works like charm
17 Apr 2016 by Member 11090364
Hi,I have a problem with validation of License in the server side of our application.What I want is when the method CreateProject(User user) is invokedBehind the scenes that will lead to check with the License service if the user has license to create new project, in case the user has no...
17 Apr 2016 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
GetService is just returning true or false. Nothing else.
18 Feb 2017 by PDTUM
Hello, I wrote an application using C# VS 2010 that calls an PDF page from an internet location and displays it on an internal Adobe viewer in an IFrame. It seemed to work perfectly, but then I updated one of the PDF docs and it still calls the old one. I even deleted the file from the online...
24 Feb 2017 by Murray Hertz
The (relatively) new CallerMemberName attribute is useful, but I would like to use it in some overrides like ToString(). The problem is that when I add it to my method, the signature changes sufficiently so that the override is no longer seen as such.In Visual Studio 2015, it shows a red...
24 Feb 2017 by Graeme_Grant
It can't be used that way. That is why the error message is there. You can read more about CallerMemberName here: CallerMemberNameAttribute Class (System.Runtime.CompilerServices)[^]
2 Feb 2018 by random_xyz
I'm trying to do is get a list of items from a node js server create li tags dynamically for each one, then somehow embed the ID that is coming from the server in each created HTML element as a custom attribute or an ID. I hope this make sense. Thanks in advanced for taking the time to help, I'm...
19 Jul 2022 by Member 13809822
Im trying to set a value to a textbox and i have found the HtmlElemnt i need and changed the value of the text box but it seems like the element won't update himself or trigger some lind mof userinput method. the web will say "You must fill this before you can finish" even when you can clearly...
8 Aug 2018 by Dinesh Kumar Dora
Hello friends, One quick question. I need to do the following modification in a xml config file. Need to replace the following: with
8 Aug 2018 by Eric Lynch
Something like the following should work. XmlNode node = doc.SelectSingleNode("//security"); XmlAttribute attr = doc.CreateAttribute("proxyCredential"); attr.Value = "attribute-value"; node.Attributes.Append(attr);
26 Nov 2019 by Krishnananthan Vijayaretnam
Currently I'm working on an asp.net mvc project. I have done an attribute routing and it's working well. The code is given below. Now I'm thinking of keeping the Route values on a table and set it to relevant actions. For example currently for the action TestOne I've set "Test_Test_One" as a...
21 Jul 2021 by KarNullKa
What does this code that has no body do? Source code [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Property)] internal class JitIntrinsicAttribute : Attribute { } Edit: I know what the attribute is...
13 Jul 2021 by mh_user
Hi, I'm trying to read attributes from an xml file with C#., -but the code I use skips rows & reads only every other attribute with the same element name. - Does anyone know better than me how to read all the attributes of 'cfgattr' with C#? ...
13 Jul 2021 by Richard MacCutchan
Look at your loop: while (reader.Read()) { bool cfg = reader.ReadToFollowing("cfgattr"); // doing this every time skips a line if (cfg==true) You should only do the...
13 Jul 2021 by mh_user
Thank YOU!! You saved my day!! This is the working code after your Suggested adjustment! using System; using System.IO; using System.Xml; namespace xml_test { class Program { static void Main(string[] args) { ...
12 Oct 2021 by KarNullKa
I have a AAA class with a custom attribute XXX, is it possible to get the AAA instance and the Property where the attribute is used in the attribute constructor? Class where is Attribute used. public class AAA { int _property; [XXX]...
15 Oct 2021 by Richard MacCutchan
This is the same question you asked yesterday at How do I fix this error?[^]. And the answer remains the same. You need to check the nearest_neighbors module or class, and find out why this attribute is not present.
3 May 2022 by Chopin2001
YouTube has html tags that start with yt-. For example, yt-page-navigation-progress or ytd-watch-flexy. Is this a new technology in html5? I'm wondering if this works in all browsers and there's nothing wrong with it? Also can JavaScript read...
30 Mar 2023 by OriginalGriff
Quote: still not tried give the solution No. While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of...
22 Sep 2023 by Marco Giglio
Hello, I'm trying to get names of attributes nodes of an XML file..i'm able to read nodes and attributes value but not names. In this xml example: - -...
22 Sep 2023 by Valery Possoz
Hello, you could be using the class XmlNode see here: XmlNode Class (System.Xml) | Microsoft Learn[^] Refactoring a bit your code like that: While reader.Read Dim lettura = reader.NodeType Dim valueA As...
24 Sep 2023 by Richard MacCutchan
You were given the answer at How read name of attribute of XML nodes (not value)![^]. You just need to adapt that code to get the names into the MessageBox.
24 Sep 2023 by Dave Kreskowiak
This is not that hard: Dim doc As XDocument = London ...
24 Sep 2023 by Graeme_Grant
Here is a different way of doing the same thing [in C#]: string xmlString = @" ...
15 Aug 2016 by Sergey Kizyan
6th lecture from my series. This lecture is about attributes.
25 Feb 2018 by #realJSOP
Abusing attributes, and loving it.
13 Mar 2012 by gossd
An introduction and proof of concept code for the idea of declarative multi threading in C#.
30 May 2018 by Syed Zain Shah
This article tells you about the convention-based Routing and Attribute Routing in detail. Feel free to give your feedback.
23 Aug 2020 by Jin Vincent Necesario
In this article, we'll explore the world of C# attributes.
1 Oct 2015 by VijayRana
Some useful MVC Attributes (Bind Attribute, HandleError Attribute, HiddenInput Attribute, Remote Attribute)
19 Oct 2014 by Shivprasad koirala
In this article we will try to understand C# Attributes.
4 Apr 2018 by Eric Lynch
A flexible command line parsing class that uses C# attributes and reflection to discover syntax
10 Mar 2016 by Masoud Zehtabi Oskuie
.NET provides many techniques to make your code cleaner, easy to read and maintain. Extensions and Attributes are two examples helping developers to not only maintain and extend the applications simpler than before but also makes repetitive tasks less annoying for developers.