Пример #1
0
 public override string ConvertName(string name)
 {
     return(CaseConverter.PascalToSnake(name));
 }
Пример #2
0
    private static IEnumerable <EntityProperty> GetEntityProperties <T>(ParameterInfo parameterInfo)
    {
        var name           = parameterInfo.Name.EnsureNotNull($"Invalid paramter {parameterInfo}");
        var parameterType  = parameterInfo.ParameterType.EnsureNotNull($"Invalid paramter {parameterInfo}");
        var isRowkey       = parameterInfo.GetCustomAttribute(typeof(RowKeyAttribute)) != null;
        var isPartitionkey = parameterInfo.GetCustomAttribute(typeof(PartitionKeyAttribute)) != null;

        var discriminatorAttribute = typeof(T).GetProperty(name)?.GetCustomAttribute <TypeDiscrimnatorAttribute>();
        var defaultValueAttribute  = parameterInfo.GetCustomAttribute <DefaultValueAttribute>();


        (TypeDiscrimnatorAttribute, ITypeProvider)? discriminator = null;
        if (discriminatorAttribute != null)
        {
            var t = (ITypeProvider)(Activator.CreateInstance(discriminatorAttribute.ConverterType) ?? throw new Exception("unable to retrive the type provider"));
            discriminator = (discriminatorAttribute, t);
        }


        if (isPartitionkey)
        {
            yield return(new EntityProperty(name, "PartitionKey", parameterType, EntityPropertyKind.PartitionKey, discriminator, defaultValueAttribute, parameterInfo));
        }

        if (isRowkey)
        {
            yield return(new EntityProperty(name, "RowKey", parameterType, EntityPropertyKind.RowKey, discriminator, defaultValueAttribute, parameterInfo));
        }

        if (!isPartitionkey && !isRowkey)
        {
            var columnName = typeof(T).GetProperty(name)?.GetCustomAttribute <JsonPropertyNameAttribute>()?.Name ?? CaseConverter.PascalToSnake(name);
            yield return(new EntityProperty(name, columnName, parameterType, EntityPropertyKind.Column, discriminator, defaultValueAttribute, parameterInfo));
        }
    }