Questions tagged [.net-attributes]

The tag `.Net attributes` describes anything related to using or creating attributes in .net source code. It is specifically meant for classes derived from the `System.Attribute` type.

.Net attributes describe the creation and usage of attribute classes in .Net program code (C#, VB.Net or otherwise). .Net attributes are derived of the System.Attribute class, and can be applied to methods, classes or assemblies.

Assembly version is described using Assembly attributes:

// Set version number for the assembly.
[assembly:AssemblyVersionAttribute("4.3.2.1")]

Classes can be decorated with attributes to denote special usage:

[TestClass]
public class MyTests 
{
    ..
}

Methods can be decorated using attributes:

[TestMethod]
public void MyFirstUnitTest() { .. }

Even parameters can be decorated using attributes.

33 questions
5
votes
3 answers

What's the difference between [Something] and [SomethingAttribute]

This has probably been already asked but it's hard to search for. What is the difference between [Something] and [SomethingAttribute]? Both of the following compile: [DefaultValue(false)] public bool Something { get; set;…
Pokechu22
  • 4,984
  • 9
  • 37
  • 62
4
votes
2 answers

How can we make sure that all NUnit [Test] methods are public?

We had a case of a missed/skipped test case today: The developer missed making the [Test] public and so NUnit (v 3.9.0) didn't didn't run it. [TestFixture] public class StackTests { [Test] public void Fail1() { Assert.Fail("Will…
Martin Ba
  • 37,187
  • 33
  • 183
  • 337
3
votes
2 answers

nameof in attribute

Considering Myatt attribute and MyObj class, it is somehow strange that ObjName property is known in scope of Myatt attribute. Isn't it? [AttributeUsage(AttributeTargets.Property)] public class MyAtt : Attribute { public MyAtt(string name) …
Saeed
  • 185
  • 2
  • 13
3
votes
4 answers

Name of a property as input to attribute constructor

I have a custom attribute and I would like it to have the name of a property as input. Because the name is a string it is a valid input type (as attributes are quite limited as to what they can have as input to their constructors). But how can I…
TheHvidsten
  • 4,028
  • 3
  • 29
  • 62
2
votes
1 answer

Understanding the use of 'Attributes'

I'm trying to understand the use of Attributes a bit better. I understand that: How to access Attributes in my code using reflection. How to create custom attributes How to specify explicitly an attribute target Now I wants to do some more with…
cse
  • 4,066
  • 2
  • 20
  • 37
2
votes
0 answers

How to invoke a Custom Attribute using reflection?

I have a method in which I am invoking methods of different classes at run time using reflection, code is below: var assembly = System.Reflection.Assembly.GetExecutingAssembly(); string[] assemblyInfo = assembly.FullName.Split(','); var…
BhushanK
  • 1,205
  • 6
  • 23
  • 39
1
vote
0 answers

PasswordPropertyText vs DataType(DataType.Password) attribute

What exactly is the difference between these two .NET attributes: [PasswordPropertyText] => PasswordPropertyTextAttribute [DataType(DataType.Password)] => DataTypeAttribute with a DataType Property of value DataType.Password Password property in…
1
vote
1 answer

Why does the JSON2CSharp online converter decorate each property with a [JsonProperty("...")] attribute?

I have this JSON response from an API: { "arguments": { "Configuration": { "Building_Configuration.Parameters_SP.fixtureStrategy_SP": "ETA", "Building_Configuration.Parameters_SP.dimensionSelection_SP":…
Jeff
  • 21
  • 7
1
vote
0 answers

Suppress implicit required attribute

Consider the following simple model: public class TestClass { [MyRequired(ErrorMessage = "Some error message")] public int TestVariable { get; set; } } This will implicitly add the [Required] attribute and the rendered html will contain…
DimChtz
  • 4,043
  • 2
  • 21
  • 39
1
vote
1 answer

Overriding permission required by AbpAuthorize attribute

I get the concept of Permissions, Roles and Authorization. But I can't get a grip of how the Authorization works when added in multiple places. Let me explain. I have an application service class with the…
1
vote
0 answers

F# What is this []?

I have come across something like this: [] several times and i have been wondering what is [] and what does it do? I would gladly read up on it but i can't since i have no clue what it…
Nulle
  • 1,301
  • 13
  • 28
0
votes
0 answers

.Net Attribute for Control with no display (like Timer)

What's the correct attribute to put on a Class for a control to indicate that there is nothing to display on the form, but that the control should only appear in the control box at the bottom of the designer? (Like Timer, for example)
Steve Mol
  • 142
  • 2
  • 8
0
votes
1 answer

Including read-only columns in an Entity Framework model

Suppose I have a .NET Entity Framework model class: public class Foo { public int FooId { get; set; } public string Description { get; set; } public DateTime Created { get; set; } public DateTime LastUpdated { get; set; } } The…
Green Grasso Holm
  • 468
  • 1
  • 4
  • 18
0
votes
1 answer

How to use a custom annotations validator POCO without any framework (no asp.net, no mvc, no ORM)

I have a custom validation class using System; using System.Collections.Generic; using System.Reflection; internal class RequiredAttribute1 : Attribute { public RequiredAttribute1() { } public void Validate(object o, MemberInfo…
heyNow
  • 866
  • 2
  • 19
  • 42
0
votes
1 answer

Extending AuditedAttribute to substitute or mask audited values

I am using ABP version 3.8.2. I have enabled ABP Audit Logging and it's working fine. Is there any way to substitute or mask Audit Log value with a different value in order to hide sensitive information like Password, Credit Card details, etc.?…