Click here to Skip to main content
15,901,505 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 Title

Attributes 

1 Oct 2013 by ICEFLOWER2
Hi, I have two questions:1. How can I have A Text Property Like TextBox ...2. How can I Make Browse For File or Directory Property ..."
1 Oct 2013 by Sergey Alexandrovich Kryukov
What do you mean "like"? TextBox or not? Anyway, just a few examples:class MyType { internal TextBox FirstTextBox { get; set; } public TextBox SecondTextBox { get; private set; } public TextBox ThirdTextBox { get { return thirdTextBox; } } // and so on... ...
2 Oct 2013 by ICEFLOWER2
I mean: I want to make Property Like Text Property of TextBox or Label Control for usercontrol to use in design modethanks
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...
9 May 2011 by Eddy Vluggen
A few fields to store general information on the provided code
23 Aug 2020 by Jin Vincent Necesario
In this article, we'll explore the world of C# attributes.
3 Dec 2013 by Rion Williams
Applying conditional attributes in ASP.NET MVC Views.
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...
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...
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...
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 ,...
1 Mar 2015 by Member 11006077
Hi All,I have got a topic to do the ppt on "Config files and its attributes usage"I have explained about App.config and web.config in pptBut my sir asking me like give examples for Attributes..Here what is mean by Attributes and how we can usei don't no What is attribute and its...
1 Mar 2015 by Thomas Daniels
See here:MSDN - Attributes (C# and Visual Basic)[^]
1 Mar 2015 by RajeeshMenoth
Hi,Refer this..1)Attributes in C#2)Attributes extend classes and types.3)C# - Attributes
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.
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]...
31 Jul 2015 by goldli88
perhaps there is a attribute [AttributeUsage(AttributeTargets.Method)] class AuthAttribute : Attribute { public AuthAttribute) { Do(); } private void Do() { do some check... //What's here ? ...
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, ...
19 Oct 2014 by Shivprasad koirala
In this article we will try to understand C# Attributes.
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);
15 Aug 2016 by Sergey Kizyan
6th lecture from my series. This lecture is about attributes.
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.
20 Nov 2013 by Member 10415722
We only talk about DTD and XML in class for 2 days and i have this assignment not sure if im doing it right or did everything that has been asked. Atleast i try, any help will be appreciated!!Assignment You have been asked to represent airport data where an airport has required attributes...
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 ///...
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...
23 Dec 2011 by weirbear
I have a VS 2005 solution (VB.NET) that contains a number of projects. In one project I have created a custom attribute class. I can assign the attribute to properties of classes in the other projects.My problem is that the attributes are not being attached in the other projects. The...
23 Dec 2011 by Wendelius
Create a Class library project, place your attribute in it and add references to that dll in your other projects. This way you can share for example classes between projects.
23 Dec 2011 by #realJSOP
Can't you implement the custom attribute in its own assembly, and then use it wherever you need it?EDIT ======================Wow - a 1-vote. You really make us want to keep helping you. Is the custom attribute defined as internal?BTW, it's considered bad practice to inherit from a...
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...
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[^]
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....
3 Aug 2015 by xszaboj
Custom validation attribute - contains
13 Mar 2012 by gossd
An introduction and proof of concept code for the idea of declarative multi threading in C#.
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...
15 Aug 2017 by Vaibhav M Nalwad
Resolving Dependencies via Attributes and Reflection
6 Jul 2013 by blnreddy
what is the use of pre-processor and attributes in csharpwhat is difference between pre-processor and attributes in csharp
27 Apr 2012 by John Orendt
The items need to be persisted.seeASP.NET Color DropDown Control[^]
20 Feb 2020 by Hamza Nadeem
@RELATION abalone @ATTRIBUTE sex REAL @ATTRIBUTE length REAL @ATTRIBUTE diameter REAL @ATTRIBUTE height REAL @ATTRIBUTE wholeWeight REAL @ATTRIBUTE shuckedWeight REAL @ATTRIBUTE...
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...
25 Nov 2013 by Balachandar Jeganathan
Exception handling using custom attributes and stacktrace.
27 Mar 2023 by V_Cento
A simple way to extend an HTML element
5 Mar 2017 by DotNetSteve
Creating an extension class for View Models to save public properties using Generics and Delegates, replacing a reflection implementation
4 Apr 2018 by Eric Lynch
A flexible command line parsing class that uses C# attributes and reflection to discover syntax
25 Feb 2018 by #realJSOP
Abusing attributes, and loving it.
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...
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...
20 Jul 2015 by Sergey Alexandrovich Kryukov
Yes, you can, but there is no such predefined attribute. You can easily define it yourself and apply to the functions to be timed. Note the enumeration member System.AttributeTargets.Method. When you define your attribute, you can apply the attribute System.AttributeUsageAttribute to your...
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 :
13 Apr 2015 by Member 11286812
XDocument xDocument = XDocument.Load("MyXml.xml");XElement soapenvXElement = xDocument.Descendants().FirstOrDefault();soapenvXElement.Value = "NEWLINK";
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)[^]
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...
6 Mar 2015 by Mikro_PM
Hi all,I have a question concerning Abstractspoon ToDoList v6.9.2.I am using several attributes, including custom ones (Project, Meeting Type, ...) to organise my project task list.To filter the work topics for regular meeting I want to filter the task list by searching for partial results...
15 Oct 2021 by Youssef Hany 2021
I'm trying to run my code on anaconda prompt and it gives me this error, any suggestions? AttributeError: module 'nearest_neighbors' has no attribute 'knn_batch' What I have tried: I've tried pip install knn but no use
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...
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...
8 Oct 2012 by YORENGOY
How to add an attribute to a method declared on partial interface?Ihave this code on a fileusing System;using System.Net.Security;using WCF = global::System.ServiceModel;namespace CMAWCF.ServiceContracts{ public partial interface IMyServiceServiceContract { ...
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 Mar 2023 by Tarak chandan
AN = Sequential() AN.add(Dense(256, input_dim = 302, activation='relu')) AN.add(Dropout(0.2)) AN.add(Dense(128, activation='relu')) AN.add(Dropout(0.2)) AN.add(Dense(128, activation='relu')) AN.add(Dropout(0.3)) AN.add(Dense(32,...
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...
21 Jan 2020 by kr.is
How to create a simple validation attribute using C#
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...
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[^]
5 Mar 2017 by RydenChoi
I am making a windows application that sync the source data to Active Directory.This application works like this.1. Choose Source Data(Department, User)2. Mapping user or department attributes from source data3. When Application service is run, it create groups and users in...
15 Oct 2021 by Youssef Hany 2021
I'm trying to run a code that uses nearest neighbor module. It uses an attribute named Knn_batch in this module. The code gives me this error: AttributeError: module 'nearest_neighbors' has no attribute 'knn_batch' the code : def...
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.
2 Oct 2023 by Marco Giglio
I'm trying to read attributes of a XML node (another system)... This is an XML of example: ...
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 = @" ...
7 Nov 2013 by rohit24c
Hi I am new to Winforms.I have a Class :public class Data { [Category("Numbers"), Description("Set of 256 user variables available in the form of a 32 bit sign integer.")] public int[] num{ get; set; } //Constructor public Data() { ...
18 Jun 2013 by codingStar
hi,alldoes anyone know how to retrieve xml attribute value in c#. - -
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...
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...
5 Dec 2013 by Ron Beyer
Unfortunately there is no magic in the ObsoleteAttribute[^] class. The compiler service looks for this attribute and displays the warnings in the dialog box.However, you can raise warnings yourself, like:public void MyMethod(){#warning This method is still in development and is...
20 Jun 2012 by jophyjob
Hello All, I made a custom attribute but i cant able to use as i needed, my Requirement is [MyAttributes(Language1[0] = "some text")] // not working public void method1() { }// Attribute class is...
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...
5 Nov 2018 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
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...
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...
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!!
19 Mar 2013 by gouravkaila
i am using e.Row.cells[icount].Attributes.Add("onclick", "alert('Test')")in place of e.Row.Attributes.Add("onclick", "alert('Test')")I t works fine as i am excluding the first 3 counts (where i dont need these attributes.)Still a better solution i am seeking.Thanks
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...
2 Feb 2018 by Richard Deeming
Try: var newItem = $("").attr("id", item._id).text(item.name); console.log("ID:", newItem.attr("id"), newItem);
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.
1 Oct 2015 by VijayRana
Some useful MVC Attributes (Bind Attribute, HandleError Attribute, HiddenInput Attribute, Remote Attribute)
3 May 2013 by gicalle75
question: how can you keep things DRY by only applying metadata information for dataannotations and validation on the master class, and then reuse this on the viewmodels?example:class book (domain model) and the metadataImports...