This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DiagramOptions | |
{ | |
[Description("Key code for deleting entities")] | |
public string DeleteKey { get; set; } = "Delete"; | |
[Description("Whether to inverse the zoom direction or not")] | |
public bool InverseZoom { get; set; } | |
[Description("The default component for nodes")] | |
public Type? DefaultNodeComponent { get; set; } | |
[Description("The grid size (grid-based snaping")] | |
public int? GridSize { get; set; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class ReflectionUtils | |
{ | |
public static IEnumerable<PossibleOption> ExtractPossibleOptions<T>() | |
{ | |
var type = typeof(T); | |
return ExtractPossibleOptions(type, string.Empty, Activator.CreateInstance(type)); | |
} | |
private static IEnumerable<PossibleOption> ExtractPossibleOptions(Type type, string prefix, object instance) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PossibleOption | |
{ | |
public string Name { get; } | |
public string Type { get; } | |
public string Default { get; } | |
public string Description { get; } | |
public PossibleOption(string name, string type, string @default, string description) | |
{ | |
Name = name; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="table-responsive"> | |
<table class="table"> | |
<thead> | |
<tr> | |
<th>Name</th> | |
<th>Type</th> | |
<th>Default</th> | |
<th>Description</th> | |
</tr> | |
</thead> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ListProductsRequest | |
{ | |
public string CategoryId { get; set; } | |
public int? Page { get; set; } | |
public int? Size { get; set; } | |
public string Filter { get; set; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"name": "categoryId", | |
"value": "qgq65s1d6qs5d1g" | |
}, | |
{ | |
"name": "page", | |
"value": 1 | |
}, | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var instance = new ListProductsRequest | |
{ | |
CategoryId = "qdfg3514sqdf65", | |
Page = 1, | |
Size = 10, | |
Filter = "price>10" | |
}; | |
var value = instance.CategoryId; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object instance = new ListProductsRequest | |
{ | |
CategoryId = "qdfg3514sqdf65", | |
Page = 1, | |
Size = 10, | |
Filter = "price>10" | |
}; | |
var value = (instance as ListProductsRequest).CategoryId; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public string GetCategoryId(object instance) | |
=> (instance as ListProductsRequest).CategoryId; | |
// Or as a lambda expression (which will help us more) | |
Func<object, string> getCategoryId = (instance) => (instance as ListProductsRequest).CategoryId; | |
// We can also generalize it | |
Func<object, object> getCategoryId = (instance) => (object)((instance as ListProductsRequest).CategoryId); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static Func<object, object> GenerateGetterLambda(PropertyInfo property) | |
{ | |
// Define our instance parameter, which will be the input of the Func | |
var objParameterExpr = Expression.Parameter(typeof(object), "instance"); | |
// 1. Cast the instance to the correct type | |
var instanceExpr = Expression.TypeAs(objParameterExpr, property.DeclaringType); | |
// 2. Call the getter and retrieve the value of the property | |
var propertyExpr = Expression.Property(instanceExpr, property); | |
// 3. Convert the property's value to object | |
var propertyObjExpr = Expression.Convert(propertyExpr, typeof(object)); |