本文整理汇总了C#中TypeCode类的典型用法代码示例。如果您正苦于以下问题:C# TypeCode类的具体用法?C# TypeCode怎么用?C# TypeCode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeCode类属于命名空间,在下文中一共展示了TypeCode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FromTypeCode
// New function; not in original C++ file
/// <summary>
/// Convert system type code to a GDAL data type.
/// </summary>
public static DataType FromTypeCode(TypeCode typeCode)
{
switch(typeCode)
{
case TypeCode.Byte:
return DataType.GDT_Byte;
case TypeCode.Int16:
return DataType.GDT_Int16;
case TypeCode.UInt16:
return DataType.GDT_UInt16;
case TypeCode.Int32:
return DataType.GDT_Int32;
case TypeCode.UInt32:
return DataType.GDT_UInt32;
case TypeCode.Single:
return DataType.GDT_Float32;
case TypeCode.Double:
return DataType.GDT_Float64;
default:
return DataType.GDT_Unknown;
}
}
示例2: EvaluateNullable
public static object EvaluateNullable (object a, object b, TypeCode tc, ExpressionType et)
{
object o = null;
if (a == null || b == null) {
if (tc != TypeCode.Boolean) {
return null;
}
switch (et) {
case ExpressionType.And:
o = And (a, b);
break;
case ExpressionType.Or:
o = Or (a, b);
break;
case ExpressionType.ExclusiveOr:
o = ExclusiveOr (a, b);
break;
}
} else {
o = Evaluate (a, b, tc, et);
}
return Convert2Nullable (o, tc);
}
示例3: GetNumericConversionOrder
/// <summary>
/// Returns a numerical code of the size of a type. All types get both a horizontal
/// and vertical code. Types that are lower in both dimensions have implicit conversions
/// to types that are higher in both dimensions.
/// </summary>
internal static bool GetNumericConversionOrder(TypeCode code, out int x, out int y)
{
// implicit conversions:
// 0 1 2 3 4
// 0: U1 -> U2 -> U4 -> U8
// | | |
// v v v
// 1: I1 -> I2 -> I4 -> I8
// | |
// v v
// 2: R4 -> R8
switch (code) {
case TypeCode.Byte: x = 0; y = 0; break;
case TypeCode.UInt16: x = 1; y = 0; break;
case TypeCode.UInt32: x = 2; y = 0; break;
case TypeCode.UInt64: x = 3; y = 0; break;
case TypeCode.SByte: x = 0; y = 1; break;
case TypeCode.Int16: x = 1; y = 1; break;
case TypeCode.Int32: x = 2; y = 1; break;
case TypeCode.Int64: x = 3; y = 1; break;
case TypeCode.Single: x = 1; y = 2; break;
case TypeCode.Double: x = 2; y = 2; break;
default:
x = y = 0;
return false;
}
return true;
}
示例4: XmlAtomicValue
//-----------------------------------------------
// XmlAtomicValue constructors and methods
//-----------------------------------------------
internal XmlAtomicValue(XmlSchemaType xmlType, bool value)
{
if (xmlType == null) throw new ArgumentNullException(nameof(xmlType));
_xmlType = xmlType;
_clrType = TypeCode.Boolean;
_unionVal.boolVal = value;
}
示例5: NumberConversionRule
/// <param name="typeCode">The <see cref="TypeCode"/> that this <see cref="NumberConversionRule"/> attempts to convert to.</param>
public NumberConversionRule(TypeCode typeCode)
: base(TypePointers.StringType)
{
if ((typeCode == TypeCode.String) || (typeCode == TypeCode.DateTime))
{
throw new ArgumentException("datatype cannot be String or DateTime.", "typeCode");
}
TypeCode = typeCode;
numberFormatInfo = NumberFormatInfo.CurrentInfo;
switch (typeCode)
{
case TypeCode.Decimal:
NumberStyles = NumberStyles.Number;
break;
case TypeCode.Double:
case TypeCode.Single:
NumberStyles = NumberStyles.Float | NumberStyles.AllowThousands;
break;
case TypeCode.Byte:
case TypeCode.SByte:
case TypeCode.Int16:
case TypeCode.UInt16:
case TypeCode.Int32:
case TypeCode.UInt32:
case TypeCode.Int64:
case TypeCode.UInt64:
NumberStyles = NumberStyles.Integer;
break;
}
}
示例6: FunctionSystem
TypeCode _ReturnTypeCode; // the return type
/// <summary>
/// passed class name, function name, and args for evaluation
/// </summary>
public FunctionSystem(string c, string f, IExpr[] a, TypeCode type)
{
_Cls = c;
_Func = f;
_Args = a;
_ReturnTypeCode = type;
}
示例7: FormatOutput
/*
public static string FormatOutput(string valueToFormat,string format,
string dataType, string nullValue )
{
if (String.IsNullOrEmpty(format)) {
return valueToFormat;
}
if (String.IsNullOrEmpty(valueToFormat)) {
return nullValue;
}
TypeCode typeCode = TypeHelper.TypeCodeFromString(dataType);
return FormatItem(valueToFormat,format,typeCode,nullValue);
}
*/
// private static string FormatItem (string valueToFormat,string format,
// TypeCode typeCode,string nullValue)
static string FormatItem (string valueToFormat,string format,
TypeCode typeCode)
{
string retValue = String.Empty;
switch (typeCode) {
case TypeCode.Int16:
case TypeCode.Int32:
retValue = FormatIntegers (valueToFormat,format);
break;
case TypeCode.DateTime:
retValue = FormatDate(valueToFormat,format);
break;
case TypeCode.Boolean:
retValue = FormatBool (valueToFormat);
break;
case TypeCode.Decimal:
retValue = FormatDecimal (valueToFormat,format);
break;
case TypeCode.Double:
case TypeCode.Single:
break;
case TypeCode.String:
case TypeCode.Char:
retValue = valueToFormat;
break;
default:
retValue = valueToFormat;
break;
}
return retValue;
}
示例8: DataCenterValue
public DataCenterValue(string name, TypeCode typeCode, object value)
: this()
{
Name = name;
TypeCode = typeCode;
Value = value;
}
示例9: Translate
public static OleDbType Translate(TypeCode type)
{
switch (type)
{
case TypeCode.Char: return OleDbType.WChar;
case TypeCode.String: return OleDbType.WChar;
case TypeCode.DateTime: return OleDbType.DBTimeStamp;
case TypeCode.Decimal: return OleDbType.Decimal;
case TypeCode.Double: return OleDbType.Double;
case TypeCode.Byte: return OleDbType.UnsignedTinyInt;
case TypeCode.Int16: return OleDbType.SmallInt;
case TypeCode.Int32: return OleDbType.Integer;
case TypeCode.Int64: return OleDbType.BigInt;
case TypeCode.UInt16: return OleDbType.UnsignedSmallInt;
case TypeCode.UInt32: return OleDbType.UnsignedInt;
case TypeCode.UInt64: return OleDbType.UnsignedBigInt;
case TypeCode.SByte: return OleDbType.TinyInt;
case TypeCode.Single: return OleDbType.Single;
case TypeCode.Boolean: return OleDbType.Boolean;
case TypeCode.DBNull: return OleDbType.Empty;
case TypeCode.Empty: return OleDbType.Empty;
case TypeCode.Object: return OleDbType.Variant;
default: throw new NotImplementedException("Unknown Data Type");
}
}
示例10: DataGridViewCustomSorter
public DataGridViewCustomSorter(DataGridView dgv)
{
myDataGridView = dgv;
mySortTypeCode = Type.GetTypeCode(Type.GetType("System.String"));
ColumnIndex = 0;
OrderOfSort = SortOrder.None;
}
示例11: Convert
public Object Convert(Object value, TypeCode typeCode) {
if (value==null) {
throw new ArgumentNullException("value");
}
Contract.EndContractBlock();
return System.Convert.ChangeType(value, typeCode, CultureInfo.InvariantCulture);
}
示例12: GetType
public IType GetType(TypeCode typeCode)
{
switch (typeCode) {
case TypeCode.Empty:
return GetType(typeof(void));
case TypeCode.Object:
return GetType(typeof(object));
case TypeCode.DBNull:
return GetType(typeof(DBNull));
case TypeCode.Boolean:
return GetType(typeof(bool));
case TypeCode.Char:
return GetType(typeof(char));
case TypeCode.SByte:
return GetType(typeof(sbyte));
case TypeCode.Byte:
return GetType(typeof(byte));
case TypeCode.Int16:
return GetType(typeof(short));
case TypeCode.UInt16:
return GetType(typeof(ushort));
case TypeCode.Int32:
return GetType(typeof(int));
case TypeCode.UInt32:
return GetType(typeof(uint));
case TypeCode.Int64:
return GetType(typeof(long));
case TypeCode.UInt64:
return GetType(typeof(ulong));
case TypeCode.Single:
return GetType(typeof(float));
case TypeCode.Double:
return GetType(typeof(double));
case TypeCode.Decimal:
return GetType(typeof(decimal));
case TypeCode.DateTime:
return GetType(typeof(DateTime));
case TypeCode.String:
return GetType(typeof(string));
}
throw new KeyNotFoundException(typeCode.ToString());
}
示例13: UnBox
static double UnBox(object numeric, TypeCode typeCode)
{
switch (typeCode)
{
case TypeCode.Byte:
return (double)(Byte) numeric;
case TypeCode.SByte:
return (double)(SByte) numeric;
case TypeCode.UInt16:
return (double)(UInt16) numeric;
case TypeCode.UInt32:
return (double)(UInt32) numeric;
case TypeCode.UInt64:
return (double)(UInt64) numeric;
case TypeCode.Int16:
return (double)(Int16) numeric;
case TypeCode.Int32:
return (double)(Int32) numeric;
case TypeCode.Int64:
return (double)(Int64) numeric;
case TypeCode.Decimal:
return (double)(Decimal) numeric;
case TypeCode.Double:
return (double)(Double) numeric;
case TypeCode.Single:
return (double)(Single) numeric;
}
throw new InvalidCastException(string.Format("Cannot unbox typecode {0} to double", typeCode));
}
示例14: Expression
internal Expression(ReportDefn r, ReportLink p, String xNode, ExpressionType et) : base(r, p)
{
_Source = xNode;
_Type = TypeCode.Empty;
_ExpectedType = et;
_Expr = null;
}
示例15: DataCenterValueRaw
public DataCenterValueRaw(TypeCode typeCode, ushort key, uint value)
: this()
{
TypeCode = typeCode;
Key = key;
_value = value;
}