コード例 #1
0
        static Mapping()
        {
            var type       = typeof(RisRecord);
            var properties = type.GetProperties();

            foreach (var property in properties)
            {
                var attributes = property.GetCustomAttributes(false);
                foreach (var attribute in attributes)
                {
                    if (attribute is FieldAttribute fieldAttribute)
                    {
                        var tags = fieldAttribute.Tag.Split(',').Select(x => x.Trim());
                        foreach (var tag in tags)
                        {
                            var converter = _converters.GetOrAdd(fieldAttribute.ConverterType,
                                                                 (t) => (IFieldConverter)Activator.CreateInstance(fieldAttribute.ConverterType));

                            var propertyContext = new PropertyContext(property, tag, converter);
                            _propertiesContexts.GetOrAdd(property.Name, (k) => propertyContext);
                            _tagMappings.AddOrUpdate(tag, (k) => propertyContext, (k, s) => propertyContext);
                        }
                    }
                }
            }
        }
コード例 #2
0
        public static bool TryGetPropertyContext(string tag, out PropertyContext propertyMapping)
        {
            if (string.IsNullOrEmpty(tag))
            {
                throw new ArgumentNullException(nameof(tag));
            }

            return(_tagMappings.TryGetValue(tag, out propertyMapping));
        }
コード例 #3
0
        public static bool TryGetPropertyContext(PropertyInfo property, out PropertyContext propertyMapping)
        {
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            return(_propertiesContexts.TryGetValue(property.Name, out propertyMapping));
        }