12345678910111213141516171819202122232425262728 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- namespace FormulaEnginePoC.FormulaEngine.Mapping
- {
- internal class TypeMapping
- {
- private readonly PropertyMapping[] _props;
- private readonly Dictionary<string, PropertyMapping> _nameDictionary;
- public PropertyMapping[] Properties => _props.ToArray();
- public TypeMapping(Type dataType)
- {
- var propertyInfos = dataType.GetProperties(BindingFlags.Instance | BindingFlags.Public).Where(p => p.CanRead).ToArray();
- _props = propertyInfos.Select(p => new PropertyMapping(p)).ToArray();
- _nameDictionary = _props.ToDictionary(p => p.Display);
- }
- public bool TryGetProperty(string display, out PropertyMapping mapping)
- {
- return _nameDictionary.TryGetValue(display, out mapping);
- }
- }
- }
|