public static string GetEnumAttributeValue(Enum enumValue, Type attributeType, string attributePropertyName)
{
/*
* Extracts a given attribute value from an enum:
*
* Ex:
* public enum X
* {
[MyAttribute(myProp = "aaaa")]
* x1,
* x2,
* [Description("desc")]
* x3
* }
*
* Usage:
* GetEnumAttribute(X.x1, typeof(MyAttribute), "myProp") returns "aaaa"
* GetEnumAttribute(X.x2, typeof(MyAttribute), "myProp") returns string.Empty
* GetEnumAttribute(X.x3, typeof(DescriptionAttribute), "Description") returns "desc"
*/
var attributeObj = enumValue.GetType()?.GetMember(enumValue.ToString())?.FirstOrDefault()?.GetCustomAttributes(attributeType, false)?.FirstOrDefault();
if (attributeObj == null)
return string.Empty;
else
{
try
{
var attributeCastedObj = Convert.ChangeType(attributeObj, attributeType);
var attributePropertyValue = attributeType.GetProperty(attributePropertyName)?.GetValue(attributeCastedObj);
return attributePropertyValue?.ToString() ?? string.Empty;
}
catch (Exception ex)
{
return string.Empty;
}
}
}
Keeping track of interesting places I put my feet on in the software development world.
Search This Blog
Tuesday, September 24, 2019
Monday, August 26, 2019
Monday, August 12, 2019
Monday, August 5, 2019
Wednesday, June 26, 2019
Get Date Out of an Elastic Timestamp
I am not sure, but I think the answer to the question on how to get a date out of an elastic timestamp,
can be using the Current Epoch Timestamp To Date
converter in this site.
can be using the Current Epoch Timestamp To Date
converter in this site.
Monday, June 24, 2019
Print call stack in javascript
From https://til.hashrocket.com/posts/478143b559-print-call-stack-on-javascript
Print call stack on Javascript
If you want to print the javascript **call stack** you can use:
```javascript
console.log(new Error().stack);
```
Here it is an **example**:
```javascript
function firstFunction() {
secondFunction();
}
function secondFunction() {
thridFunction();
}
function thridFunction() {
console.log(new Error().stack);
}
firstFunction();
//=> Error
// at thridFunction (<anonymous>:2:17)
// at secondFunction (<anonymous>:5:5)
// at firstFunction (<anonymous>:8:5)
// at <anonymous>:10:1
```
h/t @rondale_sc
viniciusnegrisolo
June 10, 2016
Tuesday, June 11, 2019
Increasing maximum allowed post body content size in .NET Web Api
This SO answer did the job.
I used int.MaxValue instead.
Subscribe to:
Posts (Atom)