1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
using System;
using System.Collections.Generic;
using System.Collections;
namespace Lextm.SharpSnmpLib.Mib
{
public class DisplayHint
{
private enum NumType {
dec,
hex,
oct,
bin,
str
}
private string _str;
private NumType _type;
private int _decimalPoints = 0;
public DisplayHint(string str)
{
_str = str;
if (str.StartsWith("d"))
{
_type = NumType.dec;
if (str.StartsWith("d-"))
{
_decimalPoints = Convert.ToInt32(str.Substring(2));
}
}
else if (str.StartsWith("o"))
{
_type = NumType.oct;
}
else if (str.StartsWith("h"))
{
_type = NumType.hex;
}
else if (str.StartsWith("b"))
{
_type = NumType.bin;
}
else
{
_type = NumType.str;
foreach (char c in str)
{
}
}
}
public override string ToString()
{
return _str;
}
internal object Decode(int i)
{
switch (_type)
{
case NumType.dec:
if (_decimalPoints == 0)
{
return i;
}
else
{
return i / Math.Pow(10.0, _decimalPoints);
}
case NumType.hex:
return System.Convert.ToString(i, 16);
case NumType.oct:
return System.Convert.ToString(i, 8);
case NumType.bin:
return System.Convert.ToString(i, 2);
default:
return null;
}
}
}
}
|