get the value of DisplayName attribute

Try these utility methods of mine: using System.ComponentModel; using System.Globalization; using System.Linq; public static T GetAttribute<T>(this MemberInfo member, bool isRequired) where T : Attribute { var attribute = member.GetCustomAttributes(typeof(T), false).SingleOrDefault(); if (attribute == null && isRequired) { throw new ArgumentException( string.Format( CultureInfo.InvariantCulture, “The {0} attribute must be defined on member {1}”, typeof(T).Name, member.Name)); } return … Read more

hasattr() vs try-except block to deal with non-existent attributes

Any benches that illustrate difference in performance? timeit it’s your friend $ python -mtimeit -s ‘class C(object): a = 4 c = C()’ ‘hasattr(c, “nonexistent”)’ 1000000 loops, best of 3: 1.87 usec per loop $ python -mtimeit -s ‘class C(object): a = 4 c = C()’ ‘hasattr(c, “a”)’ 1000000 loops, best of 3: 0.446 usec … Read more

Can’t set attributes on instance of “object” class

To support arbitrary attribute assignment, an object needs a __dict__: a dict associated with the object, where arbitrary attributes can be stored. Otherwise, there’s nowhere to put new attributes. An instance of object does not carry around a __dict__ — if it did, before the horrible circular dependence problem (since dict, like most everything else, … Read more

Type hinting for properties in PHP 7?

PHP 7.4 will support typed properties like so: class Person { public string $name; public DateTimeImmutable $dateOfBirth; } PHP 7.3 and earlier do not support this, but there are some alternatives. You can make a private property which is accessible only through getters and setters which have type declarations: class Person { private $name; public … Read more

JavaScript: Listen for attribute change?

You need MutationObserver, Here in snippet I have used setTimeout to simulate modifying attribute var element = document.querySelector(‘#test’); setTimeout(function() { element.setAttribute(‘data-text’, ‘whatever’); }, 5000) var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { if (mutation.type === “attributes”) { console.log(“attributes changed”) } }); }); observer.observe(element, { attributes: true //configure it to listen to attribute changes }); <div … Read more

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