Inheritance of Custom Attributes on Abstract Properties

Instead of calling PropertyInfo.GetCustomAttributes(…), you have to call the static method System.Attribute.GetCustomAttributes(pi,…), as in: PropertyInfo info = GetType().GetProperties(); // this gets only the attributes in the derived class and ignores the ‘true’ parameter object[] DerivedAttributes = info.GetCustomAttributes(typeof(MyAttribute),true); // this gets all of the attributes up the heirarchy object[] InheritedAttributes = System.Attribute.GetCustomAttributes(info,typeof(MyAttribute),true);

NewtonSoft add JSONIGNORE at runTime

No need to do the complicated stuff explained in the other answer. NewtonSoft JSON has a built-in feature for that: public bool ShouldSerializeINSERT_YOUR_PROPERTY_NAME_HERE() { if(someCondition){ return true; }else{ return false; } } It is called “conditional property serialization” and the documentation can be found here. Warning: first of all, it is important to get rid … Read more

__attribute__((const)) vs __attribute__((pure)) in GNU C

From the documentation for the ARM compiler (which is based on gcc): __attribute__((pure)) function attribute Many functions have no effects except to return a value, and their return value depends only on the parameters and global variables. Functions of this kind can be subject to data flow analysis and might be eliminated. __attribute__((const)) function attribute … Read more

Add and remove attribute with jquery

It’s because you’ve removed the id which is how you’re finding the element. This line of code is trying to add id=”page_navigation1″ to an element with the id named page_navigation1, but it doesn’t exist (because you deleted the attribute): $(“#page_navigation1”).attr(“id”,”page_navigation1″); Demo: If you want to add and remove a class that makes your <div> red … Read more

Can C# Attributes access the Target Class?

There are cases where you can’t rely on the calling code to pass a type reference. Below is a solution I cooked up to solve this problem. It’s a bit of a shot-gun approach, but it does work… using System; using System.Reflection; using System.Collections.Generic; using System.Linq; using System.Diagnostics; namespace Ethica.Reflection { /// <summary> /// Helps … Read more

What are the similarities and differences between Java Annotations and C# Attributes?

Control over when your metadata is made accessible is different between the two languages. Java provides the java.lang.annotation.Retention annotation and java.lang.annotation.RetentionPolicy enum to control when annotation metadata is accessible. The choices vary from Runtime (most common – annotation metadata retained in class files), to Source (metadata discarded by compiler). You tag your custom annotation interface … Read more

What is XHTML role attribute? What do you use it for?

The Short Version: The Role Attribute may give future browsers a way to work intelligently with certain XML elements in a device-independent way. For example, an unordered list that is marked with the role attribute of “navigation” can be interpreted intelligently on browsers in both desktop and handheld environments, allowing it to be displayed clearly … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)