Autor
|
Tema: Librería de Snippets para VB.NET !! (Compartan aquí sus snippets) (Leído 526,939 veces)
|
Elektro Enjuto
|
Aquí les dejo varias clases de atributos pensadas estrictamente para ser utilizadas en .NET Framework. Estas clases de atributo sirven como sustitutos de las clases de atributo disponibles en .NET Core que llevan el mismo nombre. De este modo, podemos utilizar las mismas clases de atributo pero en un código de .NET Framework, permitiendo aplicar estos atributos a un código antes de migrarlo a .NET Core. Estas clases de atirubuto son una copia idéntica de las clases disponibles en .NET Core, incluyendo los argumentos de atributo. El modo de empleo es como cualquier otra clase de atributo: <Extension> <SupportedOSPlatform("windows")> Public Function ToRectangle(bmp As Bitmap) As Rectangle Return New Rectangle(Point.Empty, bmp.Size) End Function
SupportedOSPlatformAttribute.vb ' *********************************************************************** ' Author : ElektroStudios ' Modified : 23-June-2023 ' *********************************************************************** #Region " Option Statements " Option Strict On Option Explicit On Option Infer Off #End Region #Region " Imports " #End Region #If Not NETCOREAPP Then Namespace DevCase.Runtime.Attributes ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' This attribute class is solely intended to simulate and therefore preserve the ''' 'System.Runtime.Versioning.SupportedOSPlatformAttribute' attribute class when migrating projects to .NET Core. ''' <para></para> ''' This attribute class marks APIs that are supported for a specified platform or operating system. ''' If a version is specified, the API cannot be called from an earlier version. ''' <para></para> ''' Multiple attributes can be applied to indicate support for multiple platforms or operating systems. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <remarks> ''' For more information, see <see href="https://learn.microsoft.com/en-us/dotnet/api/system.runtime.versioning.supportedosplatformattribute">SupportedOSPlatformAttribute Class</see>. ''' </remarks> ''' ---------------------------------------------------------------------------------------------------- ''' <seealso cref="System.Attribute" /> ''' ---------------------------------------------------------------------------------------------------- <AttributeUsage(AttributeTargets.Assembly Or AttributeTargets.Class Or AttributeTargets.Constructor Or AttributeTargets.Enum Or AttributeTargets.Event Or AttributeTargets.Field Or AttributeTargets.Interface Or AttributeTargets.Method Or AttributeTargets.Module Or AttributeTargets.Property Or AttributeTargets.Struct, AllowMultiple:=True, Inherited:=False)> Public NotInheritable Class SupportedOSPlatformAttribute : Inherits Attribute ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Gets the supported OS platform name that this attribute applies to, ''' optionally including a version (eg. "windows7.0"). ''' </summary> ''' ---------------------------------------------------------------------------------------------------- Public ReadOnly Property PlatformName As String ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Initializes a new instance of the <see cref="SupportedOSPlatformAttribute"/> attribute class ''' for the specified supported OS platform (eg. "windows7.0"). ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="platformName"> ''' The supported OS platform name that this attribute applies to, ''' optionally including a version (eg. "windows7.0"). ''' </param> ''' ---------------------------------------------------------------------------------------------------- Public Sub New(platformName As String) Me.PlatformName = platformName End Sub End Class End Namespace #End If
UnsupportedOSPlatformAttribute.vb ' *********************************************************************** ' Author : ElektroStudios ' Modified : 23-June-2023 ' *********************************************************************** #Region " Option Statements " Option Strict On Option Explicit On Option Infer Off #End Region #Region " Imports " #End Region #If Not NETCOREAPP Then Namespace DevCase.Runtime.Attributes ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' This attribute class is solely intended to simulate and therefore preserve the ''' 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' attribute class when migrating projects to .NET Core. ''' <para></para> ''' This attribute class marks APIs that were removed or are unsupported in a given operating system version. ''' <para></para> ''' Multiple attributes can be applied to indicate unsupported platforms or operating systems. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <remarks> ''' For more information, see <see href="https://learn.microsoft.com/en-us/dotnet/api/system.runtime.versioning.unsupportedosplatformattribute">UnsupportedOSPlatformAttribute Class</see>. ''' </remarks> ''' ---------------------------------------------------------------------------------------------------- ''' <seealso cref="System.Attribute" /> ''' ---------------------------------------------------------------------------------------------------- <AttributeUsage(AttributeTargets.Assembly Or AttributeTargets.Class Or AttributeTargets.Constructor Or AttributeTargets.Enum Or AttributeTargets.Event Or AttributeTargets.Field Or AttributeTargets.Interface Or AttributeTargets.Method Or AttributeTargets.Module Or AttributeTargets.Property Or AttributeTargets.Struct, AllowMultiple:=True, Inherited:=False)> Public NotInheritable Class UnsupportedOSPlatformAttribute : Inherits Attribute ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Gets the unsupported OS platform name that this attribute applies to, ''' optionally including a version (eg. "windows7.0"). ''' </summary> ''' ---------------------------------------------------------------------------------------------------- Public ReadOnly Property PlatformName As String ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Gets additional information about the unsupported API, for example, ''' a message that mostly suggests a replacement for the unsupported API. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- Public ReadOnly Property Message As String ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Initializes a new instance of the <see cref="UnsupportedOSPlatformAttribute"/> attribute class ''' for the specified unsupported OS platform. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="platformName"> ''' The unsupported OS platform name that this attribute applies to, ''' optionally including a version (eg. "windows7.0"). ''' </param> ''' ---------------------------------------------------------------------------------------------------- Public Sub New(platformName As String) Me.PlatformName = platformName End Sub ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Initializes a new instance of the <see cref="UnsupportedOSPlatformAttribute"/> attribute class ''' for the specified unsupported OS platform with an additional message. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="platformName"> ''' The unsupported OS platform name that this attribute applies to, ''' optionally including a version (eg. "windows7.0"). ''' </param> ''' ''' <param name="message"> ''' Additional information about the unsupported API, for example, ''' a message that mostly suggests a replacement for the unsupported API. ''' </param> ''' ---------------------------------------------------------------------------------------------------- Public Sub New(platformName As String, message As String) Me.PlatformName = platformName Me.Message = message End Sub End Class End Namespace #End If
ObsoletedOSPlatformAttribute.vb ' *********************************************************************** ' Author : ElektroStudios ' Modified : 23-June-2023 ' *********************************************************************** #Region " Option Statements " Option Strict On Option Explicit On Option Infer Off #End Region #Region " Imports " #End Region #If Not NETCOREAPP Then Namespace DevCase.Runtime.Attributes ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' This attribute class is solely intended to simulate and therefore preserve the ''' 'System.Runtime.Versioning.ObsoletedOSPlatformAttribute' attribute class when migrating projects to .NET Core. ''' <para></para> ''' This attribute class marks APIs that were obsoleted in a given operating system version. ''' <para></para> ''' Multiple attributes can be applied to indicate obsoleted platforms or operating systems. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <remarks> ''' For more information, see <see href="https://learn.microsoft.com/en-us/dotnet/api/system.runtime.versioning.obsoletedosplatformattribute">ObsoletedOSPlatformAttribute Class</see>. ''' </remarks> ''' ---------------------------------------------------------------------------------------------------- ''' <seealso cref="System.Attribute" /> ''' ---------------------------------------------------------------------------------------------------- <AttributeUsage(AttributeTargets.Assembly Or AttributeTargets.Class Or AttributeTargets.Constructor Or AttributeTargets.Enum Or AttributeTargets.Event Or AttributeTargets.Field Or AttributeTargets.Interface Or AttributeTargets.Method Or AttributeTargets.Module Or AttributeTargets.Property Or AttributeTargets.Struct, AllowMultiple:=True, Inherited:=False)> Public NotInheritable Class ObsoletedOSPlatformAttribute : Inherits Attribute ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Gets the obsoleted OS platform name that this attribute applies to, ''' optionally including a version (eg. "windows7.0"). ''' </summary> ''' ---------------------------------------------------------------------------------------------------- Public ReadOnly Property PlatformName As String ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Gets additional information about the obsoletion, for example, ''' a message that mostly suggests an alternative for the obsoleted API. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- Public ReadOnly Property Message As String ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Initializes a new instance of the <see cref="UnsupportedOSPlatformAttribute"/> attribute class ''' for the specified obsoleted OS platform. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="platformName"> ''' The obsoleted OS platform name that this attribute applies to, ''' optionally including a version (eg. "windows7.0"). ''' </param> ''' ---------------------------------------------------------------------------------------------------- Public Sub New(platformName As String) Me.PlatformName = platformName End Sub ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Initializes a new instance of the <see cref="UnsupportedOSPlatformAttribute"/> attribute class ''' for the specified obsoleted OS platform with an additional message. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="platformName"> ''' The obsoleted OS platform name that this attribute applies to, ''' optionally including a version (eg. "windows7.0"). ''' </param> ''' ''' <param name="message"> ''' Additional information about the obsoletion, for example, ''' a message that mostly suggests an alternative for the obsoleted API. ''' </param> ''' ---------------------------------------------------------------------------------------------------- Public Sub New(platformName As String, message As String) Me.PlatformName = platformName Me.Message = message End Sub End Class End Namespace #End If
TargetPlatformAttribute.vb ' *********************************************************************** ' Author : ElektroStudios ' Modified : 23-June-2023 ' *********************************************************************** #Region " Option Statements " Option Strict On Option Explicit On Option Infer Off #End Region #Region " Imports " #End Region #If Not NETCOREAPP Then Namespace DevCase.Runtime.Attributes ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' This attribute class is solely intended to simulate and therefore preserve the ''' 'System.Runtime.Versioning.TargetPlatformAttribute' attribute class when migrating projects to .NET Core. ''' <para></para> ''' This attribute class specifies the operating system that a project targets, for example, Windows or iOS. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <remarks> ''' For more information, see <see href="https://learn.microsoft.com/en-us/dotnet/api/system.runtime.versioning.targetplatformattribute">TargetPlatformAttribute Class</see>. ''' </remarks> ''' ---------------------------------------------------------------------------------------------------- ''' <seealso cref="System.Attribute" /> ''' ---------------------------------------------------------------------------------------------------- <AttributeUsage(AttributeTargets.Assembly, AllowMultiple:=False, Inherited:=False)> Public NotInheritable Class TargetPlatformAttribute : Inherits Attribute ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Gets the target OS platform name that this attribute applies to (eg. "windows"). ''' </summary> ''' ---------------------------------------------------------------------------------------------------- Public ReadOnly Property PlatformName As String ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Initializes a new instance of the <see cref="TargetPlatformAttribute"/> attribute class ''' for the specified target OS platform. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="platformName"> ''' The target OS platform name that this attribute applies to (eg. "windows"). ''' </param> ''' ---------------------------------------------------------------------------------------------------- Public Sub New(platformName As String) Me.PlatformName = platformName End Sub End Class End Namespace #End If
ModuleInitializerAttribute.vb ' *********************************************************************** ' Author : ElektroStudios ' Modified : 23-June-2023 ' *********************************************************************** #Region " Option Statements " Option Strict On Option Explicit On Option Infer Off #End Region #Region " Imports " #End Region #If Not NETCOREAPP Then Namespace DevCase.Runtime.Attributes ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' This attribute class is solely intended to simulate and therefore preserve the ''' 'System.Runtime.CompilerServices.ModuleInitializerAttribute' attribute class when migrating projects to .NET Core. ''' <para></para> ''' This attribute indicates to the compiler that a method should be called in its containing module's initializer. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <remarks> ''' For more information, see <see href="https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.moduleinitializerattribute">ModuleInitializerAttribute Class</see>. ''' <para></para> ''' When one or more valid methods with this attribute are found in a compilation, ''' the compiler will emit a module initializer that calls each of the attributed methods. ''' </remarks> ''' ---------------------------------------------------------------------------------------------------- ''' <seealso cref="System.Attribute" /> ''' ---------------------------------------------------------------------------------------------------- <AttributeUsage(AttributeTargets.Method, AllowMultiple:=False, Inherited:=False)> Public NotInheritable Class ModuleInitializerAttribute : Inherits Attribute ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Initializes a new instance of the <see cref="ModuleInitializerAttribute"/> attribute class. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- Public Sub New() End Sub End Class End Namespace #End If
SkipLocalsInitAttribute.vb ' *********************************************************************** ' Author : ElektroStudios ' Modified : 23-June-2023 ' *********************************************************************** #Region " Option Statements " Option Strict On Option Explicit On Option Infer Off #End Region #Region " Imports " #End Region #If Not NETCOREAPP Then Namespace DevCase.Runtime.Attributes ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' This attribute class is solely intended to simulate and therefore preserve the ''' 'System.Runtime.CompilerServices.SkipLocalsInitAttribute' attribute class when migrating projects to .NET Core. ''' <para></para> ''' This attribute indicates to the compiler that the .locals init flag should not be set ''' in nested method headers when emitting to metadata. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <remarks> ''' For more information, see <see href="https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.skiplocalsinitattribute">SkipLocalsInitAttribute Class</see>. ''' <para></para> ''' This attribute is unsafe, because it may reveal uninitialized memory to the application in certain instances ''' (for example, reading from uninitialized stack-allocated memory). ''' <para></para> ''' If applied to a method directly, the attribute applies to that method and all its nested functions, ''' including lambdas and local functions. ''' <para></para> ''' If applied to a type or module, it applies to all methods nested inside. ''' <para></para> ''' This attribute is intentionally not permitted on assemblies. ''' <para></para> ''' To apply the attribute to multiple type declarations, use it at the module level instead. ''' </remarks> ''' ---------------------------------------------------------------------------------------------------- ''' <seealso cref="System.Attribute" /> ''' ---------------------------------------------------------------------------------------------------- <AttributeUsage(AttributeTargets.Class Or AttributeTargets.Constructor Or AttributeTargets.Event Or AttributeTargets.Interface Or AttributeTargets.Method Or AttributeTargets.Module Or AttributeTargets.Property Or AttributeTargets.Struct, AllowMultiple:=False, Inherited:=False)> Public NotInheritable Class SkipLocalsInitAttribute : Inherits Attribute ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Initializes a new instance of the <see cref="SkipLocalsInitAttribute"/> attribute class. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- Public Sub New() End Sub End Class End Namespace #End If
|
|
« Última modificación: 10 Septiembre 2023, 06:41 am por Elektro Enjuto »
|
En línea
|
@%$& #$ %&#$, ¡hay que decirlo más!.
|
|
|
Elektro Enjuto
|
He escrito este código que permite obtener el código IL (Intermediate Language Code) de un método dinámico para posteriormente manipularlo mediante un array de bytes: ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Returns the MSIL for the method body of the source <see cref="DynamicMethod"/>, as an array of bytes. ''' <para></para> ''' This is the necessary equivalent for <see cref="MethodBody.GetILCodeAsByteArray()"/> function, ''' because <see cref="MethodBody.GetILCodeAsByteArray()"/> will not work with the method body returned by ''' an <see cref="DynamicMethod.GetMethodBody()"/> function since the IL code is stored in ''' the MethodBuilder's ILGenerator. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example #1. ''' <code language="VB.NET"> ''' Dim dynMethod As New DynamicMethod("my_dynamic_method_name", Nothing, Type.EmptyTypes, restrictedSkipVisibility:=True) ''' Dim ilGen As ILGenerator = dynMethod.GetILGenerator(streamSize:=64) ''' ilGen.Emit(OpCodes.Nop) ''' ''' Dim ilCode As Byte() = GetILCodeAsByteArray(dynMethod) ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example #2. ''' <code language="VB.NET"> ''' ' Create a simple dynamic method that has no parameters and does not return a value. ''' Dim dynMethod As New DynamicMethod("my_dynamic_method_name", Nothing, Type.EmptyTypes, restrictedSkipVisibility:=True) ''' ''' ' Get an ILGenerator and emit a body for the dynamic method. ''' Dim il As ILGenerator = dynMethod.GetILGenerator(streamSize:=64) ''' il.Emit(OpCodes.Nop) ''' il.Emit(OpCodes.Ret) ''' ''' ' Completes the dynamic method and creates a delegate that can be used to execute it. ''' ' Any further attempts to change the IL code will cause an exception. ''' Dim dynMethodInvoker As Action = CType(dynMethod.CreateDelegate(GetType(Action)), Action) ''' ''' ' Get the IL code. ''' Dim ilCode As Byte() = GetILCodeAsByteArray(dynMethod) ''' ''' Console.WriteLine($"Method body's IL bytes: {String.Join(", ", ilCode)}") ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="dynMethod"> ''' The source <see cref="DynamicMethod"/>. ''' </param> ''' ---------------------------------------------------------------------------------------------------- ''' <returns> ''' The MSIL for the method body of the source <see cref="DynamicMethod"/>, as an array of bytes. ''' </returns> ''' ---------------------------------------------------------------------------------------------------- <DebuggerStepThrough> <Extension> <EditorBrowsable(EditorBrowsableState.Always)> Public Function GetILCodeAsByteArray(dynMethod As DynamicMethod) As Byte() Dim bindingFlags As BindingFlags = BindingFlags.Instance Or BindingFlags.NonPublic ' First we try to retrieve the value of "m_resolver" field, ' which will always be null unless the dynamic method is completed ' by either calling 'dynMethod.CreateDelegate()' or 'dynMethod.Invoke()' function. ' Source: https://learn.microsoft.com/en-us/dotnet/api/system.reflection.emit.dynamicmethod.getilgenerator ' (in remarks section) ' Note that the dynamic method object does not know when it is ready for use ' since there is not API which indicates that IL generation has completed. ' Source: https://referencesource.microsoft.com/#mscorlib/system/reflection/emit/dynamicmethod.cs,7fc135a2ceea0854,references ' (in commentary lines) Dim resolver As Object = GetType(DynamicMethod).GetField("m_resolver", bindingFlags).GetValue(dynMethod) If resolver IsNot Nothing Then Return DirectCast(resolver.GetType().GetField("m_code", bindingFlags).GetValue(resolver), Byte()) Else ' So, if the dynamic method is not completed, we will retrieve the "m_ILStream" field instead. ' The only difference I notice between "m_resolver" and "m_ILStream" fields is that the IL bytes in "m_ILStream" ' will have trailing zeros / null bytes depending on the amount of unused bytes in this stream. ' ( The buffer size for "m_ILStream" is allocated by a call to 'dynMethod.GetILGenerator(streamSize)' function. ) Dim ilGen As ILGenerator = dynMethod.GetILGenerator() ' Conditional for .NET 4.x because DynamicILGenerator class derived from ILGenerator. ' Source: https://stackoverflow.com/a/4147132/1248295 Dim ilStream As FieldInfo = If(Environment.Version.Major >= 4, ilGen.GetType().BaseType.GetField("m_ILStream", bindingFlags), ilGen.GetType().GetField("m_ILStream", bindingFlags)) Return TryCast(ilStream.GetValue(ilGen), Byte()) End If End Function
Ejemplo de uso: Dim dynMethod As New DynamicMethod("my_dynamic_method_name", Nothing, Type.EmptyTypes, restrictedSkipVisibility:=True) Dim ilGen As ILGenerator = dynMethod.GetILGenerator(streamSize:=64) ilGen.Emit(OpCodes.Nop) Dim ilCode As Byte() = GetILCodeAsByteArray(dynMethod)
|
|
« Última modificación: 10 Septiembre 2023, 06:58 am por Elektro Enjuto »
|
En línea
|
@%$& #$ %&#$, ¡hay que decirlo más!.
|
|
|
Elektro Enjuto
|
Un sustituto de la clase System.Random para generar números aleatorios. Ejemplo de uso: RandomNumberGenerator.Instance.Next(0, 10)
RandomNumberGenerator.vb' *********************************************************************** ' Author : ElektroStudios ' Modified : 25-November-2022 ' *********************************************************************** #Region " Option Statements " Option Strict On Option Explicit On Option Infer Off #End Region #Region " Imports " Imports System.Security.Cryptography #End Region #Region " RandomNumberGenerator " ' ReSharper disable once CheckNamespace Namespace DevCase.Runtime.Numerics ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Wrapper class for thread-safe generation of pseudo-random numbers. ''' <para></para> ''' Lazy-load singleton for ThreadStatic <see cref="Random"/>. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- <CodeAnalysis.SuppressMessage("CodeQuality", "IDE0079:Remove unnecessary suppression", Justification:="Required to migrate this code to .NET Core")> Public Class RandomNumberGenerator #Region " Private Fields " ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' The <see cref="Random"/> instance for generation of pseudo-random numbers. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- <ThreadStatic> Private Shared RNG As Random #End Region #Region " Properties " ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Gets a <see cref="Random"/> instance for generation of pseudo-random numbers. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- Public Shared ReadOnly Property Instance As Random Get If RandomNumberGenerator.RNG Is Nothing Then Dim buffer As Byte() = New Byte(3) {} #Disable Warning SYSLIB0023 ' Type or member is obsolete Using rngProvider As New RNGCryptoServiceProvider() rngProvider.GetBytes(buffer) RandomNumberGenerator.RNG = New Random(Seed:=BitConverter.ToInt32(buffer, 0)) End Using #Enable Warning SYSLIB0023 ' Type or member is obsolete End If Return RandomNumberGenerator.RNG End Get End Property #End Region End Class End Namespace #End Region
|
|
|
En línea
|
@%$& #$ %&#$, ¡hay que decirlo más!.
|
|
|
Elektro Enjuto
|
Les presento mi GENERADOR DE CONTRASEÑAS MEMORIZABLES. Inspirado en el proyecto: https://xkpasswd.net/s/ y https://www.bartbusschots.ie/s/publications/software/xkpasswd/Ejemplo de uso: Dim options As New MemorablePasswordOptions With { .NumberOfWords = 3, .MinimumWordLength = 4, .MaximumWordLength = 8, .SeparatorCharacters = "._-+".ToCharArray(), .StringCase = MemorablePasswordStringCase.TitleCase, .FixedPrefix = Nothing, .FixedSuffix = "!", .NumberOfDigitsPrefix = 0, .NumberOfDigitsSuffix = 3 } Dim wordList As String() = System. IO. File. ReadAllLines(".\words.txt", Encoding. Default) For i As Integer = 0 To 10 Dim password As String = UtilPasswords.GenerateMemorablePassword(options, wordList) Console.WriteLine(password) Next
Salida: Actor+Teaching_Spring-174! Example_Hotel_Slavery_861! Maximum-Accuse_Offense.016! Banana.China.Baseball-154! Attach+Wash-Wagon+647! Consumer+Allow.Boom-946! Employ+Lose+Opinion_106! Feel.Carbon.Focus+176! Candy-Remove+Kick+581! Internal-Buddy_Wide-280! Serious-Everyone+Approve-522! El tipo y estructura de la contraseña se puede personalizar mediante el objeto de tipo MemorablePasswordOptions para adaptarlo a su gusto y necesidades.
Clase principal, UtilPasswords.vbImports DevCase.Core.DataProcessing.Common Imports DevCase.Core.Security.Passwords Imports DevCase.Extensions Imports DevCase.Runtime.Numerics Imports System.Text Public Class UtilPasswords ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Generates a memorable password based on the provided options and word list. ''' <para></para> ''' A memorable password is a type of password that is designed to be easy to remember, ''' while still providing a reasonable level of security. ''' <para></para> ''' It is a password generation methodology that aims to be recalled by the user ''' without the need for written notes or relying solely on password managers. ''' <para></para> ''' The concept behind a memorable password is to create a combination of words, phrases, ''' or memorable patterns that are personally meaningful to the user. ''' This can include using familiar words, personal information, ''' or unique combinations that have personal significance. ''' <para></para> ''' The goal is to create a password that is both secure and memorable, ''' striking a balance between convenience and protection. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <remarks> ''' The generated password by this function follows the following format: ''' (FixedPrefix)(DigitsPrefix+Separator)(Words+Separators)(Separator+DigitsSuffix)(FixedSuffix) ''' </remarks> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example. ''' <code language="VB.NET"> ''' Dim options As New MemorablePasswordOptions With { ''' .NumberOfWords = 3, ''' .MinimumWordLength = 4, ''' .MaximumWordLength = 8, ''' .SeparatorCharacters = "._-+".ToCharArray(), ''' .StringCase = MemorablePasswordStringCase.TitleCase, ''' .FixedPrefix = Nothing, ''' .FixedSuffix = "!", ''' .NumberOfDigitsPrefix = 0, ''' .NumberOfDigitsSuffix = 3 ''' } ''' ''' Dim wordList As String() = System.IO.File.ReadAllLines(".\words.txt", Encoding.Default) ''' ''' For i As Integer = 0 To 10 ''' Dim password As String = GenerateMemorablePassword(options, wordList) ''' Console.WriteLine(password) ''' Next ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="options"> ''' The options for generating the memorable password. ''' </param> ''' ''' <param name="wordList"> ''' The list of words to choose from. ''' </param> ''' ---------------------------------------------------------------------------------------------------- ''' <returns> ''' The resulting memorable password. ''' </returns> ''' ---------------------------------------------------------------------------------------------------- <DebuggerStepThrough> Public Shared Function GenerateMemorablePassword(options As MemorablePasswordOptions, wordList As IEnumerable(Of String)) As String If options.NumberOfDigitsPrefix < 0 Then Throw New InvalidOperationException( $"Value of property: '{NameOf(options)}.{options.NumberOfDigitsPrefix}' must be zero or greather.") End If If options.NumberOfDigitsSuffix < 0 Then Throw New InvalidOperationException( $"Value of property: '{NameOf(options)}.{options.NumberOfDigitsSuffix}' must be zero or greather.") End If Dim filteredWords As IEnumerable(Of String) = wordList.Where(Function(word As String) Return word.Length >= options.MinimumWordLength AndAlso word.Length <= options.MaximumWordLength End Function) Dim filteredWordsCount As Integer = filteredWords.Count If filteredWordsCount = 0 Then Throw New InvalidOperationException( "The provided word list does not contain any word between the " & "minimum and maximum word length specified in properties: " & $"'{options}.{options.MinimumWordLength}' and '{options}.{options.MaximumWordLength}'.") End If If filteredWordsCount < options.NumberOfWords Then Throw New InvalidOperationException( "The provided word list does not contain the" & $"enough number of words specified in property: '{options}.{options.NumberOfWords}'.") End If Dim selectedWords As New HashSet(Of String) Do Until selectedWords.Count = options.NumberOfWords selectedWords.Add(filteredWords(RandomNumberGenerator.Instance.Next(0, filteredWordsCount))) Loop Dim separatorsCount As Integer If options.SeparatorCharacters IsNot Nothing Then separatorsCount = options.SeparatorCharacters.Length End If Const digits As String = "1234567890" Dim sb As New StringBuilder() ' 1. Append the fixed prefix if provided. sb.Append(options.FixedPrefix) ' 2. Append a prefix of digits if provided, and a separator if provided. If options.NumberOfDigitsPrefix <> 0 Then For i As Integer = 0 To options.NumberOfDigitsPrefix - 1 sb.Append(digits(RandomNumberGenerator.Instance.Next(0, digits.Length))) Next If options.SeparatorCharacters IsNot Nothing AndAlso separatorsCount <> 0 Then sb.Append(options.SeparatorCharacters(RandomNumberGenerator.Instance.Next(0, separatorsCount))) End If End If ' 3. Append the selected words, together with the word separators if provided. Dim selectedWordsCount As Integer = selectedWords.Count For i As Integer = 0 To selectedWordsCount - 1 sb.Append(StringExtensions.Rename(selectedWords(i), CType(options.StringCase, StringCase))) If i <> (selectedWordsCount - 1) Then If options.SeparatorCharacters IsNot Nothing AndAlso separatorsCount <> 0 Then sb.Append(options.SeparatorCharacters(RandomNumberGenerator.Instance.Next(0, separatorsCount))) End If End If Next ' 4. Append a separator if provided, and a suffix of digits if provided. If options.NumberOfDigitsSuffix <> 0 Then If options.SeparatorCharacters IsNot Nothing AndAlso separatorsCount <> 0 Then sb.Append(options.SeparatorCharacters(RandomNumberGenerator.Instance.Next(0, separatorsCount))) End If For i As Integer = 0 To options.NumberOfDigitsSuffix - 1 sb.Append(digits(RandomNumberGenerator.Instance.Next(0, digits.Length))) Next End If ' 5. Append the fixed suffix if provided. sb.Append(options.FixedSuffix) ' (FixedPrefix)(DigitsPrefix+Separator)(Words+Separators)(Separator+DigitsSuffix)(FixedSuffix) Return sb.ToString() End Function End Class
RandomNumberGenerator.vbhttps://foro.elhacker.net/net_c_vbnet_asp/libreria_de_snippets_para_vbnet_compartan_aqui_sus_snippets-t378770.0.html;msg2272581#msg2272581 MemorablePasswordOptions.vb' *********************************************************************** ' Author : ElektroStudios ' Modified : 14-July-2023 ' *********************************************************************** #Region " Option Statements " Option Strict On Option Explicit On Option Infer Off #End Region #Region " Imports " #End Region #Region " UtilPasswords " ' ReSharper disable once CheckNamespace Namespace DevCase.Core.Security.Passwords ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Represents the options for generating a memorable password ''' with <see cref="UtilPasswords.GenerateMemorablePassword"/> function. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- Public Class MemorablePasswordOptions #Region " Properties " ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Gets or sets the number of words to include in the password. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- Public Property NumberOfWords As Integer ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Gets or sets the minimum length of a word to consider for the password. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- Public Property MinimumWordLength As Integer ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Gets or sets the maximum length of a word to consider for the password. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- Public Property MaximumWordLength As Integer ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Gets or sets the characters to use as separators between words. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- Public Property SeparatorCharacters As Char() ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Gets or sets the prefix to prepend to the password. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- Public Property FixedPrefix As String ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Gets or sets the suffix to append to the password. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- Public Property FixedSuffix As String ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Gets or sets the number of digits to include as a prefix to the password ''' (after prepending <see cref="MemorablePasswordOptions.FixedPrefix"/>). ''' </summary> ''' ---------------------------------------------------------------------------------------------------- Public Property NumberOfDigitsPrefix As Integer ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Gets or sets the number of digits to include as a suffix to the password ''' (before appending <see cref="MemorablePasswordOptions.FixedSuffix"/>). ''' </summary> ''' ---------------------------------------------------------------------------------------------------- Public Property NumberOfDigitsSuffix As Integer ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Gets or sets the case of the words in the password. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- Public Property StringCase As MemorablePasswordStringCase #End Region #Region " Constructors " ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Initializes a new instance of the <see cref="MemorablePasswordOptions"/> class. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- Public Sub New() End Sub #End Region End Class End Namespace #End Region
MemorablePasswordStringCase.vb' *********************************************************************** ' Author : ElektroStudios ' Modified : 14-July-2023 ' *********************************************************************** #Region " Option Statements " Option Strict On Option Explicit On Option Infer Off #End Region #Region " Imports " Imports DevCase.Core.DataProcessing.Common #End Region #Region " MemorablePasswordStringCase " ' ReSharper disable once CheckNamespace Namespace DevCase.Core.Security.Passwords ''' <summary> ''' Specifies the string-case of the words in a memorable password. ''' </summary> Public Enum MemorablePasswordStringCase ''' <summary> ''' Changes all characters to lower-case. ''' <para></para> ''' ''' [Example] ''' <para></para> ''' Input : ABCDEF ''' <para></para> ''' Output: abcdef ''' </summary> LowerCase = StringCase.LowerCase ''' <summary> ''' Changes all characters to upper-case. ''' <para></para> ''' ''' [Example] ''' <para></para> ''' Input : abcdef ''' <para></para> ''' Output: ABCDEF ''' </summary> UpperCase = StringCase.UpperCase ''' <summary> ''' Changes the first characters to upper-case, ''' and the rest of characters to lower-case. ''' <para></para> ''' ''' [Example] ''' <para></para> ''' Input : abcdef ''' <para></para> ''' Output: Abcdef ''' </summary> TitleCase = StringCase.TitleCase ''' <summary> ''' Mixed-case with first character to lower-case. ''' <para></para> ''' ''' [Example] ''' <para></para> ''' Input : ab cd ef ''' <para></para> ''' Output: aB Cd eF ''' </summary> MixedTitleCaseLower = StringCase.MixedTitleCaseLower ''' <summary> ''' Mixed-case with first character to upper-case. ''' <para></para> ''' ''' [Example] ''' <para></para> ''' Input : ab cd ef ''' <para></para> ''' Output: Ab cD Ef ''' </summary> MixedTitleCaseUpper = StringCase.MixedTitleCaseUpper ''' <summary> ''' Toggle-case. ''' <para></para> ''' ''' [Example] ''' <para></para> ''' Input : abc def ghi ''' <para></para> ''' Output: aBC dEF gHI ''' </summary> ToggleCase = StringCase.ToggleCase ''' <summary> ''' Alternates any lower-case character to upper-case and vice versa. ''' <para></para> ''' ''' [Example] ''' <para></para> ''' Input : Hello World! ''' <para></para> ''' Output: hELLO wORLD! ''' </summary> AlternateChars = StringCase.AlternateChars End Enum End Namespace #End Region
StringCase.vb' *********************************************************************** ' Author : ElektroStudios ' Modified : 26-October-2015 ' *********************************************************************** #Region " Option Statements " Option Strict On Option Explicit On Option Infer Off #End Region #Region " String Case " ' ReSharper disable once CheckNamespace Namespace DevCase.Core.DataProcessing.Common ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Specifies a string case. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- Public Enum StringCase As Integer ''' <summary> ''' LowerCase ''' <para></para> ''' ''' [Example] ''' <para></para> ''' Input : ABCDEF ''' <para></para> ''' Output: abcdef ''' </summary> LowerCase = &H0 ''' <summary> ''' UpperCase. ''' <para></para> ''' ''' [Example] ''' <para></para> ''' Input : abcdef ''' <para></para> ''' Output: ABCDEF ''' </summary> UpperCase = &H1 ''' <summary> ''' TitleCase. ''' <para></para> ''' ''' [Example] ''' <para></para> ''' Input : abcdef ''' <para></para> ''' Output: Abcdef ''' </summary> TitleCase = &H2 ''' <summary> ''' WordCase. ''' <para></para> ''' ''' [Example] ''' <para></para> ''' Input : abc def ''' <para></para> ''' Output: Abc Def ''' </summary> WordCase = &H3 ''' <summary> ''' CamelCase (With first letter to LowerCase). ''' <para></para> ''' ''' [Example] ''' <para></para> ''' Input : ABC DEF ''' <para></para> ''' Output: abcDef ''' </summary> CamelCaseLower = &H4 ''' <summary> ''' CamelCase (With first letter to UpperCase). ''' <para></para> ''' ''' [Example] ''' <para></para> ''' Input : ABC DEF ''' <para></para> ''' Output: AbcDef ''' </summary> CamelCaseUpper = &H5 ''' <summary> ''' MixedCase (With first letter to LowerCase). ''' <para></para> ''' ''' [Example] ''' <para></para> ''' Input : ab cd ef ''' <para></para> ''' Output: aB Cd eF ''' </summary> MixedTitleCaseLower = &H6 ''' <summary> ''' MixedCase (With first letter to UpperCase). ''' <para></para> ''' ''' [Example] ''' <para></para> ''' Input : ab cd ef ''' <para></para> ''' Output: Ab cD Ef ''' </summary> MixedTitleCaseUpper = &H7 ''' <summary> ''' MixedCase (With first letter of each word to LowerCase). ''' <para></para> ''' ''' [Example] ''' <para></para> ''' Input : ab cd ef ''' <para></para> ''' Output: aB cD eF ''' </summary> MixedWordCaseLower = &H8 ''' <summary> ''' MixedCase (With first letter of each word to UpperCase). ''' <para></para> ''' ''' [Example] ''' <para></para> ''' Input : ab cd ef ''' <para></para> ''' Output: Ab Cd Ef ''' </summary> MixedWordCaseUpper = &H9 ''' <summary> ''' ToggleCase. ''' <para></para> ''' ''' [Example] ''' <para></para> ''' Input : abc def ghi ''' <para></para> ''' Output: aBC dEF gHI ''' </summary> ToggleCase = &H10 ''' <summary> ''' Duplicates the characters. ''' <para></para> ''' ''' [Example] ''' <para></para> ''' Input : Hello World! ''' <para></para> ''' Output: HHeelllloo WWoorrlldd!! ''' </summary> DuplicateChars = &H11 ''' <summary> ''' Alternates the characters. ''' <para></para> ''' ''' [Example] ''' <para></para> ''' Input : Hello World! ''' <para></para> ''' Output: hELLO wORLD! ''' </summary> AlternateChars = &H12 End Enum End Namespace #End Region
StringExtensions.vb' *********************************************************************** ' Author : ElektroStudios ' Modified : 13-July-2023 ' *********************************************************************** #Region " Public Members Summary " ' String.Rename(StringCase) As String #End Region #Region " Option Statements " Option Strict On Option Explicit On Option Infer Off #End Region #Region " Imports " Imports System.ComponentModel Imports System.Globalization Imports System.Runtime.CompilerServices Imports DevCase.Core.DataProcessing.Common #End Region #Region " String Extensions " ' ReSharper disable once CheckNamespace Namespace DevCase.Extensions.StringExtensions ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Contains custom extension methods to use with a <see cref="String"/> type. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- <HideModuleName> Public Module StringExtensions #Region " Public Extension Methods " ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Renames a string to the specified StringCase. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example. ''' <code language="VB.NET"> ''' Dim str As String = "Hello World".Rename(StringCase.UpperCase) ''' ''' MessageBox.Show(str) ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="sender"> ''' The source <see cref="String"/>. ''' </param> ''' ''' <param name="stringCase"> ''' The <see cref="StringCase"/>. ''' </param> ''' ---------------------------------------------------------------------------------------------------- ''' <returns> ''' The renamed string. ''' </returns> ''' ---------------------------------------------------------------------------------------------------- <DebuggerStepThrough> <Extension> <EditorBrowsable(EditorBrowsableState.Always)> Public Function Rename(sender As String, stringCase As StringCase) As String Select Case stringCase Case StringCase.LowerCase Return sender.ToLower Case StringCase.UpperCase Return sender.ToUpper Case StringCase.TitleCase Return $"{Char.ToUpper(sender.First())}{sender.Remove(0, 1).ToLower()}" Case StringCase.WordCase Return CultureInfo.InvariantCulture.TextInfo.ToTitleCase(sender.ToLower()) Case StringCase.CamelCaseLower Return _ $"{Char.ToLower(sender.First())}{ _ CultureInfo.InvariantCulture.TextInfo.ToTitleCase(sender.ToLower()). Replace(" "c, String.Empty). Remove(0, 1)}" Case StringCase.CamelCaseUpper Return _ $"{Char.ToUpper(sender.First())}{ _ CultureInfo.InvariantCulture.TextInfo.ToTitleCase(sender.ToLower()). Replace(" "c, String.Empty). Remove(0, 1)}" Case StringCase.MixedTitleCaseLower Dim sb As New Global.System.Text.StringBuilder For i As Integer = 0 To sender.Length - 1 Step 2 If Not (i + 1) >= sender.Length Then sb.AppendFormat("{0}{1}", Char.ToLower(sender(i)), Char.ToUpper(sender(i + 1))) Else sb.Append(Char.ToLower(sender(i))) End If Next i Return sb.ToString() Case StringCase.MixedTitleCaseUpper Dim sb As New Global.System.Text.StringBuilder For i As Integer = 0 To sender.Length - 1 Step 2 If Not (i + 1) >= sender.Length Then sb.AppendFormat("{0}{1}", Char.ToUpper(sender(i)), Char.ToLower(sender(i + 1))) Else sb.Append(Char.ToUpper(sender(i))) End If Next i Return sb.ToString() Case StringCase.MixedWordCaseLower Dim sb As New Global.System.Text.StringBuilder For Each word As String In sender.Split sb.AppendFormat("{0} ", Rename(word, StringCase.MixedTitleCaseLower)) Next word Return sb.ToString() Case StringCase.MixedWordCaseUpper Dim sb As New Global.System.Text.StringBuilder For Each word As String In sender.Split sb.AppendFormat("{0} ", Rename(word, StringCase.MixedTitleCaseUpper)) Next word Return sb.ToString() Case StringCase.ToggleCase Dim sb As New Global.System.Text.StringBuilder For Each word As String In sender.Split sb.AppendFormat("{0}{1} ", Char.ToLower(word.First()), word.Remove(0, 1).ToUpper) Next word Return sb.ToString() Case StringCase.DuplicateChars Dim sb As New Global.System.Text.StringBuilder For Each c As Char In sender sb.Append(New String(c, 2)) Next c Return sb.ToString() Case StringCase.AlternateChars Dim sb As New Global.System.Text.StringBuilder For Each c As Char In sender Select Case Char.IsLower(c) Case True sb.Append(Char.ToUpper(c)) Case Else sb.Append(Char.ToLower(c)) End Select Next c Return sb.ToString() Case Else Return sender End Select End Function #End Region End Module End Namespace #End Region
|
|
|
En línea
|
@%$& #$ %&#$, ¡hay que decirlo más!.
|
|
|
Elektro Enjuto
|
Aquí les dejo varias funciones para enmascarar un String. Este código permite enmascarar de izquierda a derecha o de derecha a izquierda, todo el string o de forma parcial especificando la longitud de máscara, y el símbolo de máscara es personalizable. Además, permite especificar caracteres que se deban ignorar / no deban ser enmascarados. Por ejemplo, si tenemos el string "PASSWORD", podemos enmascararlo completamente: O parcialmente de izquierda a derecha: O parcialmente de derecha a izquierda: O de forma selectiva podemos crear una máscara completa o parial, e ignorar las letras "S" y "W" de la máscara:
' *********************************************************************** ' Author : ElektroStudios ' Modified : 12-July-2023 ' *********************************************************************** #Region " Public Members Summary " #Region " Functions " ' MaskString(String, Opt: Char) As String ' MaskString(String, Char(), Opt: Char) As String ' MaskString(String, Integer, Boolean, Opt: Char) As String ' MaskString(String, Integer, Boolean, Char(), Opt: Char) As String #End Region #End Region #Region " Option Statements " Option Strict On Option Explicit On Option Infer Off #End Region #Region " Imports " Imports System.Text Imports System.Security Imports System.ComponentModel Imports System.Runtime.InteropServices Imports System.Collections.Generic Imports System.Linq #End Region #Region " UtilPasswords " ' ReSharper disable once CheckNamespace Namespace DevCase.Core.Security.Passwords Public NotInheritable Class UtilPasswords #Region " Public Methods " ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Masks the source string with a specific character. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example. ''' <code language="VB.NET"> ''' Dim password As String = "This is a password" ''' Dim maskChar As Char = "*"c ''' Dim masked As String = MaskString(password, maskChar) ''' Console.WriteLine(masked) ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="input"> ''' The string to mask. ''' </param> ''' ''' <param name="maskCharacter"> ''' Optional. The character used for masking (default: "*"). ''' </param> ''' ---------------------------------------------------------------------------------------------------- ''' <returns> ''' The masked string. ''' </returns> ''' ---------------------------------------------------------------------------------------------------- <DebuggerStepperBoundary> Public Shared Function MaskString(input As String, Optional maskCharacter As Char = "*"c) As String Return MaskString(input, maskLength:=input.Length, leftToRight:=True, allowedChars:=Nothing, maskCharacter) End Function ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Masks the source string with a specific character, ''' allowing certain characters to remain unmasked. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example. ''' <code language="VB.NET"> ''' Dim serialKey As String = "123-456-789" ''' Dim allowedChars As Char() = "-".ToCharArray() ''' Dim maskChar As Char = "*"c ''' ''' Dim masked As String = MaskString(serialKey, allowedChars, maskChar) ''' Console.WriteLine(masked) ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="input"> ''' The string to mask. ''' </param> ''' ''' <param name="allowedChars"> ''' An array of characters that are allowed to remain unmasked. ''' </param> ''' ''' <param name="maskCharacter"> ''' The character used for masking (default: "*"). ''' </param> ''' ---------------------------------------------------------------------------------------------------- ''' <returns> ''' The masked string. ''' </returns> ''' ---------------------------------------------------------------------------------------------------- <DebuggerStepperBoundary> Public Shared Function MaskString(input As String, allowedChars As Char(), Optional maskCharacter As Char = "*"c) As String Return MaskString(input, maskLength:=input.Length, leftToRight:=True, allowedChars:=allowedChars, maskCharacter) End Function ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Partially masks the source string with a specific character. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example. ''' <code language="VB.NET"> ''' Dim serialKey As String = "123-456-789" ''' Dim maskLength As Integer = 7 ''' Dim leftToRight As Boolean = True ''' Dim maskChar As Char = "*"c ''' ''' Dim masked As String = MaskString(serialKey, maskLength, leftToRight, maskChar) ''' Console.WriteLine(masked) ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="input"> ''' The string to mask. ''' </param> ''' ''' <param name="maskLength"> ''' The length of the mask. ''' </param> ''' ''' <param name="leftToRight"> ''' Indicates the direction of the mask (left to right or right to left). ''' </param> ''' ''' <param name="maskCharacter"> ''' The character used for masking (default: "*"). ''' </param> ''' ---------------------------------------------------------------------------------------------------- ''' <returns> ''' The masked string. ''' </returns> ''' ---------------------------------------------------------------------------------------------------- <DebuggerStepperBoundary> Public Shared Function MaskString(input As String, maskLength As Integer, leftToRight As Boolean, Optional maskCharacter As Char = "*"c) As String Return MaskString(input, maskLength:=maskLength, leftToRight:=leftToRight, allowedChars:=Nothing, maskCharacter) End Function ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Partially masks the source string with a specific character, ''' allowing certain characters to remain unmasked. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example. ''' <code language="VB.NET"> ''' Dim serialKey As String = "123-456-789" ''' Dim maskLength As Integer = 7 ''' Dim leftToRight As Boolean = True ''' Dim allowedChars As Char() = "-".ToCharArray() ''' Dim maskChar As Char = "*"c ''' ''' Dim masked As String = MaskString(serialKey, maskLength, leftToRight, allowedChars, maskChar) ''' Console.WriteLine(masked) ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="input"> ''' The string to mask. ''' </param> ''' ''' <param name="maskLength"> ''' The length of the mask. ''' </param> ''' ''' <param name="leftToRight"> ''' Indicates the direction of the mask (left to right or right to left). ''' </param> ''' ''' <param name="allowedChars"> ''' An array of characters that are allowed to remain unmasked. ''' </param> ''' ''' <param name="maskCharacter"> ''' The character used for masking (default: "*"). ''' </param> ''' ---------------------------------------------------------------------------------------------------- ''' <returns> ''' The masked string. ''' </returns> ''' ---------------------------------------------------------------------------------------------------- <DebuggerStepperBoundary> Public Shared Function MaskString(input As String, maskLength As Integer, leftToRight As Boolean, allowedChars As Char(), Optional maskCharacter As Char = "*"c) As String If String.IsNullOrEmpty(input) Then Throw New ArgumentNullException(paramName:=NameOf(input)) End If If String.IsNullOrEmpty(maskCharacter) Then Throw New ArgumentNullException(paramName:=NameOf(maskCharacter)) End If If maskLength <= 0 Then Throw New ArgumentException($"maskLength must be greather than zero.", paramName:=NameOf(maskLength)) End If Dim valueLength As Integer = input.Length If maskLength > valueLength Then Throw New ArgumentException($"maskLength can't be greather than the source string length.", paramName:=NameOf(maskLength)) End If Dim allowedCharIndices As IDictionary(Of Integer, Char) = Nothing If allowedChars IsNot Nothing AndAlso allowedChars.Length > 0 Then allowedCharIndices = New Dictionary(Of Integer, Char ) Dim startPos As Integer Dim endPos As Integer If maskLength = valueLength Then ' Full mask. startPos = 0 endPos = valueLength - 1 Else If leftToRight Then ' Left to right mask. startPos = 0 endPos = maskLength - 1 Else ' Right to left mask. startPos = valueLength - maskLength endPos = valueLength - 1 End If End If For i As Integer = startPos To endPos Dim c As Char = input(i) If allowedChars.Contains(c) Then allowedCharIndices.Add(i, c) End If Next End If Dim sb As New StringBuilder(valueLength, valueLength) If maskLength = valueLength Then ' Full mask. sb.Append(maskCharacter, maskLength) Else If leftToRight Then ' Left to right mask. sb.Append(maskCharacter, maskLength) sb.Append(input.Substring(maskLength)) Else ' Right to left mask. sb.Append(input.Substring(0, valueLength - maskLength)) sb.Append(maskCharacter, maskLength) End If End If If allowedCharIndices IsNot Nothing Then For Each pair As KeyValuePair(Of Integer, Char) In allowedCharIndices sb.Chars(pair.Key) = pair.Value Next End If Return sb.ToString() End Function
|
|
« Última modificación: 10 Septiembre 2023, 08:09 am por Elektro Enjuto »
|
En línea
|
@%$& #$ %&#$, ¡hay que decirlo más!.
|
|
|
Elektro Enjuto
|
Lo mismo de antes pero para un objeto de tipo SecureString: ' *********************************************************************** ' Author : ElektroStudios ' Modified : 12-July-2023 ' *********************************************************************** #Region " Public Members Summary " #Region " Functions " ' MaskSecureString(String, Opt: Char) As SecureString ' MaskSecureString(String, Char(), Opt: Char) As SecureString ' MaskSecureString(String, Integer, Boolean, Opt: Char) As SecureString ' MaskSecureString(String, Integer, Boolean, Char(), Opt: Char) As SecureString ' MaskSecureString(SecureString, Opt: Char) As SecureString ' MaskSecureString(SecureString, Char(), Opt: Char) As SecureString ' MaskSecureString(SecureString, Integer, Boolean, Opt: Char) As SecureString ' MaskSecureString(SecureString, Integer, Boolean, Char(), Opt: Char) As SecureString #End Region #End Region #Region " Option Statements " Option Strict On Option Explicit On Option Infer Off #End Region #Region " Imports " Imports System.Text Imports System.Security Imports System.ComponentModel Imports System.Runtime.InteropServices Imports System.Collections.Generic Imports System.Linq #End Region #Region " UtilPasswords " ' ReSharper disable once CheckNamespace Namespace DevCase.Core.Security.Passwords Public NotInheritable Class UtilPasswords #Region " Public Methods " ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Masks the source string with a specific character. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example. ''' <code language="VB.NET"> ''' Dim password As String = "This is a password" ''' Dim maskChar As Char = "*"c ''' ''' Dim masked As SecureString = MaskSecureString(password, maskChar) ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="input"> ''' The string to mask. ''' </param> ''' ''' <param name="maskCharacter"> ''' Optional. The character used for masking (default: "*"). ''' </param> ''' ---------------------------------------------------------------------------------------------------- ''' <returns> ''' The masked string. ''' </returns> ''' ---------------------------------------------------------------------------------------------------- <DebuggerStepperBoundary> Public Shared Function MaskSecureString(input As String, Optional maskCharacter As Char = "*"c) As SecureString Return MaskSecureString(input, maskLength:=input.Length, leftToRight:=True, allowedChars:=Nothing, maskCharacter) End Function ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Masks the source string with a specific character, ''' allowing certain characters to remain unmasked. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example. ''' <code language="VB.NET"> ''' Dim serialKey As String = "123-456-789" ''' Dim allowedChars As Char() = "-".ToCharArray() ''' Dim maskChar As Char = "*"c ''' ''' Dim masked As SecureString = MaskSecureString(serialKey, allowedChars, maskChar) ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="input"> ''' The string to mask. ''' </param> ''' ''' <param name="allowedChars"> ''' An array of characters that are allowed to remain unmasked. ''' </param> ''' ''' <param name="maskCharacter"> ''' The character used for masking (default: "*"). ''' </param> ''' ---------------------------------------------------------------------------------------------------- ''' <returns> ''' The masked string. ''' </returns> ''' ---------------------------------------------------------------------------------------------------- <DebuggerStepperBoundary> Public Shared Function MaskSecureString(input As String, allowedChars As Char(), Optional maskCharacter As Char = "*"c) As SecureString Return MaskSecureString(input, maskLength:=input.Length, leftToRight:=True, allowedChars:=allowedChars, maskCharacter) End Function ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Partially masks the source string with a specific character. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example. ''' <code language="VB.NET"> ''' Dim serialKey As String = "123-456-789" ''' Dim maskLength As Integer = 7 ''' Dim leftToRight As Boolean = True ''' Dim maskChar As Char = "*"c ''' ''' Dim masked As SecureString = MaskSecureString(serialKey, maskLength, leftToRight, maskChar) ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="input"> ''' The string to mask. ''' </param> ''' ''' <param name="maskLength"> ''' The length of the mask. ''' </param> ''' ''' <param name="leftToRight"> ''' Indicates the direction of the mask (left to right or right to left). ''' </param> ''' ''' <param name="maskCharacter"> ''' The character used for masking (default: "*"). ''' </param> ''' ---------------------------------------------------------------------------------------------------- ''' <returns> ''' The masked string. ''' </returns> ''' ---------------------------------------------------------------------------------------------------- <DebuggerStepperBoundary> Public Shared Function MaskSecureString(input As String, maskLength As Integer, leftToRight As Boolean, Optional maskCharacter As Char = "*"c) As SecureString Return MaskSecureString(input, maskLength:=maskLength, leftToRight:=leftToRight, allowedChars:=Nothing, maskCharacter) End Function ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Partially masks the source string with a specific character, ''' allowing certain characters to remain unmasked. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example. ''' <code language="VB.NET"> ''' Dim serialKey As String = "123-456-789" ''' Dim maskLength As Integer = 7 ''' Dim leftToRight As Boolean = True ''' Dim allowedChars As Char() = "-".ToCharArray() ''' Dim maskChar As Char = "*"c ''' ''' Dim masked As SecureString = MaskSecureString(serialKey, maskLength, leftToRight, allowedChars, maskChar) ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="input"> ''' The string to mask. ''' </param> ''' ''' <param name="maskLength"> ''' The length of the mask. ''' </param> ''' ''' <param name="leftToRight"> ''' Indicates the direction of the mask (left to right or right to left). ''' </param> ''' ''' <param name="allowedChars"> ''' An array of characters that are allowed to remain unmasked. ''' </param> ''' ''' <param name="maskCharacter"> ''' The character used for masking (default: "*"). ''' </param> ''' ---------------------------------------------------------------------------------------------------- ''' <returns> ''' The masked string. ''' </returns> ''' ---------------------------------------------------------------------------------------------------- <DebuggerStepperBoundary> Public Shared Function MaskSecureString(input As String, maskLength As Integer, leftToRight As Boolean, allowedChars As Char(), Optional maskCharacter As Char = "*"c) As SecureString If String.IsNullOrEmpty(input) Then Throw New ArgumentNullException(paramName:=NameOf(input)) End If If String.IsNullOrEmpty(maskCharacter) Then Throw New ArgumentNullException(paramName:=NameOf(maskCharacter)) End If If maskLength <= 0 Then Throw New ArgumentException($"maskLength must be greather than zero.", paramName:=NameOf(maskLength)) End If Dim valueLength As Integer = input.Length If maskLength > valueLength Then Throw New ArgumentException($"maskLength can't be greather than the source string length.", paramName:=NameOf(maskLength)) End If Dim allowedCharIndices As IDictionary(Of Integer, Char) = Nothing If allowedChars IsNot Nothing AndAlso allowedChars.Length > 0 Then allowedCharIndices = New Dictionary(Of Integer, Char ) Dim startPos As Integer Dim endPos As Integer If maskLength = valueLength Then ' Full mask. startPos = 0 endPos = valueLength - 1 Else If leftToRight Then ' Left to right mask. startPos = 0 endPos = maskLength - 1 Else ' Right to left mask. startPos = valueLength - maskLength endPos = valueLength - 1 End If End If For i As Integer = startPos To endPos Dim c As Char = input(i) If allowedChars.Contains(c) Then allowedCharIndices.Add(i, c) End If Next End If Dim sec As New SecureString() If maskLength = valueLength Then ' Full mask. For i As Integer = 0 To valueLength Dim dictValue As Char = Nothing If allowedCharIndices IsNot Nothing AndAlso allowedCharIndices.TryGetValue(i, dictValue) Then sec.AppendChar(dictValue) Continue For End If sec.AppendChar(maskCharacter) Next Else If leftToRight Then ' Left to right mask. For i As Integer = 0 To maskLength - 1 Dim dictValue As Char = Nothing If allowedCharIndices IsNot Nothing AndAlso allowedCharIndices.TryGetValue(i, dictValue) Then sec.AppendChar(dictValue) Continue For End If sec.AppendChar(maskCharacter) Next For i As Integer = maskLength To valueLength - 1 sec.AppendChar(input(i)) Next Else ' Right to left mask. For i As Integer = 0 To valueLength - maskLength - 1 sec.AppendChar(input(i)) Next For i As Integer = valueLength - maskLength To valueLength - 1 Dim dictValue As Char = Nothing If allowedCharIndices IsNot Nothing AndAlso allowedCharIndices.TryGetValue(i, dictValue) Then sec.AppendChar(dictValue) Continue For End If sec.AppendChar(maskCharacter) Next End If End If Return sec End Function ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Masks the source string with a specific character. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example. ''' <code language="VB.NET"> ''' Dim secureStr As New SecureString() ''' With secureStr ''' .AppendChar("p"c) ''' .AppendChar("a"c) ''' .AppendChar("s"c) ''' .AppendChar("s"c) ''' .AppendChar("w"c) ''' .AppendChar("o"c) ''' .AppendChar("r"c) ''' .AppendChar("d"c) ''' End With ''' ''' Dim maskChar As Char = "*"c ''' Dim masked As SecureString = MaskSecureString(secureStr, maskChar) ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="value"> ''' The string to mask. ''' </param> ''' ''' <param name="maskCharacter"> ''' Optional. The character used for masking (default: "*"). ''' </param> ''' ---------------------------------------------------------------------------------------------------- ''' <returns> ''' The masked string. ''' </returns> ''' ---------------------------------------------------------------------------------------------------- <DebuggerStepperBoundary> Public Shared Function MaskSecureString(value As SecureString, Optional maskCharacter As Char = "*"c) As SecureString Return MaskSecureString(value, maskLength:=value.Length, leftToRight:=True, allowedChars:=Nothing, maskCharacter) End Function ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Masks the source string with a specific character, ''' allowing certain characters to remain unmasked. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example. ''' <code language="VB.NET"> ''' Dim serialKey As New SecureString() ''' With serialKey ''' .AppendChar("1"c) ''' .AppendChar("2"c) ''' .AppendChar("3"c) ''' .AppendChar("-"c) ''' .AppendChar("4"c) ''' .AppendChar("5"c) ''' .AppendChar("6"c) ''' .AppendChar("-"c) ''' .AppendChar("7"c) ''' .AppendChar("8"c) ''' .AppendChar("9"c) ''' End With ''' ''' Dim allowedChars As Char() = "-".ToCharArray() ''' Dim maskChar As Char = "*"c ''' ''' Dim masked As SecureString = MaskSecureString(serialKey, allowedChars, maskChar) ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="value"> ''' The string to mask. ''' </param> ''' ''' <param name="allowedChars"> ''' An array of characters that are allowed to remain unmasked. ''' </param> ''' ''' <param name="maskCharacter"> ''' The character used for masking (default: "*"). ''' </param> ''' ---------------------------------------------------------------------------------------------------- ''' <returns> ''' The masked string. ''' </returns> ''' ---------------------------------------------------------------------------------------------------- <DebuggerStepperBoundary> Public Shared Function MaskSecureString(value As SecureString, allowedChars As Char(), Optional maskCharacter As Char = "*"c) As SecureString Return MaskSecureString(value, maskLength:=value.Length, leftToRight:=True, allowedChars:=allowedChars, maskCharacter) End Function ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Partially masks the source string with a specific character. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example. ''' <code language="VB.NET"> ''' Dim serialKey As New SecureString() ''' With serialKey ''' .AppendChar("1"c) ''' .AppendChar("2"c) ''' .AppendChar("3"c) ''' .AppendChar("-"c) ''' .AppendChar("4"c) ''' .AppendChar("5"c) ''' .AppendChar("6"c) ''' .AppendChar("-"c) ''' .AppendChar("7"c) ''' .AppendChar("8"c) ''' .AppendChar("9"c) ''' End With ''' ''' Dim maskLength As Integer = 7 ''' Dim leftToRight As Boolean = True ''' Dim maskChar As Char = "*"c ''' ''' Dim masked As SecureString = MaskSecureString(serialKey, maskLength, leftToRight, maskChar) ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="value"> ''' The string to mask. ''' </param> ''' ''' <param name="maskLength"> ''' The length of the mask. ''' </param> ''' ''' <param name="leftToRight"> ''' Indicates the direction of the mask (left to right or right to left). ''' </param> ''' ''' <param name="maskCharacter"> ''' The character used for masking (default: "*"). ''' </param> ''' ---------------------------------------------------------------------------------------------------- ''' <returns> ''' The masked string. ''' </returns> ''' ---------------------------------------------------------------------------------------------------- <DebuggerStepperBoundary> Public Shared Function MaskSecureString(value As SecureString, maskLength As Integer, leftToRight As Boolean, Optional maskCharacter As Char = "*"c) As SecureString Return MaskSecureString(value, maskLength:=maskLength, leftToRight:=leftToRight, allowedChars:=Nothing, maskCharacter) End Function ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Partially masks the source string with a specific character, ''' allowing certain characters to remain unmasked. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example. ''' <code language="VB.NET"> ''' Dim serialKey As New SecureString() ''' With serialKey ''' .AppendChar("1"c) ''' .AppendChar("2"c) ''' .AppendChar("3"c) ''' .AppendChar("-"c) ''' .AppendChar("4"c) ''' .AppendChar("5"c) ''' .AppendChar("6"c) ''' .AppendChar("-"c) ''' .AppendChar("7"c) ''' .AppendChar("8"c) ''' .AppendChar("9"c) ''' End With ''' ''' Dim maskLength As Integer = 7 ''' Dim leftToRight As Boolean = True ''' Dim allowedChars As Char() = "-".ToCharArray() ''' Dim maskChar As Char = "*"c ''' ''' Dim masked As SecureString = MaskSecureString(serialKey, maskLength, leftToRight, allowedChars, maskChar) ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="value"> ''' The string to mask. ''' </param> ''' ''' <param name="maskLength"> ''' The length of the mask. ''' </param> ''' ''' <param name="leftToRight"> ''' Indicates the direction of the mask (left to right or right to left). ''' </param> ''' ''' <param name="allowedChars"> ''' An array of characters that are allowed to remain unmasked. ''' </param> ''' ''' <param name="maskCharacter"> ''' The character used for masking (default: "*"). ''' </param> ''' ---------------------------------------------------------------------------------------------------- ''' <returns> ''' The masked string. ''' </returns> ''' ---------------------------------------------------------------------------------------------------- <DebuggerStepperBoundary> Public Shared Function MaskSecureString(value As SecureString, maskLength As Integer, leftToRight As Boolean, allowedChars As Char(), Optional maskCharacter As Char = "*"c) As SecureString Dim managedString As String = ToManagedString(value) Return MaskSecureString(managedString, maskLength:=maskLength, leftToRight:=leftToRight, allowedChars:=allowedChars, maskCharacter:=maskCharacter) End Function #End Region #Region " Private Methods " ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Converts the source <see cref="Global.System.Security.SecureString"/> to a managed <see cref="String"/>. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example. ''' <code language="VB.NET"> ''' Dim secStr As New SecureString() ''' With secStr ''' .AppendChar("q"c) ''' .AppendChar("w"c) ''' .AppendChar("e"c) ''' .AppendChar("r"c) ''' .AppendChar("t"c) ''' .AppendChar("y"c) ''' End With ''' ''' MessageBox.Show(secStr.ToManagedString()) ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="secureString"> ''' The source <see cref="Global.System.Security.SecureString"/>. ''' </param> ''' ---------------------------------------------------------------------------------------------------- ''' <returns> ''' The resulting <see cref="String"/>. ''' </returns> ''' ---------------------------------------------------------------------------------------------------- <DebuggerStepThrough> <EditorBrowsable(EditorBrowsableState.Never)> Private Shared Function ToManagedString(secureString As Global.System.Security.SecureString) As String If secureString Is Nothing Then Throw New ArgumentNullException(NameOf(secureString)) End If If secureString.Length = 0 Then Return "" Else Dim ptr As System.IntPtr = Global.System.IntPtr.Zero Try ptr = Marshal.SecureStringToGlobalAllocUnicode(secureString) Return Marshal.PtrToStringUni(ptr) Finally If ptr <> IntPtr.Zero Then Marshal.ZeroFreeGlobalAllocUnicode(ptr) End If End Try End If End Function #End Region End Class End Namespace #End Region
|
|
|
En línea
|
@%$& #$ %&#$, ¡hay que decirlo más!.
|
|
|
Elektro Enjuto
|
He escrito este simulador / generador de errores tipográficos en un string. No está muy pulido, pero es un comienzo de idea. Las reglas son las siguientes: ● The error-rate percentage calculation is done for the input text length, instead of throwing the dice for each character.
● Letters can only be replaced with different letters of the same case (upper-case or lower-case).
● Numbers can only be replaced with other (different) numbers.
● Special characters like punctuation and white-spaces will remain untouched. Ejemplo de uso: Dim inputText As String = "I possess the virtues of rapid and error-free typing. Through my precise keystrokes and unwavering focus, I consistently deliver written content efficiently and accurately. My typing speed is unparalleled, allowing me to swiftly transcribe thoughts into written form with remarkable velocity. Each keystroke is executed with precision, enabling me to maintain a consistent flow of text while adhering to the highest standards of accuracy. In addition to speed, my dedication to perfection ensures that typographical errors are virtually non-existent in my output. Meticulously reviewing each line of text, I meticulously detect and rectify any potential errors, guaranteeing a polished and professional final product. Whether it's crafting detailed reports, composing compelling articles, or engaging in fast-paced communication, my quick and error-free typing abilities empower me to meet deadlines with ease and precision. I take pride in my proficiency, knowing that it contributes to a seamless and efficient workflow. In summary, my virtuosity in fast and error-free typing is a testament to my commitment to professionalism and excellence. With swift keystrokes and unwavering accuracy, I offer a valuable asset for any task that demands efficiency, precision, and an impeccable attention to detail." Dim errorrate As Integer = 2 ' 2 percent of the total input text length. Dim letters As Boolean = True Dim numbers As Boolean = True Dim result As String = UtilString.GenerateTypos(inputText, errorrate, letters, numbers) Console.WriteLine(result)
Salida: Whether it's crafting detailed reports, composing yompelling articles, or engaging in fast-paced communication, my quick and error-free gyping abilities empower me to meet deadlines with ease and precusion. I take pride in my proriciency, knowing that it contributes to a seamless and efficient workflow.
In summary, my virtuosity in fast and error-free typing is a kestament to my commitment to professionalism and excellence. With fwift keystrokes and unwavering accuracy, I offer a valuable asset for eny task that demands efficiencv, precision, and an imxeccable attention to detail.
UtilString.vb' *********************************************************************** ' Author : ElektroStudios ' Modified : 14-July-2023 ' *********************************************************************** #Region " Public Members Summary " #Region " Functions " ' GenerateTypos(String, Integer, Boolean, Boolean) As String #End Region #End Region #Region " Option Statements " Option Strict On Option Explicit On Option Infer Off #End Region #Region " Imports " Imports System.Collections.Generic Imports System.Text Imports DevCase.Runtime.Numerics #End Region #Region " String Util " ' ReSharper disable once CheckNamespace Namespace DevCase.Core.DataProcessing.Common Partial Public NotInheritable Class UtilString #Region " Public Methods " ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Simulate random typographical errors in the input text, based on the specified error rate. ''' <para></para> ''' Rules: ''' <para></para> ''' ● The error-rate percentage calculation is done for the input text length, ''' instead of throwing the dice for each character. ''' <para></para> ''' ● Letters can only be replaced with different letters of the same case (upper-case or lower-case). ''' <para></para> ''' ● Numbers can only be replaced with different numbers. ''' <para></para> ''' ● Special characters like punctuation and white-spaces will remain untouched. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example. ''' <code language="VB.NET"> ''' Dim inputText As String = "I possess the virtues of rapid and error-free typing. Through my precise keystrokes and unwavering focus, I consistently deliver written content efficiently and accurately. ''' ''' My typing speed is unparalleled, allowing me to swiftly transcribe thoughts into written form with remarkable velocity. Each keystroke is executed with precision, enabling me to maintain a consistent flow of text while adhering to the highest standards of accuracy. ''' ''' In addition to speed, my dedication to perfection ensures that typographical errors are virtually non-existent in my output. Meticulously reviewing each line of text, I meticulously detect and rectify any potential errors, guaranteeing a polished and professional final product. ''' ''' Whether it's crafting detailed reports, composing compelling articles, or engaging in fast-paced communication, my quick and error-free typing abilities empower me to meet deadlines with ease and precision. I take pride in my proficiency, knowing that it contributes to a seamless and efficient workflow. ''' ''' In summary, my virtuosity in fast and error-free typing is a testament to my commitment to professionalism and excellence. With swift keystrokes and unwavering accuracy, I offer a valuable asset for any task that demands efficiency, precision, and an impeccable attention to detail." ''' ''' Dim errorrate As Integer = 2 ' 2 percent of the total input text length. ''' Dim letters As Boolean = True ''' Dim numbers As Boolean = True ''' ''' Dim result As String = GenerateTypos(inputText, errorrate, letters, numbers) ''' ''' Console.WriteLine(result) ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="input"> ''' The input text. ''' </param> ''' ''' <param name="errorRate"> ''' The error rate percentage. It must be in the range of 0 to 100. ''' <para></para> ''' Note: The error-rate percentage calculation is done for the input text length, ''' instead of throwing the dice for each character. ''' <para></para> ''' If this value is 0, no changes are made to the input text. ''' <para></para> ''' If error rate is too small for the length of the input text, it may not add any typos. ''' <para></para> ''' Suggested values can go between 1 to 5 percent. ''' Higher values will produce more typos, so more unrealistic simulations. ''' </param> ''' ''' <param name="letters"> ''' Optional. If true, allows to simulate random typographical errors in letters. Default value is True. ''' <para></para> ''' Note: Letters can only be replaced with different letters of the same case (upper-case or lower-case). ''' </param> ''' ''' <param name="numbers"> ''' Optional. If true, allows to simulate random typographical errors in numbers. Default value is True. ''' <para></para> ''' Note: Numbers can only be replaced with different numbers. ''' </param> ''' ---------------------------------------------------------------------------------------------------- ''' <returns> ''' The resulting text with random typographical errors added. ''' </returns> ''' ---------------------------------------------------------------------------------------------------- Public Shared Function GenerateTypos(input As String, errorRate As Integer, letters As Boolean, numbers As Boolean) As String If errorRate < 0 Or errorRate > 100 Then Throw New ArgumentException($"'{NameOf(errorRate)}' must be in the range of 0 to 100.") ElseIf errorRate = 0 Then Return input End If ' Get a proper input string length by replacing white-spaces ' to try produce a more realistic (smaller) error rate count. Dim charsToRemove As Char() = ",.´`+¡'!·$%&/()=?¿^;:¨*[]{}-_""".ToCharArray() Dim inputLength As Integer = InternalReplaceChars(input, charsToRemove, Nothing, StringComparison.OrdinalIgnoreCase, -1).Length ' Calculate the amount of typographical errors to generate in the source string. Dim typosCount As Integer = CInt(System.Math.Round(inputLength * errorRate / 100)) If typosCount = 0 Then typosCount = 1 End If Dim sb As New StringBuilder() Dim selectedIndices As New HashSet(Of Integer)() Dim validIndices As New List(Of Integer)() For i As Integer = 0 To input.Length - 1 Dim c As Char = input(i) If (letters AndAlso Char.IsLetter(c)) OrElse (numbers AndAlso Char.IsDigit(c)) Then validIndices.Add(i) End If Next If validIndices.Count = 0 Then Return input End If If validIndices.Count <= typosCount Then For i As Integer = 0 To input.Length - 1 Dim c As Char = input(i) Dim modifiedChar As Char = c If validIndices.Contains(i) AndAlso RandomNumberGenerator.Instance.Next(100) < errorRate Then If letters AndAlso Char.IsLetter(c) Then modifiedChar = RandomReplaceLetterOrDigit(c) ElseIf numbers AndAlso Char.IsDigit(c) Then modifiedChar = RandomReplaceLetterOrDigit(c) End If End If sb.Append(modifiedChar) Next Return sb.ToString() End If While selectedIndices.Count < typosCount Dim index As Integer = validIndices(RandomNumberGenerator.Instance.Next(validIndices.Count)) selectedIndices.Add(index) End While For i As Integer = 0 To input.Length - 1 Dim c As Char = input(i) Dim modifiedChar As Char = c If selectedIndices.Contains(i) Then If letters AndAlso Char.IsLetter(c) Then modifiedChar = RandomReplaceLetterOrDigit(c) ElseIf numbers AndAlso Char.IsDigit(c) Then modifiedChar = RandomReplaceLetterOrDigit(c) End If End If sb.Append(modifiedChar) Next Return sb.ToString() End Function #End Region #Region " Private Methods " ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Replaces text using the specified string comparison type. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <remarks> ''' Original source: ''' <see href="http://www.codeproject.com/Articles/10890/Fastest-C-Case-Insenstive-String-Replace?msg=1835929#xx1835929xx"/> ''' </remarks> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example. ''' <code language="VB.NET"> ''' Dim str As String = "Hello World!".Replace("Hd".ToCharArray(), "_", StringComparison.OrdinalIgnoreCase) ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="str"> ''' The source <see cref="String"/>. ''' </param> ''' ''' <param name="findWhat"> ''' The characters to find. ''' </param> ''' ''' <param name="replaceWith"> ''' The string to replace with. ''' </param> ''' ''' <param name="comparisonType"> ''' The string comparison type. ''' </param> ''' ''' <param name="stringBuilderCapacity"> ''' The initial buffer size of the <see cref="Stringbuilder"/>. ''' This parameter is reserved for testing purposes. ''' </param> ''' ---------------------------------------------------------------------------------------------------- ''' <returns> ''' The replaced string. ''' </returns> ''' ---------------------------------------------------------------------------------------------------- <DebuggerStepThrough> Private Shared Function InternalReplaceChars(str As String, findWhat As IEnumerable(Of Char), replaceWith As String, comparisonType As StringComparison, stringBuilderCapacity As Integer) As String Dim sb As New Global.System.Text.StringBuilder(capacity:=If(stringBuilderCapacity <= 0, System.Math.Min(4096, str.Length), stringBuilderCapacity)) Dim charFound As Boolean For Each c As Char In str For Each find As Char In findWhat If CStr(c).Equals(find, comparisonType) Then charFound = True Exit For End If Next If Not charFound Then sb.Append(c) Else sb.Append(replaceWith) charFound = False End If Next Return sb.ToString() End Function #End Region End Class End Namespace #End Region
UtilString.vb' *********************************************************************** ' Author : ElektroStudios ' Modified : 14-July-2023 ' *********************************************************************** #Region " Public Members Summary " #Region " Functions " ' RandomReplaceLetterOrDigit(Char) As Char #End Region #End Region #Region " Option Statements " Option Strict On Option Explicit On Option Infer Off #End Region #Region " Imports " Imports DevCase.Runtime.Numerics #End Region #Region " String Util " ' ReSharper disable once CheckNamespace Namespace DevCase.Core.DataProcessing.Common Partial Public NotInheritable Class UtilString #Region " Public Methods " ''' -------------------------------------------------------------------------------------------------- ''' <summary> ''' Replaces a letter or digit character with a random character of the same type based on these specific rules: ''' <para></para> ''' ● If the character is a digit ( <c>Char.IsDigit(character)</c> ), ''' the function returns a different digit from the range "0" to "9". ''' <para></para> ''' ● If the character is a letter ( <c>Char.IsLetter(character)</c> ): ''' <para></para> ''' - If it is a vowel, and it is upper-case, the function returns a different upper-case vowel. ''' <para></para> ''' - If it is a vowel, and it is lower-case, the function returns a different lower-case vowel. ''' <para></para> ''' - If it is a consonant, and it is upper-case, the function returns a different upper-case consonant. ''' <para></para> ''' - If it is a consonant, and it is lower-case, the function returns a different lower-case consonant. ''' <para></para> ''' ● If the character is neither a letter nor a digit, the function returns the same character. ''' </summary> ''' -------------------------------------------------------------------------------------------------- ''' <param name="character"> ''' The character to be replaced. ''' </param> ''' -------------------------------------------------------------------------------------------------- ''' <returns> ''' If the character is a letter or digit, returns a random character of the same type; ''' otherwise, returns the same character. ''' </returns> ''' -------------------------------------------------------------------------------------------------- <DebuggerStepThrough> Public Shared Function RandomReplaceLetterOrDigit(character As Char) As Char Dim availableChars As Char() If Char.IsDigit(character) Then availableChars = "0123456789".ToCharArray() ElseIf Char.IsLetter(character) Then availableChars = If(Char.IsUpper(character), If("AEIOU".Contains(character), "AEIOU".ToCharArray(), "BCDFGHJKLMNPQRSTVWXYZ".ToCharArray()), If("aeiou".Contains(character), "aeiou".ToCharArray(), "bcdfghjklmnpqrstvwxyz".ToCharArray())) Else Return character ' Throw New ArgumentException("The character is neither a letter nor a digit.", paramName:=NameOf(character)) End If Dim randomChar As Char Do randomChar = availableChars(RandomNumberGenerator.Instance.Next(availableChars.Length)) Loop While randomChar = character Return randomChar End Function #End Region End Class End Namespace #End Region
RandomNumberGenerator.vbhttps://foro.elhacker.net/net_c_vbnet_asp/libreria_de_snippets_para_vbnet_compartan_aqui_sus_snippets-t378770.0.html;msg2272581#msg2272581
|
|
|
En línea
|
@%$& #$ %&#$, ¡hay que decirlo más!.
|
|
|
Elektro Enjuto
|
Aquí les dejo una función para eliminar los tags html de un código html y dejar solo el texto, lo que se conoce como "html stripper". Se necesita la librería HtmlAgilityPack: https://www.nuget.org/packages/HtmlAgilityPack' *********************************************************************** ' Author : ElektroStudios ' Modified : 17-July-2023 ' *********************************************************************** #Region " Public Members Summary " #Region " Functions " ' StripHtml(String, String()) As String #End Region #End Region #Region " Option Statements " Option Strict On Option Explicit On Option Infer Off #End Region #Region " Imports " Imports System.Collections.Generic Imports System.Collections.ObjectModel Imports System.ComponentModel Imports System.Linq Imports HtmlAgilityPack #End Region #Region " HtmlAgilityPack Util " ' ReSharper disable once CheckNamespace Namespace DevCase.ThirdParty.HtmlAgilityPack ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Contains HtmlAgilityPack related utilities. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <remarks> ''' Note: Some functionalities of this assembly may require to install one or all of the listed NuGet packages: ''' <para></para> ''' <see href="https://www.nuget.org/packages/HtmlAgilityPack">HtmlAgilityPack</see> ''' </remarks> ''' ---------------------------------------------------------------------------------------------------- <ImmutableObject(True)> Public NotInheritable Class UtilHtmlAgilityPack #Region " Constructors " ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Prevents a default instance of the <see cref="UtilHtmlAgilityPack"/> class from being created. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <remarks> ''' Note: Some functionalities of this assembly may require to install one or all of the listed NuGet packages: ''' <para></para> ''' <see href="https://www.nuget.org/packages/HtmlAgilityPack">HtmlAgilityPack</see> ''' </remarks> ''' ---------------------------------------------------------------------------------------------------- <DebuggerNonUserCode> Private Sub New() End Sub #End Region #Region " Public Methods " ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Removes HTML tags from an html string and returns the content in plain text format. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <remarks> ''' Note: Some functionalities of this assembly may require to install one or all of the listed NuGet packages: ''' <para></para> ''' <seealso href="https://www.nuget.org/packages/HtmlAgilityPack">HtmlAgilityPack</seealso> ''' </remarks> ''' ---------------------------------------------------------------------------------------------------- ''' <seealso href="https://stackoverflow.com/a/12836974/1248295">Original C# algorithm</seealso> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example. ''' <code language="VB.NET"> ''' Dim html As String = ''' <![CDATA[ ''' <P style="MARGIN: 0cm 0cm 10pt" class=MsoNormal><SPAN style="LINE-HEIGHT: 115%; ''' FONT-FAMILY: 'Verdana','sans-serif'; COLOR: #333333; FONT-SIZE: 9pt">In an ''' email sent just three days before the Deepwater Horizon exploded, the onshore ''' <SPAN style="mso-bidi-font-weight: bold"><b>BP</b></SPAN> manager in charge of ''' the drilling rig warned his supervisor that last-minute procedural changes were ''' creating "chaos". April emails were given to government investigators by <SPAN ''' style="mso-bidi-font-weight: bold"><b>BP</b></SPAN> and reviewed by The Wall ''' Street Journal and are the most direct evidence yet that workers on the rig ''' were unhappy with the numerous changes, and had voiced their concerns to <SPAN ''' style="mso-bidi-font-weight: bold"><b>BP</b></SPAN>’s operations managers in ''' Houston. This raises further questions about whether <SPAN ''' style="mso-bidi-font-weight: bold"><b>BP</b></SPAN> managers properly ''' considered the consequences of changes they ordered on the rig, an issue ''' investigators say contributed to the disaster.</SPAN></p><br/> ''' ]]>.Value ''' ''' Dim allowedTags As String() = {"span", "b"} ''' Dim str As String = StripHtml(html, allowedTags) ''' Console.WriteLine(str) ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="html"> ''' The string that contains HTML tags. ''' </param> ''' ''' <param name="allowedTags"> ''' An optional list of allowed HTML tags that will not be removed from the string. ''' </param> ''' ---------------------------------------------------------------------------------------------------- ''' <returns> ''' The resulting plain text content without HTML tags. ''' </returns> ''' ---------------------------------------------------------------------------------------------------- <DebuggerStepThrough> Public Shared Function StripHtml(html As String, ParamArray allowedTags As String()) As String If String.IsNullOrEmpty(html) Then Return String.Empty End If Dim document As New HtmlDocument() document.LoadHtml(html) Dim nodes As New Queue(Of HtmlNode)(document.DocumentNode.SelectNodes("./*|./text()")) Do While nodes.Count > 0 Dim node As HtmlNode = nodes.Dequeue() Dim parentNode As HtmlNode = node.ParentNode If Not allowedTags.Contains(node.Name) AndAlso node.Name <> "#text" Then Dim childNodes As HtmlNodeCollection = node.SelectNodes("./*|./text()") If childNodes IsNot Nothing Then For Each child As HtmlNode In childNodes nodes.Enqueue(child) parentNode.InsertBefore(child, node) Next child End If parentNode.RemoveChild(node) End If Loop Return System.Net.WebUtility.HtmlDecode(document.DocumentNode.InnerHtml) End Function #End Region End Class End Namespace #End Region
|
|
|
En línea
|
@%$& #$ %&#$, ¡hay que decirlo más!.
|
|
|
Elektro Enjuto
|
Aquí les dejo una clase utiliratia para manipular el indexador de carpetas de Windows. Permite añadir y eliminar directorios, enumerar los directorios actuales, y buscar un directorio. Se necesita esta librería: https://www.nuget.org/packages/tlbimp-Microsoft.Search.InteropEjemplos de uso: Incluir un directorio: Dim directoryPath As String = "C:\Games\" SearchIndexerUtil.AddDirectoryRule(directoryPath, include:=True)
Eliminar el directorio: SearchIndexerUtil.RemoveDirectoryRule(directoryPath)
Comprobar si el directorio está incluído: Dim isIncluded As Boolean = SearchIndexerUtil.IsDirectoryIncluded(directoryPath) Debug. WriteLine($ "{NameOf(isIncluded)}: {isIncluded}")
Obtener los directorios incluídos: Dim rules As ReadOnlyCollection(Of CSearchScopeRule) = SearchIndexerUtil.GetDirectoryRules() For Each rule As CSearchScopeRuleClass In rules.Where(Function(x) x.IsDefault = 0) Debug. WriteLine($ "{NameOf(rule.PatternOrURL)}: {rule.PatternOrURL}") Debug. WriteLine($ "{NameOf(rule.IsIncluded)}: {rule.IsIncluded = 1}") Next
' *********************************************************************** ' Author : ElektroStudios ' Modified : 10-October-2022 ' *********************************************************************** #Region " Public Members Summary " #Region " Methods " ' AddDirectoryRule(String, Boolean) ' AddDirectoryRule(DirectoryInfo, Boolean) ' RemoveDirectoryRule(String) ' RemoveDirectoryRule(DirectoryInfo) ' GetDirectoryRules() As ReadOnlyCollection(Of CSearchScopeRule) ' FindDirectoryRule(String) As CSearchScopeRule ' FindDirectoryRule(DirectoryInfo) As CSearchScopeRule ' IsDirectoryIncluded(String) As Boolean ' IsDirectoryIncluded(DirectoryInfo) As Boolean #End Region #End Region #Region " Option Statements " Option Strict On Option Explicit On Option Infer Off #End Region #Region " Imports " Imports System.Collections.ObjectModel Imports System.IO Imports Microsoft.Search.Interop #End Region #Region " SearchIndexer Util " ' ReSharper disable once CheckNamespace Namespace DevCase.ThirdParty.MicrosoftSearchIndexer ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Contains Microsoft Search Indexer related utilities. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <remarks> ''' Note: Some functionalities of this assembly may require to install one or all of the listed NuGet packages: ''' <para></para> ''' <see href="https://www.nuget.org/packages/tlbimp-Microsoft.Search.Interop">tlbimp-Microsoft.Search.Interop by mamift</see> ''' </remarks> ''' ---------------------------------------------------------------------------------------------------- Public NotInheritable Class UtilSearchIndexer #Region " Private Fields " ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Provides methods for controlling the Search service. ''' <para></para> ''' This interface manages settings and objects that affect the search engine across catalogs. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <remarks> ''' Note: Some functionalities of this assembly may require to install one or all of the listed NuGet packages: ''' <para></para> ''' <see href="https://www.nuget.org/packages/tlbimp-Microsoft.Search.Interop">tlbimp-Microsoft.Search.Interop by mamift</see> ''' </remarks> ''' ---------------------------------------------------------------------------------------------------- Private Shared searchManager As CSearchManager ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Provides methods to manage a search catalog for purposes such as re-indexing or setting timeouts. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <remarks> ''' Note: Some functionalities of this assembly may require to install one or all of the listed NuGet packages: ''' <para></para> ''' <see href="https://www.nuget.org/packages/tlbimp-Microsoft.Search.Interop">tlbimp-Microsoft.Search.Interop by mamift</see> ''' </remarks> ''' ---------------------------------------------------------------------------------------------------- Private Shared catalogManager As CSearchCatalogManager ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Provides methods that notify the search engine of containers to crawl and/or watch, ''' and items under those containers to include or exclude when crawling or watching. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <remarks> ''' Note: Some functionalities of this assembly may require to install one or all of the listed NuGet packages: ''' <para></para> ''' <see href="https://www.nuget.org/packages/tlbimp-Microsoft.Search.Interop">tlbimp-Microsoft.Search.Interop by mamift</see> ''' </remarks> ''' ---------------------------------------------------------------------------------------------------- Private Shared scopeManager As CSearchCrawlScopeManager #End Region #Region " Constructors " ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Prevents a default instance of the <see cref="UtilSearchIndexer"/> class from being created. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <remarks> ''' Note: Some functionalities of this assembly may require to install one or all of the listed NuGet packages: ''' <para></para> ''' <see href="https://www.nuget.org/packages/tlbimp-Microsoft.Search.Interop">tlbimp-Microsoft.Search.Interop by mamift</see> ''' </remarks> ''' ---------------------------------------------------------------------------------------------------- <DebuggerNonUserCode> Private Sub New() End Sub #End Region #Region " Public Methods " ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Adds the specified directory path to Windows Search Index. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <remarks> ''' Documentation: <see href="https://learn.microsoft.com/en-us/windows/win32/api/searchapi/nf-searchapi-isearchcrawlscopemanager-adduserscoperule"/> ''' </remarks> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example. ''' <code language="VB.NET"> ''' Dim directoryPath As String = "C:\Games\" ''' SearchIndexerUtil.AddDirectoryRule(directoryPath, include:=True) ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="directoryPathOrPattern"> ''' The directory path (or a directory path pattern with wildcards) to be indexed. ''' </param> ''' ''' <param name="include"> ''' <see langword="True"/> if this directory should be included in all searches; ''' otherwise, <see langword="False"/>. ''' </param> ''' ---------------------------------------------------------------------------------------------------- <DebuggerStepThrough> Public Shared Sub AddDirectoryRule(directoryPathOrPattern As String, include As Boolean) UtilSearchIndexer.InitializeManagers() Dim uriPath As String = $"file:///{directoryPathOrPattern}" UtilSearchIndexer.scopeManager.AddUserScopeRule(uriPath, fInclude:=If(include, 1, 0), fOverrideChildren:=0, fFollowFlags:=Nothing) UtilSearchIndexer.scopeManager.SaveAll() End Sub ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Adds the specified directory path to Windows Search Index. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <remarks> ''' Documentation: <see href="https://learn.microsoft.com/en-us/windows/win32/api/searchapi/nf-searchapi-isearchcrawlscopemanager-adduserscoperule"/> ''' </remarks> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example. ''' <code language="VB.NET"> ''' Dim directory As New DirectoryInfo("C:\Games\") ''' SearchIndexerUtil.AddDirectoryRule(directory, include:=True) ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="directory"> ''' The directory path to be indexed. ''' </param> ''' ''' <param name="include"> ''' <see langword="True"/> if this directory should be included in all searches; ''' otherwise, <see langword="False"/>. ''' </param> ''' ---------------------------------------------------------------------------------------------------- <DebuggerStepThrough> Public Shared Sub AddDirectoryRule(directory As DirectoryInfo, include As Boolean) UtilSearchIndexer.AddDirectoryRule(directory.FullName, include) End Sub ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Removes the specified directory path from Windows Search Index. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <remarks> ''' Documentation: <see href="https://learn.microsoft.com/en-us/windows/win32/api/searchapi/nf-searchapi-isearchcrawlscopemanager-removescoperule"/> ''' </remarks> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example. ''' <code language="VB.NET"> ''' Dim directoryPath As String = "C:\Games\" ''' SearchIndexerUtil.RemoveDirectoryRule(directoryPath) ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="directoryPath"> ''' The directory path (or a directory path pattern with wildcards) to be deindexed. ''' </param> ''' ---------------------------------------------------------------------------------------------------- <DebuggerStepThrough> Public Shared Sub RemoveDirectoryRule(directoryPath As String) UtilSearchIndexer.InitializeManagers() Dim uriPath As String = $"file:///{directoryPath}" UtilSearchIndexer.scopeManager.RemoveScopeRule(uriPath) UtilSearchIndexer.scopeManager.SaveAll() End Sub ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Removes the specified directory path from Windows Search Index. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <remarks> ''' Documentation: <see href="https://learn.microsoft.com/en-us/windows/win32/api/searchapi/nf-searchapi-isearchcrawlscopemanager-removescoperule"/> ''' </remarks> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example. ''' <code language="VB.NET"> ''' Dim directory As New DirectoryInfo("C:\Games\") ''' SearchIndexerUtil.RemoveDirectoryRule(directory) ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="directory"> ''' The directory path to be deindexed. ''' </param> ''' ---------------------------------------------------------------------------------------------------- <DebuggerStepThrough> Public Shared Sub RemoveDirectoryRule(directory As DirectoryInfo) UtilSearchIndexer.RemoveDirectoryRule(directory.FullName) End Sub ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Returns all the directory rules in Windows Search Index. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <remarks> ''' Documentation: <see href="https://learn.microsoft.com/en-us/windows/win32/api/searchapi/nn-searchapi-ienumsearchscoperules"/> ''' </remarks> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example. ''' <code language="VB.NET"> ''' Dim rules As ReadOnlyCollection(Of CSearchScopeRule) = SearchIndexerUtil.GetDirectoryRules() ''' ''' For Each rule As CSearchScopeRuleClass In rules.Where(Function(x) x.IsDefault = 0) ''' Debug.WriteLine($"{NameOf(rule.PatternOrURL)}: {rule.PatternOrURL}") ''' Debug.WriteLine($"{NameOf(rule.IsIncluded)}: {rule.IsIncluded = 1}") ''' Debug.WriteLine("") ''' Next ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <returns> ''' The resulting directory rules. ''' </returns> ''' ---------------------------------------------------------------------------------------------------- <DebuggerStepThrough> Public Shared Function GetDirectoryRules() As ReadOnlyCollection(Of CSearchScopeRule) UtilSearchIndexer.InitializeManagers() Dim scopeEnumerator As CEnumSearchScopeRules = UtilSearchIndexer.scopeManager.EnumerateScopeRules() Dim fetched As UInteger Do Dim scopeRule As CSearchScopeRule = Nothing scopeEnumerator.Next(1, scopeRule, fetched) If fetched <> 0 Then Else Exit Do End If Loop End Function ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Finds a directory rule that matches the specified directory path in Windows Search Index. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <remarks> ''' Documentation: <see href="https://learn.microsoft.com/en-us/windows/win32/api/searchapi/nf-searchapi-isearchcrawlscopemanager-removescoperule"/> ''' </remarks> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example. ''' <code language="VB.NET"> ''' Dim directoryPath As String = "C:\Games\" ''' Dim rule As CSearchScopeRule = FindDirectoryRule(directoryPath) ''' ''' If rule IsNot Nothing Then ''' Debug.WriteLine($"{NameOf(rule.PatternOrURL)}: {rule.PatternOrURL}") ''' Debug.WriteLine($"{NameOf(rule.IsIncluded)}: {rule.IsIncluded = 1}") ''' End If ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="directoryPathOrPattern"> ''' The directory path (or a directory path pattern with wildcards) to find. ''' </param> ''' ---------------------------------------------------------------------------------------------------- ''' <returns> ''' The resulting directory rule, ''' or <see langword="Nothing"/> if does not exist a directory rule that matches the specified directory path. ''' </returns> ''' ---------------------------------------------------------------------------------------------------- <DebuggerStepThrough> Public Shared Function FindDirectoryRule(directoryPathOrPattern As String) As CSearchScopeRule Dim uriPath As String = $"file:///{directoryPathOrPattern}" Return UtilSearchIndexer.GetDirectoryRules().Where(Function(scope) scope.PatternOrURL = uriPath).SingleOrDefault() End Function ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Finds a directory rule that matches the specified directory path in Windows Search Index. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <remarks> ''' Documentation: <see href="https://learn.microsoft.com/en-us/windows/win32/api/searchapi/nf-searchapi-isearchcrawlscopemanager-removescoperule"/> ''' </remarks> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example. ''' <code language="VB.NET"> ''' Dim directory As New DirectoryInfo("C:\Games\") ''' Dim rule As CSearchScopeRule = FindDirectoryRule(directory) ''' ''' If rule IsNot Nothing Then ''' Debug.WriteLine($"{NameOf(rule.PatternOrURL)}: {rule.PatternOrURL}") ''' Debug.WriteLine($"{NameOf(rule.IsIncluded)}: {rule.IsIncluded = 1}") ''' End If ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="directory"> ''' The directory path to find. ''' </param> ''' ---------------------------------------------------------------------------------------------------- ''' <returns> ''' The resulting directory rule, ''' or <see langword="Nothing"/> if does not exist a directory rule that matches the specified directory path. ''' </returns> ''' ---------------------------------------------------------------------------------------------------- <DebuggerStepThrough> Public Shared Function FindDirectoryRule(directory As DirectoryInfo) As CSearchScopeRule Return UtilSearchIndexer.FindDirectoryRule(directory.FullName) End Function ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Returns a value indicating whether the specified directory path is included in Windows Search Index. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <remarks> ''' Documentation: <see href="https://learn.microsoft.com/en-us/windows/win32/api/searchapi/nf-searchapi-isearchcrawlscopemanager-includedincrawlscope"/> ''' </remarks> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example. ''' <code language="VB.NET"> ''' Dim directoryPath As String = "C:\Games\" ''' Dim isIncluded As Boolean = IsDirectoryIncluded(directoryPath) ''' ''' Debug.WriteLine($"{NameOf(isIncluded)}: {isIncluded}") ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="directoryPathOrPattern"> ''' The directory path (or a directory path pattern with wildcards) to find. ''' </param> ''' ---------------------------------------------------------------------------------------------------- ''' <returns> ''' <see langword="True"/> if the specified directory path is included in Windows Search Index; ''' otherwise, <see langword="False"/>. ''' </returns> ''' ---------------------------------------------------------------------------------------------------- <DebuggerStepThrough> Public Shared Function IsDirectoryIncluded(directoryPathOrPattern As String) As Boolean UtilSearchIndexer.InitializeManagers() Dim uriPath As String = $"file:///{directoryPathOrPattern}" Dim included As Integer = UtilSearchIndexer.scopeManager.IncludedInCrawlScope(uriPath) Return included = 1 End Function ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Returns a value indicating whether the specified directory path is included in Windows Search Index. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <remarks> ''' Documentation: <see href="https://learn.microsoft.com/en-us/windows/win32/api/searchapi/nf-searchapi-isearchcrawlscopemanager-includedincrawlscope"/> ''' </remarks> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example. ''' <code language="VB.NET"> ''' Dim directory As New DirectoryInfo("C:\Games\") ''' Dim isIncluded As Boolean = IsDirectoryIncluded(directory) ''' ''' Debug.WriteLine($"{NameOf(isIncluded)}: {isIncluded}") ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="directory"> ''' The directory path to find. ''' </param> ''' ---------------------------------------------------------------------------------------------------- ''' <returns> ''' <see langword="True"/> if the specified directory path is included in Windows Search Index; ''' otherwise, <see langword="False"/>. ''' </returns> ''' ---------------------------------------------------------------------------------------------------- <DebuggerStepThrough> Public Shared Function IsDirectoryIncluded(directory As DirectoryInfo) As Boolean Return UtilSearchIndexer.IsDirectoryIncluded(directory.FullName) End Function #End Region #Region " Private Methods " ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Initializes the value for <see cref="UtilSearchIndexer.searchManager"/>, ''' <see cref="UtilSearchIndexer.catalogManager"/> and ''' <see cref="UtilSearchIndexer.scopeManager"/> members. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <remarks> ''' Note: Some functionalities of this assembly may require to install one or all of the listed NuGet packages: ''' <para></para> ''' <see href="https://www.nuget.org/packages/tlbimp-Microsoft.Search.Interop">tlbimp-Microsoft.Search.Interop by mamift</see> ''' </remarks> ''' ---------------------------------------------------------------------------------------------------- <DebuggerStepThrough> Private Shared Sub InitializeManagers() If UtilSearchIndexer.searchManager Is Nothing Then UtilSearchIndexer.searchManager = New CSearchManager() End If If UtilSearchIndexer.catalogManager Is Nothing Then UtilSearchIndexer.catalogManager = DirectCast(searchManager.GetCatalog("SystemIndex"), CSearchCatalogManager) End If If UtilSearchIndexer.scopeManager Is Nothing Then UtilSearchIndexer.scopeManager = DirectCast(catalogManager.GetCrawlScopeManager(), CSearchCrawlScopeManager) End If End Sub #End Region End Class End Namespace #End Region
|
|
|
En línea
|
@%$& #$ %&#$, ¡hay que decirlo más!.
|
|
|
Elektro Enjuto
|
Aquí un código para generar las páginas de impresión (para la impresora) del contenido de un control DataGridView. Ejemplo de uso: Dim headerBackColor As Color = Color.Gray Dim headerForeColor As Color = Color.White Dim rowBackColor As Color = Color.LightGray Dim rowForeColor As Color = Color.LightGray Dim rowBackColorAlternate As Color = Color.WhiteSmoke Dim rowForeColorAlternate As Color = Color.WhiteSmoke Dim printDocument As PrintDocument = Me.DataGridView1.GetPrintDocument("Title", textFont:=New Font("Arial", 16), headerBackColor:=headerBackColor, headerForeColor:=headerForeColor, rowBackColor:=rowBackColor, rowForeColor:=rowForeColor, rowBackColorAlternate:=rowBackColorAlternate, rowForeColorAlternate:=rowForeColorAlternate) Dim printPreviewDialog As PrintPreviewDialog = PrintPreviewDialog1 printPreviewDialog.ShowDialog()
' *********************************************************************** ' Author : ElektroStudios ' Modified : 13-July-2023 ' *********************************************************************** #Region " Public Members Summary " ' DataGridView.GetPrintDocument(Opt: String, Opt: Font, Opt: Color, Opt: Color, Opt: Color, Opt: Color, Opt: Color, Opt: Color) As PrintDocument #End Region #Region " Option Statements " Option Strict On Option Explicit On Option Infer Off #End Region #Region " Imports " Imports System.Drawing.Printing Imports System.Runtime.CompilerServices #End Region #Region " DataGridView Extensions " ' ReSharper disable once CheckNamespace Namespace DevCase.Extensions.DataGridViewExtensions ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Contains custom extension methods to use with <see cref="DataGridView"/> control. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- <HideModuleName> Public Module DataGridViewExtensions #Region " Public Extension Methods " ''' ---------------------------------------------------------------------------------------------------- ''' <summary> ''' Generates a <see cref="PrintDocument"/> object for printing the contents of the source <see cref="DataGridView"/>. ''' </summary> ''' ---------------------------------------------------------------------------------------------------- ''' <example> This is a code example. ''' <code language="VB.NET"> ''' Dim headerBackColor As Color = Color.Gray ''' Dim headerForeColor As Color = Color.White ''' Dim rowBackColor As Color = Color.LightGray ''' Dim rowForeColor As Color = Color.LightGray ''' Dim rowBackColorAlternate As Color = Color.WhiteSmoke ''' Dim rowForeColorAlternate As Color = Color.WhiteSmoke ''' ''' Dim printDocument As PrintDocument = ''' Me.DataGridView1.GetPrintDocument("Title", textFont:=New Font("Arial", 16), ''' headerBackColor:=headerBackColor, headerForeColor:=headerForeColor, ''' rowBackColor:=rowBackColor, rowForeColor:=rowForeColor, ''' rowBackColorAlternate:=rowBackColorAlternate, rowForeColorAlternate:=rowForeColorAlternate) ''' ''' Dim printPreviewDialog As PrintPreviewDialog = PrintPreviewDialog1 ''' printPreviewDialog.ShowDialog() ''' </code> ''' </example> ''' ---------------------------------------------------------------------------------------------------- ''' <param name="dataGridView"> ''' The <see cref="DataGridView"/> to print. ''' </param> ''' ''' <param name="title"> ''' The title to be printed at the top of the document. ''' <para></para> ''' If not provided, the <see cref="DataGridView.Name"/> property value will be used as the title. ''' </param> ''' ''' <param name="textFont"> ''' Optional. The font to draw header and row texts. ''' <para></para> ''' If not provided, the <see cref="DataGridView.Font"/> property value will be used as the text font. ''' </param> ''' ''' <param name="headerBackColor"> ''' Optional. The background color of the header row. ''' <para></para> ''' If not provided, the default color is <see cref="Color.White"/>. ''' </param> ''' ''' <param name="headerForeColor"> ''' Optional. The text color of the header row. ''' <para></para> ''' If not provided, the default color is <see cref="Color.Black"/>. ''' </param> ''' ''' <param name="rowBackColor"> ''' Optional. The background color of the data rows. ''' <para></para> ''' If not provided, the default color is <see cref="Color.White"/>. ''' </param> ''' ''' <param name="rowForeColor"> ''' Optional. The text color of the data rows. ''' <para></para> ''' If not provided, the default color is <see cref="Color.Black"/>. ''' </param> ''' ''' <param name="rowBackColorAlternate"> ''' Optional. The background color of the alternate data rows. ''' <para></para> ''' If not provided, the default color is <see cref="Color.White"/>. ''' </param> ''' ''' <param name="rowForeColorAlternate"> ''' Optional. text color of the alternate data rows. ''' <para></para> ''' If not provided, the default color is <see cref="Color.Black"/>. ''' </param> ''' ---------------------------------------------------------------------------------------------------- ''' <returns> ''' A <see cref="PrintDocument"/> object for printing the contents of the source <see cref="DataGridView"/>. ''' </returns> ''' ---------------------------------------------------------------------------------------------------- <Extension> <DebuggerStepThrough> Public Function GetPrintDocument(dataGridView As DataGridView, Optional title As String = Nothing, Optional textFont As Font = Nothing, Optional headerBackColor As Color = Nothing, Optional headerForeColor As Color = Nothing, Optional rowBackColor As Color = Nothing, Optional rowForeColor As Color = Nothing, Optional rowBackColorAlternate As Color = Nothing, Optional rowForeColorAlternate As Color = Nothing) As PrintDocument If String.IsNullOrEmpty(title) Then title = dataGridView.Name End If If textFont Is Nothing Then textFont = dataGridView.Font End If If headerBackColor = Nothing Then headerBackColor = Color.White End If If headerForeColor = Nothing Then headerForeColor = Color.Black End If If rowBackColor = Nothing Then rowBackColor = Color.White End If If rowForeColor = Nothing Then rowForeColor = Color.Black End If If rowBackColorAlternate = Nothing Then rowBackColorAlternate = Color.White End If If rowForeColorAlternate = Nothing Then rowForeColorAlternate = Color.Black End If Dim currentPageIndex As Integer = 0 Dim printedRowsCount As Integer = 0 Dim printDocument As New PrintDocument() AddHandler printDocument.PrintPage, Sub(sender, e) Dim printAreaHeight As Integer = e.MarginBounds.Height Dim printAreaWidth As Integer = e.MarginBounds.Width Dim printAreaLeft As Integer = e.MarginBounds.Left Dim printAreaTop As Integer = e.MarginBounds.Top Dim headerHeight As Integer = dataGridView.ColumnHeadersHeight Dim rowHeight As Integer = dataGridView.Rows(0).Height Dim gridWidth As Integer = dataGridView.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) Dim gridLeft As Integer = printAreaLeft + (printAreaWidth - gridWidth) \ 2 Dim titleSize As SizeF = e.Graphics.MeasureString(title, textFont) Dim titleLeft As Integer = gridLeft Dim titleTop As Integer = printAreaTop - CInt(titleSize.Height) - 20 e.Graphics.DrawString(title, textFont, Brushes.Black, titleLeft, titleTop, New StringFormat() With {.Alignment = StringAlignment.Near}) Dim rowsPerPage As Integer = CInt(Math.Floor((printAreaHeight - headerHeight) / rowHeight)) Dim rowIndex As Integer = printedRowsCount Dim headerWidth As Integer = 0 For Each column As DataGridViewColumn In dataGridView.Columns headerWidth += column.Width Next Dim headerBounds As New Rectangle(gridLeft, printAreaTop + headerHeight, headerWidth, rowHeight) Using headerBackBrush As New SolidBrush(headerBackColor) e.Graphics.FillRectangle(headerBackBrush, headerBounds) For Each column As DataGridViewColumn In dataGridView.Columns Dim cellBounds As New Rectangle(headerBounds.Left, headerBounds.Top, column.Width, headerBounds.Height) Using headerTextBrush As New SolidBrush(headerForeColor) e.Graphics.DrawString(column.HeaderText, textFont, headerTextBrush, cellBounds, New StringFormat() With {.Alignment = StringAlignment.Center}) End Using headerBounds.X += column.Width Next End Using While rowIndex < dataGridView.Rows.Count AndAlso rowIndex < printedRowsCount + rowsPerPage Dim row As DataGridViewRow = dataGridView.Rows(rowIndex) Dim cellIndex As Integer = 0 Dim currentRowBackColor As Color Dim currentRowForeColor As Color If rowIndex Mod 2 = 0 Then currentRowBackColor = rowBackColor currentRowForeColor = rowForeColor Else currentRowBackColor = rowBackColorAlternate currentRowForeColor = rowForeColorAlternate End If While cellIndex < dataGridView.Columns.Count Dim cellBounds As New Rectangle(printAreaLeft + (gridLeft - dataGridView.Columns(cellIndex).Width), (printAreaTop + headerHeight + (rowIndex - printedRowsCount) * rowHeight) + headerBounds.Height * 2, dataGridView.Columns(cellIndex).Width, rowHeight) Using rowBackBrush As New SolidBrush(currentRowBackColor) e.Graphics.FillRectangle(rowBackBrush, cellBounds) End Using e.Graphics.DrawRectangle(Pens.LightGray, cellBounds) Using rowTextBrush As New SolidBrush(currentRowForeColor) e.Graphics.DrawString(row.Cells(cellIndex).FormattedValue.ToString(), textFont, rowTextBrush, cellBounds, New StringFormat()) End Using printAreaLeft += dataGridView.Columns(cellIndex).Width cellIndex += 1 End While printAreaLeft = e.MarginBounds.Left rowIndex += 1 End While If rowIndex < dataGridView.Rows.Count Then printedRowsCount = rowIndex e.HasMorePages = True Else printedRowsCount = 0 currentPageIndex = 0 e.HasMorePages = False End If End Sub Return printDocument End Function #End Region End Module End Namespace #End Region
|
|
|
En línea
|
@%$& #$ %&#$, ¡hay que decirlo más!.
|
|
|
|
Mensajes similares |
|
Asunto |
Iniciado por |
Respuestas |
Vistas |
Último mensaje |
|
|
Librería de Snippets en C/C++
« 1 2 3 4 »
Programación C/C++
|
z3nth10n
|
31
|
25,810
|
2 Agosto 2013, 17:13 pm
por 0xDani
|
|
|
[APORTE] [VBS] Snippets para manipular reglas de bloqueo del firewall de Windows
Scripting
|
Eleкtro
|
1
|
4,067
|
3 Febrero 2014, 20:19 pm
por Eleкtro
|
|
|
Librería de Snippets para Delphi
« 1 2 »
Programación General
|
crack81
|
15
|
21,045
|
25 Marzo 2016, 18:39 pm
por crack81
|
|
|
Una organización en Github para subir, proyectos, snippets y otros?
Sugerencias y dudas sobre el Foro
|
z3nth10n
|
0
|
3,065
|
21 Febrero 2017, 10:47 am
por z3nth10n
|
|
|
índice de la Librería de Snippets para VB.NET !!
.NET (C#, VB.NET, ASP)
|
Eleкtro
|
7
|
6,506
|
4 Julio 2018, 21:35 pm
por Eleкtro
|
|