singollo

Untitled

May 16th, 2018
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. private IEnumerable<ApiEndpoint> apiEndpoints()
  2.         {
  3.             var fieldInfos = GetType().GetFields(BindingFlags.Public |
  4.                                                  BindingFlags.Static | BindingFlags.FlattenHierarchy);
  5.  
  6.             var fields = fieldInfos.Where(fi => fi.FieldType == typeof(ApiEndpoint)).ToList();
  7.             var result = new List<ApiEndpoint>();
  8.             foreach (var field in fields)
  9.             {
  10. //                var val = this.GetType().InvokeMember(field.Name, BindingFlags.GetField, null, this, null);
  11.                 var val = field.GetValue(this);
  12.                 if (val.GetType() == typeof(ApiEndpoint))
  13.                 {
  14.                     result.Add(val); // tutaj nie zadziała, bo GetValue() zwróciło typ Object
  15.                 }
  16. //                result.Add(field.GetValue(field));
  17.             }
  18.             return result;
Advertisement
Add Comment
Please, Sign In to add comment