AT.MIN.Tools.FormatHex C# (CSharp) Method

FormatHex() private static method

private static FormatHex ( string NativeFormat, bool Alternate, int FieldLength, int FieldPrecision, bool Left2Right, char Padding, object Value ) : string
NativeFormat string
Alternate bool
FieldLength int
FieldPrecision int
Left2Right bool
Padding char
Value object
return string
		private static string FormatHex( string NativeFormat, bool Alternate,
											int FieldLength, int FieldPrecision,
											bool Left2Right,
											char Padding, object Value )
		{
			string w = String.Empty;
			string lengthFormat = "{0" + ( FieldLength != int.MinValue ?
											"," + ( Left2Right ?
													"-" :
													String.Empty ) + FieldLength.ToString() :
											String.Empty ) + "}";
			string numberFormat = "{0:" + NativeFormat + ( FieldPrecision != int.MinValue ?
											FieldPrecision.ToString() :
											String.Empty ) + "}";

			if ( IsNumericType( Value ) )
			{
				w = String.Format( numberFormat, Value );

				if ( Left2Right || Padding == ' ' )
				{
					if ( Alternate )
						w = ( NativeFormat == "x" ? "0x" : "0X" ) + w;
					w = String.Format( lengthFormat, w );
				}
				else
				{
					if ( FieldLength != int.MinValue )
						w = w.PadLeft( FieldLength - ( Alternate ? 2 : 0 ), Padding );
					if ( Alternate )
						w = ( NativeFormat == "x" ? "0x" : "0X" ) + w;
				}
			}

			return w;
		}
		#endregion