Create a delegate when there is a conditional attribute
You could try wrapping it in a lambda function: MyPCL.PCLDebug.LogLine = s => { System.Diagnostics.Debug.WriteLine( s ); };
You could try wrapping it in a lambda function: MyPCL.PCLDebug.LogLine = s => { System.Diagnostics.Debug.WriteLine( s ); };
Prior to VS2013 you could use: [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] so that it doesn’t show up in IntelliSense. If the consumer still wants to use it they can, but it won’t be as discoverable. Keith’s point about over-engineering still stands though. Since VS2013 this feature has been removed. As noted in https://github.com/dotnet/roslyn/issues/37478 this was “by design” and apparently … Read more
Here is my solution. I’ve added resourceName and resourceType properties to attribute, like microsoft has done in DataAnnotations. public class CustomAttribute : Attribute { public CustomAttribute(Type resourceType, string resourceName) { Message = ResourceHelper.GetResourceLookup(resourceType, resourceName); } public string Message { get; set; } } public class ResourceHelper { public static string GetResourceLookup(Type resourceType, string resourceName) { … Read more
You don’t have to reset hard (if I understand correctly what you’re doing). My case is similiar. I added a .gitattributes in a running project. I need the files I have and the files in online repo to be ruled by gitattr. # This will force git to recheck and “reapply” gitattributes changes. git rm … Read more
I assume you’re using MySQL 5.7, which adds the JSON data type. Use JSON_EXTRACT(colname, ‘$.cost’) to access the cost property. It will be NULL is there’s no such property. WHERE JSON_EXTRACT(colname, ‘$.cost’) IS NOT NULL WHERE JSON_EXTRACT(colname, ‘$.cost’) IS NULL WHERE JSON_EXTRACT(colname, ‘$.cost’) != ” It will also be NULL if the value in the … Read more
The requirement is only by standards. It is perfectly possible to do whatever you want on a page and not follow standards. Things may not display or work correctly if you do that, but likely they will. The goal is to follow them, and the idea is that if you follow them, your page will … Read more
Typically, Python code strives to adhere to the Uniform Access Principle. Specifically, the accepted approach is: Expose your instance variables directly, allowing, for instance, foo.x = 0, not foo.set_x(0) If you need to wrap the accesses inside methods, for whatever reason, use @property, which preserves the access semantics. That is, foo.x = 0 now invokes … Read more
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
Terminology Mental model: A variable stored in an instance or class is called an attribute. A function stored in an instance or class is called a method. According to Python’s glossary: attribute: A value associated with an object which is referenced by name using dotted expressions. For example, if an object o has an attribute … Read more
Here’s a helper method that should point you in the right direction. protected Als GetEnumByStringValueAttribute(string value) { Type enumType = typeof(Als); foreach (Enum val in Enum.GetValues(enumType)) { FieldInfo fi = enumType.GetField(val.ToString()); StringValueAttribute[] attributes = (StringValueAttribute[])fi.GetCustomAttributes( typeof(StringValueAttribute), false); StringValueAttribute attr = attributes[0]; if (attr.Value == value) { return (Als)val; } } throw new ArgumentException(“The value ‘” … Read more