Originally Posted by
liljeberg94
Sorry, i'm noobish @ this could you please convert it to vb.net and i give u a cookie making machine

VB.NET:
Code:
Imports System
Imports System.Collections.Generic
Namespace PrivServerCommandSearch
''' <summary>
''' Encapsulates GM Commands, and has static/shared members available for adding, and searching
''' commands easily.
''' </summary>
''' 10/29/2008 4:01 PM
Friend Class Commands
Implements IEquatable(Of Commands)
#Region "Constructors"
''' <summary>
''' Initializes a new instance of the <see cref="Commands"/> class.
''' </summary>
''' <param name="command">The command.</param>
''' <param name="commandSyntax">The command syntax.</param>
''' <param name="gmLevel">The gm level.</param>
Public Sub New(command__1 As String, commandSyntax As String, gmLevel__2 As Integer)
Command = command__1
Syntax = commandSyntax
GMLevel = gmLevel__2
End Sub
''' <summary>
''' Initializes a new instance of the <see cref="Commands"/> class, with the GMLevel set to 0.
''' </summary>
''' <param name="command">The command.</param>
''' <param name="commandSyntax">The command syntax.</param>
Public Sub New(command As String, commandSyntax As String)
Me.New(command, commandSyntax, 0)
End Sub
#End Region
#Region "Fields and Properties"
Private Shared _commandList As List(Of Commands)
''' <summary>
''' Gets the command.
''' </summary>
''' <value>The command.</value>
Public Property Command() As String
Get
End Get
Private Set
End Set
End Property
''' <summary>
''' Gets the command syntax.
''' </summary>
''' <value>The syntax.</value>
Public Property Syntax() As String
Get
End Get
Private Set
End Set
End Property
''' <summary>
''' Gets the GM Level for this command.
''' </summary>
''' <value>The GM level.</value>
Public Property GMLevel() As Integer
Get
End Get
Private Set
End Set
End Property
''' <summary>
''' Gets the command list.
''' </summary>
''' <value>The command list.</value>
Public Shared ReadOnly Property CommandList() As List(Of Commands)
Get
If _commandList Is Nothing Then
_commandList = New List(Of Commands)()
End If
Return _commandList
End Get
End Property
#End Region
#Region "Search"
''' <summary>
''' Searches commands for the specified search string.
''' </summary>
''' <param name="searchString">The search string.</param>
''' <returns>A <see cref="System.Collections.Generic.List{T}"/> containing Commands
''' that match the search.
''' If <paramref name="searchString"/> is null or empty, returns null.</returns>
Public Shared Function Search(searchString As String) As List(Of Commands)
If String.IsNullOrEmpty(searchString) Then
Return Nothing
End If
Dim ret As New List(Of Commands)()
For Each c As Commands In CommandList
If c.Command.Contains(searchString) Then
ret.Add(c)
ElseIf c.Syntax.Contains(searchString) Then
ret.Add(c)
End If
Next
Return ret
End Function
''' <summary>
''' Searches commands for the specified search string.
''' </summary>
''' <param name="searchString">The search string.</param>
''' <param name="gmLevel">The GM Level to search for. This includes the provided level, and all levels below it.</param>
''' <returns>A <see cref="System.Collections.Generic.List{T}"/> containing Commands
''' that match the search.
''' If <paramref name="searchString"/> is null or empty, returns null.</returns>
Public Shared Function Search(searchString As String, gmLevel As Integer) As List(Of Commands)
If String.IsNullOrEmpty(searchString) Then
Return Nothing
End If
Dim ret As New List(Of Commands)()
For Each c As Commands In CommandList
If c.GMLevel > gmLevel Then
Continue For
End If
If c.Command.Contains(searchString) Then
ret.Add(c)
ElseIf c.Syntax.Contains(searchString) Then
ret.Add(c)
End If
Next
Return ret
End Function
''' <summary>
''' Searches commands for the specified search string.
''' </summary>
''' <param name="searchStrings">The search strings.</param>
''' <returns>A <see cref="System.Collections.Generic.List{T}"/> containing Commands
''' that match the search.</returns>
Public Shared Function Search(searchStrings As IEnumerable(Of String)) As List(Of Commands)
Dim ret As New List(Of Commands)()
For Each s As String In searchStrings
Dim tmp As List(Of Commands) = Search(s)
If tmp IsNot Nothing Then
For Each c As Commands In tmp
If Not ret.Contains(c) Then
ret.Add(c)
End If
Next
End If
Next
Return If(ret.Count = 0, Nothing, ret)
End Function
''' <summary>
''' Searches commands for the specified search string.
''' </summary>
''' <param name="searchStrings">The search strings.</param>
''' <param name="gmLevel">The GM Level to search for. This includes the provided level, and all levels below it.</param>
''' <returns>A <see cref="System.Collections.Generic.List{T}"/> containing Commands
''' that match the search.</returns>
Public Shared Function Search(searchStrings As IEnumerable(Of String), gmLevel As Integer) As List(Of Commands)
Dim ret As New List(Of Commands)()
For Each s As String In searchStrings
Dim tmp As List(Of Commands) = Search(s, gmLevel)
If tmp IsNot Nothing Then
For Each c As Commands In tmp
If Not ret.Contains(c) Then
ret.Add(c)
End If
Next
End If
Next
Return If(ret.Count = 0, Nothing, ret)
End Function
#End Region
#Region "Add"
''' <summary>
''' Adds the specified command.
''' </summary>
''' <param name="command">The command.</param>
Public Shared Sub Add(command As Commands)
If Not CommandList.Contains(command) Then
CommandList.Add(command)
End If
End Sub
''' <summary>
''' Adds the specified command.
''' </summary>
''' <param name="command">The command.</param>
''' <param name="commandSyntax">The command syntax.</param>
''' <param name="gmLevel">The GM level.</param>
Public Shared Sub Add(command As String, commandSyntax As String, gmLevel As Integer)
Add(New Commands(command, commandSyntax, gmLevel))
End Sub
''' <summary>
''' Adds the specified command.
''' </summary>
''' <param name="command">The command.</param>
''' <param name="commandSyntax">The command syntax.</param>
Public Shared Sub Add(command As String, commandSyntax As String)
Add(New Commands(command, commandSyntax))
End Sub
#End Region
#Region "Equality Members"
''' <summary>
''' Indicates whether the current object is equal to another object of the same type.
''' </summary>
''' <returns>
''' true if the current object is equal to the <paramref name="obj" /> parameter; otherwise, false.
''' </returns>
''' <param name="obj">An object to compare with this object.</param>
Public Function Equals(obj As Commands) As Boolean
If ReferenceEquals(Nothing, obj) Then
Return False
End If
If ReferenceEquals(Me, obj) Then
Return True
End If
Return Equals(obj.Command, Command) AndAlso obj.GMLevel = GMLevel AndAlso Equals(obj.Syntax, Syntax)
End Function
''' <summary>
''' Indicates whether the current object is equal to another object of the same type.
''' </summary>
''' <returns>
''' true if the current object is equal to the <paramref name="other" /> parameter; otherwise, false.
''' </returns>
''' <param name="other">An object to compare with this object.</param>
Private Function Equals(other As Commands) As Boolean Implements IEquatable(Of Commands).Equals
Return Equals(other)
End Function
''' <summary>
''' Determines whether the specified <see cref="T:System.Object" /> is equal to the current <see cref="T:System.Object" />.
''' </summary>
''' <returns>
''' true if the specified <see cref="T:System.Object" /> is equal to the current <see cref="T:System.Object" />; otherwise, false.
''' </returns>
''' <param name="obj">The <see cref="T:System.Object" /> to compare with the current <see cref="T:System.Object" />. </param>
''' <exception cref="T:System.NullReferenceException">The <paramref name="obj" /> parameter is null.</exception><filterpriority>2</filterpriority>
Public Overloads Overrides Function Equals(obj As Object) As Boolean
If ReferenceEquals(Nothing, obj) Then
Return False
End If
If ReferenceEquals(Me, obj) Then
Return True
End If
Return obj.[GetType]() = GetType(Commands) AndAlso Equals(DirectCast(obj, Commands))
End Function
''' <summary>
''' Serves as a hash function for a particular type.
''' </summary>
''' <returns>
''' A hash code for the current <see cref="T:System.Object" />.
''' </returns>
''' <filterpriority>2</filterpriority>
Public Overloads Overrides Function GetHashCode() As Integer
Dim result As Integer = (If(Command IsNot Nothing, Command.GetHashCode(), 0))
result = (result * 397) Xor GMLevel
result = (result * 397) Xor (If(Syntax IsNot Nothing, Syntax.GetHashCode(), 0))
Return result
End Function
Public Shared Operator =(left As Commands, right As Commands) As Boolean
Return Equals(left, right)
End Operator
Public Shared Operator <>(left As Commands, right As Commands) As Boolean
Return Not Equals(left, right)
End Operator
#End Region
#Region "ToString Override"
''' <summary>
''' Returns a <see cref="T:System.String" /> that represents the current <see cref="T:System.Object" />.
''' </summary>
''' <returns>
''' A <see cref="T:System.String" /> that represents the current <see cref="T:System.Object" />.
''' </returns>
''' <filterpriority>2</filterpriority>
Public Overloads Overrides Function ToString() As String
Return String.Format("Command: {0} - Syntax: {1} - GM Level: {2}", Command, Syntax, GMLevel)
End Function
#End Region
End Class
Public Class CommandExampleClass
Public Shared Sub Test()
Commands.Add(".gmlist", "Shows Gm's Online")
Commands.Add(".acct", "Checks Your Account Gm Level.")
Dim foundCommands As List(Of Commands) = Commands.Search("list")
For Each command As Commands In foundCommands
' Will output: Command: .gmlist - Syntax: Shows Gm's Online - GM Level: 0
Console.WriteLine(command.ToString())
Next
End Sub
End Class
End Namespace
Preferred (C#):
Code:
using System;
using System.Collections.Generic;
namespace PrivServerCommandSearch
{
/// <summary>
/// Encapsulates GM Commands, and has static/shared members available for adding, and searching
/// commands easily.
/// </summary>
/// 10/29/2008 4:01 PM
internal class Commands : IEquatable<Commands>
{
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="Commands"/> class.
/// </summary>
/// <param name="command">The command.</param>
/// <param name="commandSyntax">The command syntax.</param>
/// <param name="gmLevel">The gm level.</param>
public Commands(string command, string commandSyntax, int gmLevel)
{
Command = command;
Syntax = commandSyntax;
GMLevel = gmLevel;
}
/// <summary>
/// Initializes a new instance of the <see cref="Commands"/> class, with the GMLevel set to 0.
/// </summary>
/// <param name="command">The command.</param>
/// <param name="commandSyntax">The command syntax.</param>
public Commands(string command, string commandSyntax) : this(command, commandSyntax, 0) {}
#endregion
#region Fields and Properties
private static List<Commands> _commandList;
/// <summary>
/// Gets the command.
/// </summary>
/// <value>The command.</value>
public string Command { get; private set; }
/// <summary>
/// Gets the command syntax.
/// </summary>
/// <value>The syntax.</value>
public string Syntax { get; private set; }
/// <summary>
/// Gets the GM Level for this command.
/// </summary>
/// <value>The GM level.</value>
public int GMLevel { get; private set; }
/// <summary>
/// Gets the command list.
/// </summary>
/// <value>The command list.</value>
public static List<Commands> CommandList
{
get
{
if (_commandList == null)
{
_commandList = new List<Commands>();
}
return _commandList;
}
}
#endregion
#region Search
/// <summary>
/// Searches commands for the specified search string.
/// </summary>
/// <param name="searchString">The search string.</param>
/// <returns>A <see cref="System.Collections.Generic.List{T}"/> containing Commands
/// that match the search.
/// If <paramref name="searchString"/> is null or empty, returns null.</returns>
public static List<Commands> Search(string searchString)
{
if (string.IsNullOrEmpty(searchString))
{
return null;
}
List<Commands> ret = new List<Commands>();
foreach (Commands c in CommandList)
{
if (c.Command.Contains(searchString))
{
ret.Add(c);
}
else if (c.Syntax.Contains(searchString))
{
ret.Add(c);
}
}
return ret;
}
/// <summary>
/// Searches commands for the specified search string.
/// </summary>
/// <param name="searchString">The search string.</param>
/// <param name="gmLevel">The GM Level to search for. This includes the provided level, and all levels below it.</param>
/// <returns>A <see cref="System.Collections.Generic.List{T}"/> containing Commands
/// that match the search.
/// If <paramref name="searchString"/> is null or empty, returns null.</returns>
public static List<Commands> Search(string searchString, int gmLevel)
{
if (string.IsNullOrEmpty(searchString))
{
return null;
}
List<Commands> ret = new List<Commands>();
foreach (Commands c in CommandList)
{
if (c.GMLevel > gmLevel)
{
continue;
}
if (c.Command.Contains(searchString))
{
ret.Add(c);
}
else if (c.Syntax.Contains(searchString))
{
ret.Add(c);
}
}
return ret;
}
/// <summary>
/// Searches commands for the specified search string.
/// </summary>
/// <param name="searchStrings">The search strings.</param>
/// <returns>A <see cref="System.Collections.Generic.List{T}"/> containing Commands
/// that match the search.</returns>
public static List<Commands> Search(IEnumerable<string> searchStrings)
{
List<Commands> ret = new List<Commands>();
foreach (string s in searchStrings)
{
List<Commands> tmp = Search(s);
if (tmp != null)
{
foreach (Commands c in tmp)
{
if (!ret.Contains(c))
{
ret.Add(c);
}
}
}
}
return ret.Count == 0
? null
: ret;
}
/// <summary>
/// Searches commands for the specified search string.
/// </summary>
/// <param name="searchStrings">The search strings.</param>
/// <param name="gmLevel">The GM Level to search for. This includes the provided level, and all levels below it.</param>
/// <returns>A <see cref="System.Collections.Generic.List{T}"/> containing Commands
/// that match the search.</returns>
public static List<Commands> Search(IEnumerable<string> searchStrings, int gmLevel)
{
List<Commands> ret = new List<Commands>();
foreach (string s in searchStrings)
{
List<Commands> tmp = Search(s, gmLevel);
if (tmp != null)
{
foreach (Commands c in tmp)
{
if (!ret.Contains(c))
{
ret.Add(c);
}
}
}
}
return ret.Count == 0
? null
: ret;
}
#endregion
#region Add
/// <summary>
/// Adds the specified command.
/// </summary>
/// <param name="command">The command.</param>
public static void Add(Commands command)
{
if (!CommandList.Contains(command))
{
CommandList.Add(command);
}
}
/// <summary>
/// Adds the specified command.
/// </summary>
/// <param name="command">The command.</param>
/// <param name="commandSyntax">The command syntax.</param>
/// <param name="gmLevel">The GM level.</param>
public static void Add(string command, string commandSyntax, int gmLevel)
{
Add(new Commands(command, commandSyntax, gmLevel));
}
/// <summary>
/// Adds the specified command.
/// </summary>
/// <param name="command">The command.</param>
/// <param name="commandSyntax">The command syntax.</param>
public static void Add(string command, string commandSyntax)
{
Add(new Commands(command, commandSyntax));
}
#endregion
#region Equality Members
/// <summary>
/// Indicates whether the current object is equal to another object of the same type.
/// </summary>
/// <returns>
/// true if the current object is equal to the <paramref name="obj" /> parameter; otherwise, false.
/// </returns>
/// <param name="obj">An object to compare with this object.</param>
public bool Equals(Commands obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
return Equals(obj.Command, Command) && obj.GMLevel == GMLevel && Equals(obj.Syntax, Syntax);
}
/// <summary>
/// Indicates whether the current object is equal to another object of the same type.
/// </summary>
/// <returns>
/// true if the current object is equal to the <paramref name="other" /> parameter; otherwise, false.
/// </returns>
/// <param name="other">An object to compare with this object.</param>
bool IEquatable<Commands>.Equals(Commands other)
{
return Equals(other);
}
/// <summary>
/// Determines whether the specified <see cref="T:System.Object" /> is equal to the current <see cref="T:System.Object" />.
/// </summary>
/// <returns>
/// true if the specified <see cref="T:System.Object" /> is equal to the current <see cref="T:System.Object" />; otherwise, false.
/// </returns>
/// <param name="obj">The <see cref="T:System.Object" /> to compare with the current <see cref="T:System.Object" />. </param>
/// <exception cref="T:System.NullReferenceException">The <paramref name="obj" /> parameter is null.</exception><filterpriority>2</filterpriority>
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
return obj.GetType() == typeof (Commands) && Equals((Commands) obj);
}
/// <summary>
/// Serves as a hash function for a particular type.
/// </summary>
/// <returns>
/// A hash code for the current <see cref="T:System.Object" />.
/// </returns>
/// <filterpriority>2</filterpriority>
public override int GetHashCode()
{
unchecked
{
int result = (Command != null
? Command.GetHashCode()
: 0);
result = (result * 397) ^ GMLevel;
result = (result * 397) ^ (Syntax != null
? Syntax.GetHashCode()
: 0);
return result;
}
}
public static bool operator ==(Commands left, Commands right)
{
return Equals(left, right);
}
public static bool operator !=(Commands left, Commands right)
{
return !Equals(left, right);
}
#endregion
#region ToString Override
/// <summary>
/// Returns a <see cref="T:System.String" /> that represents the current <see cref="T:System.Object" />.
/// </summary>
/// <returns>
/// A <see cref="T:System.String" /> that represents the current <see cref="T:System.Object" />.
/// </returns>
/// <filterpriority>2</filterpriority>
public override string ToString()
{
return string.Format("Command: {0} - Syntax: {1} - GM Level: {2}", Command, Syntax, GMLevel);
}
#endregion
}
public class CommandExampleClass
{
public static void Test()
{
Commands.Add(".gmlist", "Shows Gm's Online");
Commands.Add(".acct", "Checks Your Account Gm Level.");
List<Commands> foundCommands = Commands.Search("list");
foreach (Commands command in foundCommands)
{
Console.WriteLine(command.ToString());
// Will output: Command: .gmlist - Syntax: Shows Gm's Online - GM Level: 0
}
}
}
}
Enjoy.