Questions tagged [getcustomattributes]

21 questions
21
votes
2 answers

Why does ICustomAttributeProvider.GetCustomAttributes() return object[] instead of Attribute[]?

Why does ICustomAttributeProvider.GetCustomAttributes() return object[] instead of Attribute[]? Is there any circumstance when using the ICustomAttributeProvider implementations from mscorlib and System assemblies will return objects that are not of…
smartcaveman
  • 41,281
  • 29
  • 127
  • 212
19
votes
1 answer

How do I GetCustomAttributes?

I have tried the following code using the 2.0 framework and I get an attribute back, but when I try this on the compact framework, it always returns an empty array. The MSDN documenation says its supported, am I doing something wrong? Test x =…
SwDevMan81
  • 48,814
  • 22
  • 151
  • 184
6
votes
1 answer

Getting attribute from overridden property via a linq Expression

I'm trying to use GetCustomAttributes() to get an attribute defined on a property. The issue is that the property is an overridden one and I can't work out how to extract the overridden one from the expression. I can only work out how to get the…
Jero
  • 1,081
  • 1
  • 8
  • 11
5
votes
1 answer

Custom Attributes such as Displayname not listed with GetCustomAttribute

I have some code to define custom attributes and then to read in the code, it fails to work. To try and fix the problem I have gone back and tried to use DisplayName, however , I am still having the same issue GetCustomAttribute or…
user427165
5
votes
2 answers

In .Net, why aren't attributes declared on interfaces returned when calling Type.GetCustomAttributes(true)?

In answer to this question I tried to use Type.GetCustomAttributes(true) on a class which implements an interface which has an Attribute defined on it. I was surprised to discover that GetCustomAttributes didn't return the attribute defined on the…
Wesley Wiser
  • 9,491
  • 4
  • 50
  • 69
4
votes
2 answers

Bizarre behavior with custom attributes and GetCustomAttributes

I've been fighting this problem for hours and I could not find anything related on SO (or google for that matter). Here's my problem: I have a custom attribute that contains an object array…
victor
  • 1,532
  • 1
  • 13
  • 32
4
votes
1 answer

Why is MemberInfo.GetCustomAttributes(Type) defined to return an array of attributes?

public enum Animal { [Description("King of jungle")] Lion= 1, [Description("Tallest there")] Giraffe = 2 } Suppose I have the FieldInfo, I can go about it two ways: //static one on 'Attribute' class Attribute attribute =…
nawfal
  • 70,104
  • 56
  • 326
  • 368
3
votes
3 answers

Unity Interception GetCustomAttribute

Thanks in advance for your help! (Yes, there's a question at the bottom) I'm using Unity 3.x Interception to perform AOP pre and post database connection and transaction activities. The database interceptor is always instantiated and the…
Werewolf
  • 472
  • 3
  • 11
2
votes
0 answers

mvc getting attributes for derived model

I have 1 base model, a child model and another which is a child of the second one: class FirstModel { public virtual decimal? Property1 { get; set; } } class SecondModel : FirstModel { public override decimal? Property1 { get; set;…
2
votes
2 answers

VB.net Values of Custom Attributes

I'm new to custom attributes, so I'm wondering if it is possible to get the values of the attributes. An example of the properties in my class which I use the custom attributes is: Private mFiller As String
bornbnid
  • 383
  • 4
  • 9
1
vote
1 answer

How to update woocommerce sale price with custom product attribute value?

I'm trying to update the meta "Sale price" with the custom product attribute "value" named "Cost_price" for every product (simple & variable). This custom product attribute is API connected with other site and It will change the value (price) once a…
Milan M
  • 45
  • 5
1
vote
0 answers

Why do I get "'CustomAttributes' is not a member of 'PropertyInfo'"

I am using reflection to get some property values. The code (appears to) work as intended, but Visual Studio reports error BC30456 'CustomAttributes' is not a member of 'PropertyInfo'. The first time I wrote the code it compiled cleanly; at some…
1
vote
1 answer

VB.net (.NET 3.5) Custom Attribute and Type.GetCustomAttribute() always 1

How should I be a) defining Custom Attributes and b) getting the said custom attribute assignment in the following scenario? Scenario: We would like to define a custom attribute (custAtrib1) to be used by inherited class (myClassFoo of a base class…
MonkeyPen
  • 23
  • 4
1
vote
1 answer

C# - Silverlight - CustomAttribute with Enum

I have the following class: [MetadataAttribute] [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)] public class ModuleActivationButtonAttribute : ExportAttribute { public Enum TargetRegion { get; set; } public…
cmaduro
  • 1,672
  • 3
  • 21
  • 40
1
vote
1 answer

System.Type.GetCustomAttributes on an assembly loaded from a network share is not showing all attributes

I have a managed dll – repro.dll, which contains class TestModuleCommand decorated with 2 attributes: System.ObsoleteAttribute and System.Management.Automation.CmdletAttribute (comes from System.Management.Automation.dll which is in the GAC in…
1
2