Get Enum from Description attribute [duplicate]

public static class EnumEx { public static T GetValueFromDescription<T>(string description) where T : Enum { foreach(var field in typeof(T).GetFields()) { if (Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) is DescriptionAttribute attribute) { if (attribute.Description == description) return (T)field.GetValue(null); } else { if (field.Name == description) return (T)field.GetValue(null); } } throw new ArgumentException(“Not found.”, nameof(description)); // Or return default(T); } } … Read more

When to use setAttribute vs .attribute= in JavaScript?

From Javascript: The Definitive Guide, it clarifies things. It notes that HTMLElement objects of a HTML doc define JS properties that correspond to all standard HTML attributes. So you only need to use setAttribute for non-standard attributes. Example: node.className=”test”; // works node.frameborder=”0″; // doesn’t work – non standard attribute node.setAttribute(‘frameborder’, ‘0’); // works

What are differences between AssemblyVersion, AssemblyFileVersion and AssemblyInformationalVersion?

AssemblyVersion Where other assemblies that reference your assembly will look. If this number changes, other assemblies must update their references to your assembly! Only update this version if it breaks backward compatibility. The AssemblyVersion is required. I use the format: major.minor (and major for very stable codebases). This would result in: [assembly: AssemblyVersion(“1.3”)] If you’re … Read more

Recursion, parsing xml file with attributes into treeview c#

You need to move the loop through attributes out of the loop through child nodes: private void AddNode(XmlNode inXmlNode, TreeNode inTreeNode) { // Loop through the XML nodes until the leaf is reached. // Add the nodes to the TreeView during the looping process. if (inXmlNode.HasChildNodes) { //Check if the XmlNode has attributes foreach (XmlAttribute … Read more

Extracting an attribute value with beautifulsoup

.find_all() returns list of all found elements, so: input_tag = soup.find_all(attrs={“name” : “stainfo”}) input_tag is a list (probably containing only one element). Depending on what you want exactly you either should do: output = input_tag[0][‘value’] or use .find() method which returns only one (first) found element: input_tag = soup.find(attrs={“name”: “stainfo”}) output = input_tag[‘value’]

Difference between text and innerHTML using Selenium

To start with, text is a property where as innerHTML is an attribute. Fundamentally there are some differences between a property and an attribute. get_attribute(“innerHTML”) get_attribute(innerHTML) gets the innerHTML of the element. This method will first try to return the value of a property with the given name. If a property with that name doesn’t … Read more