IsLargerThan generic extension method for C# and VB.NET

This is the IsLargerThan generic extension method, this extension method which is part of the Fesslersoft.Extensions. It should only work with numeric values.

Samples

Sample C#

Sample VB.NET

If you have any questions or suggestions feel free to rate this snippet, post a comment or Contact Us via Email.

Related links:

Please rate this snippet

IsNull extension method for C# and VB.NET

You can use the IsNull Extension method by using the snippet below.

Sample C#

public static bool IsNull(this object source)
{
     return source == null;
}

Sample VB.NET

<System.Runtime.CompilerServices.Extension> _
Public Shared Function IsNull(source As Object) As Boolean
	Return source Is Nothing
End Function

As always, this extension method has been added to the Github Fesslersoft.Extensions Repository

Please rate this snippet

How to check if a number is a power of 2 in C# and VB.NET

To check if a number is a power of 2 in C# and VB.NET you can use the following extension method.

Sample C#

public static bool IsPowerOfTwo(this ulong input)
{
    return (input != 0) && ((input & (input - 1)) == 0);
}

Sample VB.NET

<System.Runtime.CompilerServices.Extension> _
Public Shared Function IsPowerOfTwo(input As ULong) As Boolean
	Return (input <> 0) AndAlso ((input And (input - 1)) = 0)
End Function

As always, the extension method was added to out Fesslersoft.Extensions library @Github

Please rate this snippet

How to check if a character is Uppercase in C# and VB.NET

To check if a character is Uppercase in C# and VB.NET you can use the following Extension Method

Sample C#

/// <summary>
///     Checks whether the character is an uppercase Character or not
/// </summary>
/// <param name="inputChar"></param>
/// <returns>True or False depending on the character</returns>
public static bool IsUpperCase(this char inputChar)
{
	return inputChar >= 'A' && inputChar <= 'Z';
}

Sample VB.NET

''' <summary>
'''     Checks whether the character is an uppercase Character or not
''' </summary>
''' <param name="inputChar"></param>
''' <returns>True or False depending on the character</returns>
<System.Runtime.CompilerServices.Extension> _
Public Shared Function IsUpperCase(inputChar As Char) As Boolean
	Return inputChar >= "A"C AndAlso inputChar <= "Z"C
End Function




Please rate this snippet

How to change the File extension in C# and VB.NET

To change the File extension in C# and VB.NET you can use the following snippet.

Sample C#

public static FileInfo ChangeExtension(FileInfo file, string newExtension)
{
	if (!newExtension.StartsWith("."))
	{
		newExtension = "." + newExtension;
	}
	var fileName = string.Concat(Path.GetFileNameWithoutExtension(file.FullName), newExtension);
	if (File.Exists(fileName))
	{
		File.Delete(fileName);
	}
	File.Move(file.FullName,fileName);
	if (File.Exists(fileName))
	{
		File.Delete(file.FullName);
	}
	return new FileInfo(fileName);
}

Sample VB.NET

Public Shared Function ChangeExtension(file__1 As FileInfo, newExtension As String) As FileInfo
	If Not newExtension.StartsWith(".") Then
		newExtension = Convert.ToString(".") & newExtension
	End If
	Dim fileName = String.Concat(Path.GetFileNameWithoutExtension(file__1.FullName), newExtension)
	If File.Exists(fileName) Then
		File.Delete(fileName)
	End If
	File.Move(file__1.FullName, fileName)
	If File.Exists(fileName) Then
		File.Delete(file__1.FullName)
	End If
	Return New FileInfo(fileName)
End Function

Please rate this snippet

Trim functions for Javascript

This snippet will give you the Trim functions for Javascript.

Sample Javascript

String.prototype.ltrim = function () {
    return this.replace(/^\s+/, '');
}

String.prototype.rtrim = function () {
    return this.replace(/\s+$/, '');
}

String.prototype.trim = function () {
    return this.ltrim().rtrim();
}

Please rate this snippet

IndexOf method for Javascript

With the snippet below you can use the IndexOf method for Javascript.

Sample JS

Array.prototype.IndexOf = Array.prototype.IndexOf || function (element) {
    for (var i=0; i < this.length; i++) {
        if(this[i] === element) return i;
    }
    return -1;
};

Please rate this snippet

Mid, Left, Right Extension Methods for C# and VB.NET

Here are three Extension Methods which let you use the Left, Mid and Right Methods from VB6 in C# and VB.NET. The Extension Methods simply wrap the on-board .NET Framework Method Substring. These Extension Methods are now part of the Fesslersoft.Extensions.

Samples

C# Sample

VB.NET Sample

Compatibility (as Extension method):
working .NET 2.0 working .NET 3.0 not tested .NET 3.5 not working .NET 4.0 not working .NET 4.5
Compatibility (Non-Extension method):
working .NET 2.0 working .NET 3.0 not tested .NET 3.5 not working .NET 4.0 not working .NET 4.5

If you have any questions or suggestions feel free to rate this snippet, post a comment or Contact Us via Email.

Related links:

Please rate this snippet