Пример #1
0
        private InheritanceDiscriminatorConfiguration Add(Type baseType, PropertyInfo propertyInfo, Type[] subTypes, bool addStaticTypeProperty)
        {
            TryGetDiscriminatorValue(baseType, propertyInfo, out var rootValue);
            var subTypesAndDiscriminator = new SubTypesAndDiscriminator(propertyInfo, rootValue, addStaticTypeProperty);

            foreach (var subType in subTypes.Where(x => x != baseType && baseType.IsAssignableFrom(x)))
            {
                if (TryGetDiscriminatorValue(subType, propertyInfo, out var discriminatorValue))
                {
                    if (subTypesAndDiscriminator.SubTypesWithDiscriminatorValue.Values.Contains(discriminatorValue))
                    {
                        throw new ArgumentException(
                                  $"DiscriminatorValue already exists: type: {subType}, value: {discriminatorValue}");
                    }

                    subTypesAndDiscriminator.SubTypesWithDiscriminatorValue.Add(subType, discriminatorValue);
                }
                Add(subType, propertyInfo, subTypes, addStaticTypeProperty);
            }

            _config.Add(baseType, subTypesAndDiscriminator);
            return(this);
        }
Пример #2
0
 public bool TryGetValue(Type type, out SubTypesAndDiscriminator result)
 => _config.TryGetValue(type, out result);