Created
December 18, 2023 19:21
-
-
Save YurePereira/441fac80847740d6e1ac358818a463fb to your computer and use it in GitHub Desktop.
Código para emissão de protocolos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Security.Cryptography; | |
| using System.Linq; | |
| public class Program | |
| { | |
| public static Protocolo protocolo { get; set; } | |
| public static void Main() | |
| { | |
| protocolo = Protocolo.Novo; | |
| Console.WriteLine("Protocolo:"); | |
| Console.WriteLine(protocolo.RetornarNumeroProtocolo()); | |
| } | |
| } | |
| public class Protocolo | |
| { | |
| public string Numero { get; set; } | |
| public override string ToString() | |
| { | |
| return Numero; | |
| } | |
| public static Protocolo Novo => new Protocolo | |
| { | |
| Numero = DateTime.Now.Year + GerarNumero() | |
| }; | |
| public static string GerarNumero() | |
| { | |
| var bytes = new byte[8]; | |
| using (var rng = RandomNumberGenerator.Create()) | |
| { | |
| rng.GetNonZeroBytes(bytes); | |
| } | |
| return string.Join(string.Empty, bytes.Select(n => n.ToString("X2"))); | |
| } | |
| public string RetornarNumeroProtocolo() | |
| { | |
| var anoCorrente = DateTime.Now.Year; | |
| Numero = anoCorrente + GerarNumero(); | |
| return Numero; | |
| } | |
| } | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Melhorar forma de criação de instância da classe, analisar utilização do padrão de projeto singleton.