Shiny Donkey!
Shiny Donkey! Shiny Donkey! Shiny Donkey!
                  Fake Banner Ads!  Mini-Sites!  
    New Shiny Donkey Posts  more >>
JER
Rob Miller
Rob Miller
satishreddy
* BREAKING NEWS *  9 out of 10 two-headed Sasquatches recommend what The Rock is cookin' instead of shinydonkey.com

.NET
[reply]   

01/29/04 11:12 AM EST
posted by JER email web

I was capturing some data from the CIM repository & the numbers I was receiving were just huge, so I wanted to make sure no data was lost when I brought the data into scope. I had no clue what the max/min values of each type were, though, so I wrote the following code & thought it was worth sharing.
//Get all publicly available Type Codes (System.Int32, System.Char, etc.)
MemberInfo[] availableTypes = Type.GetType("System.TypeCode").GetFields();

Response.Write("<p style=\"font-family:Arial;font-size:9px\">");

//loop over each type & print all available fields
foreach(MemberInfo m in availableTypes){
	try{
		//Get all publicly accessible fields
		FieldInfo[] allFields = Type.GetType("System." + m.Name).GetFields();
		Response.Write("<br><br><b>" + m.Name + "</b>");
		foreach(FieldInfo f in allFields){
			Response.Write("<br>  " + f.Name + ": "
		+ Type.GetType("System." + m.Name).InvokeMember(f.Name,
		System.Reflection.BindingFlags.GetField,
		null,
		null,
		null).ToString());
		}
	} catch(Exception ex){
		Response.Write("<br><br>" + m.Name + " blew up: " + ex.Message);
	}
}
The preceding code produces the following results:



value__ blew up: Object reference not set to an instance of an object.

Empty
  Value:

Object

DBNull
  Value:

Boolean
  TrueString: True
  FalseString: False

Char
  MaxValue: ?
  MinValue:

SByte
  MaxValue: 127
  MinValue: -128

Byte
  MaxValue: 255
  MinValue: 0

Int16
  MaxValue: 32767
  MinValue: -32768

UInt16
  MaxValue: 65535
  MinValue:

Int32
  MaxValue: 2147483647
  MinValue: -2147483648

UInt32
  MaxValue: 4294967295
  MinValue: 0

Int64
  MaxValue: 9223372036854775807
  MinValue: -9223372036854775808

UInt64
  MaxValue: 18446744073709551615
  MinValue: 0

Single
  MinValue: -3.402823E+38
  Epsilon: 1.401298E-45
  MaxValue: 3.402823E+38
  PositiveInfinity: Infinity
  NegativeInfinity: -Infinity
  NaN: NaN

Double
  MinValue: -1.79769313486232E+308
  MaxValue: 1.79769313486232E+308
  Epsilon: 4.94065645841247E-324
  NegativeInfinity: -Infinity
  PositiveInfinity: Infinity
  NaN: NaN

Decimal
  Zero: 0
  One: 1
  MinusOne: -1
  MaxValue: 79228162514264337593543950335
  MinValue: -79228162514264337593543950335

DateTime
  MinValue: 1/1/0001 12:00:00 AM
  MaxValue: 12/31/9999 11:59:59 PM

String
  Empty:

 

Name

 registered? log in!

E-mail (optional)

Website (optional)

  

To ensure security, this site requires unregistered users to enter a verification code:
 
Your code is:  
Enter Code:   

Note: Only registered ShinyDonkey.com users can post images. Only administrators can delete images.

  

New messages disabled indefinitely due to SPAM.



"And remember, a shiny new donkey for whoever brings me the head of Colonel Montoya..."
e-mail webmaster