private static DnPropriedadeJsonAtributo GetDnJsonPropertyAttributeByProperty(PropertyInfo property) { var attr = property.GetCustomAttribute <DnPropriedadeJsonAtributo>(true); if (attr == null) { attr = new DnPropriedadeJsonAtributo { Descricao = property.GetCustomAttribute <DescriptionAttribute>(true)?.Description ?? property.Name, Grupo = "", Nome = property.Name, NomeDaPropriedade = property.Name.ToDnJsonStringNormalized(), Tipo = property.PropertyType, Propriedade = property, Enumeradores = null, DestinoDeChaveExterna = null, Agregacao = null, Composicao = null, Formulario = EnumTipoDeComponenteDeFormularioDeTela.Texto, Grid = property.Name, EhEnumerador = property.PropertyType.IsNullableEnum(), EhChaveExterna = false, EhChave = false, EhDnChaveUnica = false, EhLista = property.PropertyType.IsList(), PermiteNulo = property.PropertyType.IsOfNullableType(), Minimo = property.GetCustomAttribute <MinLengthAttribute>(true)?.Length ?? 0, Maximo = property.GetCustomAttribute <MaxLengthAttribute>(true)?.Length ?? 0 }; } attr.OperacaoDeCondicional = property.GetCustomAttributes <DnOperacaoDeCondicionalDeTelaAtributo>(); attr.Agregacao = property.GetCustomAttribute <DnAgregacaoDeMuitosParaMuitosAtributo>(true) ?? property.GetCustomAttribute <DnAgregacaoAtributo>(true); attr.Composicao = property.GetCustomAttribute <DnComposicaoAtributo>(true); attr.EhChave = property.IsDefined(typeof(KeyAttribute)); attr.EhDnChaveUnica = property.IsDefined(typeof(DnChaveUnicaAtributo)); attr.EhLista = property.PropertyType.IsList(); attr.EhRequerido = attr.EhRequerido || property.IsDefined(typeof(RequiredAttribute), true); attr.PermiteNulo = (property.PropertyType.IsOfNullableType() && !attr.EhRequerido); attr.Tipo = property.PropertyType.GetNonNullableType(); attr.Propriedade = property; if (attr.Maximo == 0 && property.PropertyType.EhNumerico()) { attr.Maximo = property.PropertyType.GetMaxValueOfNumber().DnCast <double>(); } if (property.IsDefined(typeof(JsonIgnoreAttribute))) { attr.Formulario = EnumTipoDeComponenteDeFormularioDeTela.Nenhum; } return(attr); }
private static void Comment(DnPropriedadeJsonAtributo property, IXLCell headerCell) { var isKeyComment = property.EhChave || property.EhDnChaveUnica ? $"\nIs Key" : ""; var isPkComment = property.EhChaveExterna ? $"\nIs Fk" : ""; var isRequiredComment = property.EhRequerido ? $"\nIs EhRequerido" : ""; var isListComment = property.EhLista ? $"\nIs list" : ""; var isEnumComment = property.EhEnumerador ? $"\nIs enum" : ""; var enumValues = property.EhEnumerador ? "\nValues: " + string.Join(", ", property.Enumeradores.Select(x => $"{x.Key} = {x.Value}")) : ""; var comment = property.Minimo == 0 && property.Maximo == 0 ? "" : $"{property.Nome}\nMin: {property.Minimo}, TamanhoMaximo: {property.Maximo}{isKeyComment}{isPkComment}{isRequiredComment}{isListComment}{isEnumComment}{enumValues}"; headerCell.Comment.AddText(comment); }
private static void Style(DnPropriedadeJsonAtributo property, IXLCell headerCell) { headerCell.Style.Font.FontSize = 11; headerCell.Style.Protection.Locked = true; headerCell.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; headerCell.Style.Fill.BackgroundColor = XLColor.FromArgb(0xF8F8F8); headerCell.Style.Font.FontColor = XLColor.Black; headerCell.Style.Border.TopBorder = XLBorderStyleValues.Medium; headerCell.Style.Border.RightBorder = XLBorderStyleValues.Medium; headerCell.Style.Border.BottomBorder = XLBorderStyleValues.Medium; headerCell.Style.Border.LeftBorder = XLBorderStyleValues.Medium; headerCell.Style.Border.BottomBorderColor = XLColor.FromArgb(0x777777); headerCell.Style.Border.TopBorderColor = XLColor.FromArgb(0x777777); headerCell.Style.Border.LeftBorderColor = XLColor.FromArgb(0x777777); headerCell.Style.Border.RightBorderColor = XLColor.FromArgb(0x777777); if (property.EhRequerido) { headerCell.Style.Font.Bold = true; } }
private static void Example <T>(int addExample, IXLWorksheet worksheet, PropertyInfo[] propertiesExample, int i, DnPropriedadeJsonAtributo property) { for (var x = 0; x < addExample; x++) { var example = typeof(T).GetExampleValue(); var exampleCell = worksheet.Column(i + 1).Cell(2 + x); var exampleProperty = propertiesExample.FirstOrDefault(x => x.Name == property.NomeDaPropriedadeCaseSensitive); exampleCell.Value = exampleProperty?.GetValue(example) ?? ""; } }