Lambda expression in attribute constructor

Having a generic attribute is not possible in a conventional way. However C# and VB don’t support it but the CLR does. If you want to write some IL code it’s possible. Let’s take your code: [AttributeUsage(AttributeTargets.Property)] public class RelatedPropertyAttribute: Attribute { public string RelatedProperty { get; private set; } public RelatedPropertyAttribute(string relatedProperty) { RelatedProperty … Read more

How to declare a static attribute in Python?

All variables defined on the class level in Python are considered static class Example: Variable = 2 # static variable print Example.Variable # prints 2 (static variable) # Access through an instance instance = Example() print instance.Variable # still 2 (ordinary variable) # Change within an instance instance.Variable = 3 #(ordinary variable) print instance.Variable # … Read more

How to set multiple attributes with one value function?

UPDATE (July 8th 2016) This answer applies to d3 v3.x — NOT v4.x. For the latter version, see Tim Hayes’s answer, also on this page. Or… just swap attr with attrs in my answer below, and don’t forget to require/import/script-embed d3-selection-multi. And… don’t miss the bit about using .each, which may be useful to you. … Read more

Passing array via attribute to AngularJS directive

If you’re accessing this array from your scope, i.e. loaded in a controller, you can just pass the name of the variable: Binding array to directive variable in AngularJS Directive: scope:{ title: “@”, author: “@”, content: “@”, cover: “@”, date: “@”, tags: “=” }, Template: <post title=”sample title” tags=”arrayName” … >

How to use an Exception’s attributes in Python?

Use the as statement. You can read more about this in Handling Exceptions. >>> try: … print(a) … except NameError as e: … print(dir(e)) # print attributes of e … [‘__cause__’, ‘__class__’, ‘__context__’, ‘__delattr__’, ‘__dict__’, ‘__doc__’, ‘__eq__’, ‘__format__’, ‘__ge__’, ‘__getattribute__’, ‘__gt__’, ‘__hash__’, ‘__init__’, ‘__le__’, ‘__lt__’, ‘__ne__’, ‘__new__’, ‘__reduce__’, ‘__reduce_ex__’, ‘__repr__’, ‘__setattr__’, ‘__setstate__’, ‘__sizeof__’, ‘__str__’, ‘__subclasshook__’, … Read more

How best to use File Version and Assembly Version?

In solutions with multiple projects, one thing I’ve found very helpful is to have all the AssemblyInfo files point to a single project that governs the versioning. So my AssemblyInfos have a line: [assembly: AssemblyVersion(Foo.StaticVersion.Bar)] I have a project with a single file that declares the string: namespace Foo { public static class StaticVersion { … Read more

.NET DefaultValue attribute

The place where I typically used DefaultValue is for classes which are serialized/deserialized to XML. It does not set the default value during instantiation and doesn’t impact autoproperties. From MSDN: A DefaultValueAttribute will not cause a member to be automatically initialized with the attribute’s value. You must set the initial value in your code. MSDN … Read more

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