Get Value of a Custom Attribute

Access to the value of a Custom Attribute

var attribute =
(MethodTestingAttibute)
typeof (Vehicles)
.GetMethod("m1")
.GetCustomAttributes(typeof (MethodTestingAttibute), false).First();
Console.WriteLine(attribute.Value);

Get value of a custom attribute

Adding custom attributes makes your HTML invalid. Use custom data attributes instead:

<strong id="the_id" data-original-title="I NEED THIS">
$('#the_id').data('original-title')

https://jsbin.com/akoyut/2/edit

Get custom attribute value in Jquery?

Because you're alerting the result of .val() (and I'm not sure why you're using it) which is a jQuery object - you simply want the attribute:

var text = $(this).attr("data-overlay")
alert(text);

Read value of custom attributes

It seems your only issue is retrieving PropertyInfos those annotated by [Custom(Export = true)]. You can achieve that this way:

var exportedProps = type_info.GetProperties()
.Where(p => p.PropertyType.GetCustomAttribute<CustomAttribute>()?.Export == true)

Get custom attribute value

Microsoft.FxCop.Sdk.AttributeNode cannot be cast to a normal System.Attribute, System.Reflection.CustomAttributeData, or anything else that I tried. Finally, I could get the value I was looking for using the following function:

public Microsoft.FxCop.Sdk.Expression GetPositionalArgument(int position)

Get value of custom attribute

Remove the context of your selector:

http://jsfiddle.net/NrQek/1/

 var userType = $("input[name=ctrl_CustomerType]:checked").attr('xmlvalue');
alert("xmlvalue is: " + userType);

C# get property value from object using custom attribute

In your example, you're getting the customattributes of the class instead of the properties.

Here is an example:

private object GetValueBySectionFlag(object obj, string flagName)
{
// get the type:
var objType = obj.GetType();

// iterate the properties
var prop = (from property in objType.GetProperties()
// iterate it's attributes
from attrib in property.GetCustomAttributes(typeof(SectionFlagAttribute), false).Cast<SectionFlagAttribute>()
// filter on the name
where attrib.Name == flagName
// select the propertyInfo
select property).FirstOrDefault();

// use the propertyinfo to get the instance->property value
return prop?.GetValue(obj);
}

Note: this will return only the first property which contains the SectionFlagAttribute with the right name. You could modify the method to return multiple values. (like a collection of propertyname/value)


Usage:

// a test instance.
var obj = new ApplicationStatusFlags { IceAttributeStatement = true };

// get the value by SectionFlag name
var iceAttributeStatement = GetValueBySectionFlag(obj, "APPLICANTSTATEMENT");

If the returned value is null then the flag is not found or the property's value is null.

C# .NET CORE how to get the value of a custom attribute?

Add using System.Reflection and then you may use extension methods from CustomAttributeExtensions.cs.

Something like this should work for you:

typeof(<class name>).GetTypeInfo()
.GetProperty(<property name>).GetCustomAttribute<YourAttribute>();

in your case

typeof(KeyVaultConfiguration).GetTypeInfo()
.GetProperty("AuthClientId").GetCustomAttribute<EncryptedAttribute>();

angular2 getting value of custom attribute

There is the getAttribute(...) method for that on elements:

currentField.getAttribute('field')

See also getAttribute() versus Element object properties?



Related Topics



Leave a reply



Submit