Define an ‘s src attribute in CSS [duplicate]
just this as img tag is a content element img { content:url(http://example.com/image.png); }
just this as img tag is a content element img { content:url(http://example.com/image.png); }
Try hasattr(): if hasattr(a, ‘property’): a.property See zweiterlinde’s answer below, who offers good advice about asking forgiveness! A very pythonic approach! The general practice in python is that, if the property is likely to be there most of the time, simply call it and either let the exception propagate, or trap it with a try/except … Read more
This really depends on what exactly you’re trying to accomplish. The System.ComponentModel.TypeDescriptor stuff can be used to add attributes to types, properties and object instances, and it has the limitation that you have to use it to retrieve those properties as well. If you’re writing the code that consumes those attributes, and you can live … Read more
There is a significant semantic difference (beyond performance considerations): when the attribute is defined on the instance (which is what we usually do), there can be multiple objects referred to. Each gets a totally separate version of that attribute. when the attribute is defined on the class, there is only one underlying object referred to, … Read more
Actually, if you’re working with jQuery, as of version 1.4.3 1.4.4 (because of the bug as mentioned in the comments below), data-* attributes are supported through .data(): As of jQuery 1.4.3 HTML 5 data- attributes will be automatically pulled in to jQuery’s data object. Note that strings are left intact while JavaScript values are converted … Read more
This is more of an xpath question, but like this, assuming the context is the parent element: <xsl:value-of select=”name/@attribute1″ />
In .NET 4 there is a new method Enum.HasFlag. This allows you to write: if ( testItem.HasFlag( FlagTest.Flag1 ) ) { // Do Stuff } which is much more readable, IMO. The .NET source indicates that this performs the same logic as the accepted answer: public Boolean HasFlag(Enum flag) { if (!this.GetType().IsEquivalentTo(flag.GetType())) { throw new … Read more
This is a CLR restriction. Only primitive constants or arrays of primitives can be used as attribute parameters. The reason why is that an attribute must be encoded entirely in metadata. This is different than a method body which is coded in IL. Using MetaData only severely restricts the scope of values that can be … Read more
We’re using a global file called GlobalAssemblyInfo.cs and a local one called AssemblyInfo.cs. The global file contains the following attributes: [assembly: AssemblyProduct(“Your Product Name”)] [assembly: AssemblyCompany(“Your Company”)] [assembly: AssemblyCopyright(“Copyright © 2008 …”)] [assembly: AssemblyTrademark(“Your Trademark – if applicable”)] #if DEBUG [assembly: AssemblyConfiguration(“Debug”)] #else [assembly: AssemblyConfiguration(“Release”)] #endif [assembly: AssemblyVersion(“This is set by build process”)] [assembly: AssemblyFileVersion(“This … Read more
Yes, absolutely. Using Reflection: static IEnumerable<Type> GetTypesWithHelpAttribute(Assembly assembly) { foreach(Type type in assembly.GetTypes()) { if (type.GetCustomAttributes(typeof(HelpAttribute), true).Length > 0) { yield return type; } } }