Example #1
0
        IWriteProperty <T, TProperty> GetWriteProperty <TProperty>(string name)
        {
            lock (_properties)
            {
                if (_properties.TryGetValue(name, out IWriteProperty <T> property))
                {
                    return(property as IWriteProperty <T, TProperty>);
                }

                if (_propertyIndex.TryGetValue(name, out var propertyInfo))
                {
                    if (propertyInfo.PropertyType != typeof(TProperty))
                    {
                        throw new ArgumentException(
                                  $"Property type mismatch, {TypeMetadataCache<TProperty>.ShortName} != {TypeMetadataCache.GetShortName(propertyInfo.PropertyType)}");
                    }

                    var writeProperty = new WriteProperty <T, TProperty>(_implementationType, propertyInfo);

                    _properties[name] = writeProperty;

                    return(writeProperty);
                }
            }

            throw new ArgumentException($"{TypeMetadataCache<T>.ShortName} does not contain the property: {name}", nameof(name));
        }
Example #2
0
        IWriteProperty <T, TProperty> IWritePropertyCache <T> .GetProperty <TProperty>(string name)
        {
            lock (_properties)
            {
                if (_properties.TryGetValue(name, out var property))
                {
                    return(property as IWriteProperty <T, TProperty>);
                }

                var writeProperty = new WriteProperty <T, TProperty>(_implementationType, name);

                _properties[name] = writeProperty;

                return(writeProperty);
            }
        }
Example #3
0
        IWriteProperty <T, TProperty> IWritePropertyCache <T> .GetProperty <TProperty>(PropertyInfo propertyInfo)
        {
            lock (_properties)
            {
                var name = propertyInfo?.Name ?? throw new ArgumentNullException(nameof(propertyInfo));

                if (_properties.TryGetValue(name, out var property))
                {
                    return(property as IWriteProperty <T, TProperty>);
                }

                var writeProperty = new WriteProperty <T, TProperty>(_implementationType, propertyInfo);

                _properties[name] = writeProperty;

                return(writeProperty);
            }
        }