internal static ElementType GetElementType(TypeCode tc) { switch (tc) { case TypeCode.Boolean: //Booleans get treated as I4 in cil return ElementType.I4; case TypeCode.Single: return ElementType.R4; case TypeCode.Double: return ElementType.R8; case TypeCode.Char: return ElementType.Char; case TypeCode.Byte: return ElementType.U1; case TypeCode.SByte: return ElementType.I1; case TypeCode.Int16: return ElementType.I2; case TypeCode.UInt16: return ElementType.U2; case TypeCode.Int32: return ElementType.I4; case TypeCode.UInt32: return ElementType.U4; case TypeCode.Int64: return ElementType.I8; case TypeCode.UInt64: return ElementType.U8; default: throw new ArgumentException("tc"); } }
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; }
public EnumSerializer(Type enumType) { if (enumType == null) { throw new ArgumentNullException("enumType"); } this.enumType = enumType; this.typeCode = Type.GetTypeCode(enumType); switch(this.typeCode) { case TypeCode.Byte: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: case TypeCode.UInt16: case TypeCode.UInt32: case TypeCode.UInt64: case TypeCode.SByte: break; default: throw new NotSupportedException(); } }
internal Expression(ReportDefn r, ReportLink p, String xNode, ExpressionType et) : base(r, p) { _Source = xNode; _Type = TypeCode.Empty; _ExpectedType = et; _Expr = null; }
public static string ConvertType(TypeCode typeCode) { switch (typeCode) { case TypeCode.Boolean: return "Boolean"; case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: case TypeCode.DateTime: return "Number"; case TypeCode.Char: case TypeCode.String: return "String"; case TypeCode.Empty: case TypeCode.Object: case TypeCode.DBNull: default: return "Null"; } }
// 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; } }
public Object Convert(Object value, TypeCode typeCode) { if (value==null) { throw new ArgumentNullException("value"); } Contract.EndContractBlock(); return System.Convert.ChangeType(value, typeCode, CultureInfo.InvariantCulture); }
public DynamicExpression(Report rpt, ReportLink p, string expr, Row row) { _Source=expr; _Expr = null; _rl = p; _Type = DoParse(rpt); }
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"); } }
/// <summary> /// Convert from value /// </summary> /// <param name="enumType"></param> /// <param name="p"></param> /// <param name="numberStyles"></param> public static object ConvertToNumeric(TypeCode dataTypeCode, string value, int numberBase) { Type dataType = FactoryStandardType.Get(dataTypeCode); MethodInfo mi = typeof(Convert).GetMethod(NameOfConvertToMethodNumeric(dataTypeCode), new Type[] { typeof(string), typeof(int) }); return mi.Invoke(dataType, new object[] { value, numberBase }); }
internal RuntimeType(RuntimeTypeHandle handle) { this.handle = handle; typeStruct = (MetadataTypeStruct*)((uint**)&handle)[0]; assemblyQualifiedName = Mosa.Runtime.Internal.InitializeMetadataString(typeStruct->Name); // TODO name = Mosa.Runtime.Internal.InitializeMetadataString(typeStruct->Name); // TODO @namespace = Mosa.Runtime.Internal.InitializeMetadataString(typeStruct->Name); // TODO fullname = Mosa.Runtime.Internal.InitializeMetadataString(typeStruct->Name); typeCode = (TypeCode)(typeStruct->Attributes >> 24); attributes = (TypeAttributes)(typeStruct->Attributes & 0x00FFFFFF); // Declaring Type if (typeStruct->DeclaringType != null) { RuntimeTypeHandle declaringHandle = new RuntimeTypeHandle(); ((uint**)&declaringHandle)[0] = (uint*)typeStruct->DeclaringType; declaringTypeHandle = declaringHandle; } // Element Type if ((*typeStruct).ElementType != null) { RuntimeTypeHandle elementHandle = new RuntimeTypeHandle(); ((uint**)&elementHandle)[0] = (uint*)typeStruct->ElementType; elementTypeHandle = elementHandle; } }
/* 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; }
public DataCenterValue(string name, TypeCode typeCode, object value) : this() { Name = name; TypeCode = typeCode; Value = value; }
//----------------------------------------------- // 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; }
public DataGridViewCustomSorter(DataGridView dgv) { myDataGridView = dgv; mySortTypeCode = Type.GetTypeCode(Type.GetType("System.String")); ColumnIndex = 0; OrderOfSort = SortOrder.None; }
private WireType GetWireType(TypeCode code, DataFormat format, ref Type type, out int modelKey) { modelKey = -1; if (type.IsEnum) return WireType.None; switch (code) { case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: case TypeCode.UInt16: case TypeCode.UInt32: case TypeCode.UInt64: case TypeCode.Boolean: case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Char: return WireType.Variant; case TypeCode.Double: return WireType.Fixed64; case TypeCode.Single: return WireType.Fixed32; case TypeCode.String: case TypeCode.DateTime: case TypeCode.Decimal: return WireType.String; } if (type == typeof(byte[]) || type == typeof(TimeSpan) || type == typeof(Guid) || type == typeof(Uri)) return WireType.String; if ((modelKey = GetKey(ref type)) >= 0) { return WireType.String; } return WireType.None; }
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)); }
string _UniqueName; // unique name of expression; not always created internal Expression(ReportDefn r, ReportLink p, XmlNode xNode, ExpressionType et) : base(r, p) { _Source=xNode.InnerText; _Type = TypeCode.Empty; _ExpectedType = et; _Expr = null; }
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()); }
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); }
public DataCenterValueRaw(TypeCode typeCode, ushort key, uint value) : this() { TypeCode = typeCode; Key = key; _value = value; }
/// <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; }
/// <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; } }
public object Convert(object value, TypeCode typeCode) { if (value == null) { throw new ArgumentNullException("value"); } return System.Convert.ChangeType(value, typeCode, CultureInfo.InvariantCulture); }
public IDocumentIndex Add(string name, int value) { PrepareForIndexing(); _name = name; _intValue = value; _typeCode = TypeCode.Int32; IsDirty = true; return this; }
public IDocumentIndex Add(string name, double value) { PrepareForIndexing(); _name = name; _doubleValue = value; _typeCode = TypeCode.Single; IsDirty = true; return this; }
public LuceneDocumentIndex(int documentId, Localizer t) { Fields = new List<AbstractField>(); SetContentItemId(documentId); IsDirty = false; _typeCode = TypeCode.Empty; T = t; }
public IDocumentIndex Add(string name, string value) { PrepareForIndexing(); _name = name; _stringValue = value; _typeCode = TypeCode.String; IsDirty = true; return this; }
/// <summary> /// Initialize a new instance of the EvalNodeLiteral class. /// </summary> /// <param name="type">Type of the literal contained.</param> /// <param name="value">Actual literal value.</param> /// <param name="language">Language used for evaluation.</param> public EvalNodeLiteral(TypeCode type, object value, Language language) { _type = type; _value = value; _language = language; }
/// <summary> /// /// </summary> public ParameterDefine( string name, TypeCode typeCode, string conveter) { // TODO: 2010-07-29 add converterName // this.Name = name; this.TypeCode = typeCode; this.ConverterName = conveter; }
internal TypeData(Type type) { Type = type; TypeCode = Type.GetTypeCode(type); Size = TypeCode == TypeCode.Object ? default(byte) : TypeCode.Size(); }
internal void InitCustomAttributeBuilder(ConstructorInfo con, Object[] constructorArgs, PropertyInfo[] namedProperties, Object[] propertyValues, FieldInfo[] namedFields, Object[] fieldValues) { if (con == null) { throw new ArgumentNullException("con"); } if (constructorArgs == null) { throw new ArgumentNullException("constructorArgs"); } if (namedProperties == null) { throw new ArgumentNullException("namedProperties"); } if (propertyValues == null) { throw new ArgumentNullException("propertyValues"); } if (namedFields == null) { throw new ArgumentNullException("namedFields"); } if (fieldValues == null) { throw new ArgumentNullException("fieldValues"); } if (namedProperties.Length != propertyValues.Length) { throw new ArgumentException(Environment.GetResourceString("Arg_ArrayLengthsDiffer"), "namedProperties, propertyValues"); } if (namedFields.Length != fieldValues.Length) { throw new ArgumentException(Environment.GetResourceString("Arg_ArrayLengthsDiffer"), "namedFields, fieldValues"); } Contract.EndContractBlock(); if ((con.Attributes & MethodAttributes.Static) == MethodAttributes.Static || (con.Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private) { throw new ArgumentException(Environment.GetResourceString("Argument_BadConstructor")); } if ((con.CallingConvention & CallingConventions.Standard) != CallingConventions.Standard) { throw new ArgumentException(Environment.GetResourceString("Argument_BadConstructorCallConv")); } // Cache information used elsewhere. m_con = con; m_constructorArgs = new Object[constructorArgs.Length]; Array.Copy(constructorArgs, m_constructorArgs, constructorArgs.Length); Type[] paramTypes; int i; // Get the types of the constructor's formal parameters. paramTypes = con.GetParameterTypes(); // Since we're guaranteed a non-var calling convention, the number of arguments must equal the number of parameters. if (paramTypes.Length != constructorArgs.Length) { throw new ArgumentException(Environment.GetResourceString("Argument_BadParameterCountsForConstructor")); } // Verify that the constructor has a valid signature (custom attributes only support a subset of our type system). for (i = 0; i < paramTypes.Length; i++) { if (!ValidateType(paramTypes[i])) { throw new ArgumentException(Environment.GetResourceString("Argument_BadTypeInCustomAttribute")); } } // Now verify that the types of the actual parameters are compatible with the types of the formal parameters. for (i = 0; i < paramTypes.Length; i++) { if (constructorArgs[i] == null) { continue; } TypeCode paramTC = Type.GetTypeCode(paramTypes[i]); if (paramTC != Type.GetTypeCode(constructorArgs[i].GetType())) { if (paramTC != TypeCode.Object || !ValidateType(constructorArgs[i].GetType())) { throw new ArgumentException(Environment.GetResourceString("Argument_BadParameterTypeForConstructor", i)); } } } // Allocate a memory stream to represent the CA blob in the metadata and a binary writer to help format it. MemoryStream stream = new MemoryStream(); BinaryWriter writer = new BinaryWriter(stream); // Write the blob protocol version (currently 1). writer.Write((ushort)1); // Now emit the constructor argument values (no need for types, they're inferred from the constructor signature). for (i = 0; i < constructorArgs.Length; i++) { EmitValue(writer, paramTypes[i], constructorArgs[i]); } // Next a short with the count of properties and fields. writer.Write((ushort)(namedProperties.Length + namedFields.Length)); // Emit all the property sets. for (i = 0; i < namedProperties.Length; i++) { // Validate the property. if (namedProperties[i] == null) { throw new ArgumentNullException("namedProperties[" + i + "]"); } // Allow null for non-primitive types only. Type propType = namedProperties[i].PropertyType; if (propertyValues[i] == null && propType.IsPrimitive) { throw new ArgumentNullException("propertyValues[" + i + "]"); } // Validate property type. if (!ValidateType(propType)) { throw new ArgumentException(Environment.GetResourceString("Argument_BadTypeInCustomAttribute")); } // Property has to be writable. if (!namedProperties[i].CanWrite) { throw new ArgumentException(Environment.GetResourceString("Argument_NotAWritableProperty")); } // Property has to be from the same class or base class as ConstructorInfo. if (namedProperties[i].DeclaringType != con.DeclaringType && (!(con.DeclaringType is TypeBuilderInstantiation)) && !con.DeclaringType.IsSubclassOf(namedProperties[i].DeclaringType)) { // Might have failed check because one type is a XXXBuilder // and the other is not. Deal with these special cases // separately. if (!TypeBuilder.IsTypeEqual(namedProperties[i].DeclaringType, con.DeclaringType)) { // IsSubclassOf is overloaded to do the right thing if // the constructor is a TypeBuilder, but we still need // to deal with the case where the property's declaring // type is one. if (!(namedProperties[i].DeclaringType is TypeBuilder) || !con.DeclaringType.IsSubclassOf(((TypeBuilder)namedProperties[i].DeclaringType).BakedRuntimeType)) { throw new ArgumentException(Environment.GetResourceString("Argument_BadPropertyForConstructorBuilder")); } } } // Make sure the property's type can take the given value. // Note that there will be no coersion. if (propertyValues[i] != null && propType != typeof(Object) && Type.GetTypeCode(propertyValues[i].GetType()) != Type.GetTypeCode(propType)) { throw new ArgumentException(Environment.GetResourceString("Argument_ConstantDoesntMatch")); } // First a byte indicating that this is a property. writer.Write((byte)CustomAttributeEncoding.Property); // Emit the property type, name and value. EmitType(writer, propType); EmitString(writer, namedProperties[i].Name); EmitValue(writer, propType, propertyValues[i]); } // Emit all the field sets. for (i = 0; i < namedFields.Length; i++) { // Validate the field. if (namedFields[i] == null) { throw new ArgumentNullException("namedFields[" + i + "]"); } // Allow null for non-primitive types only. Type fldType = namedFields[i].FieldType; if (fieldValues[i] == null && fldType.IsPrimitive) { throw new ArgumentNullException("fieldValues[" + i + "]"); } // Validate field type. if (!ValidateType(fldType)) { throw new ArgumentException(Environment.GetResourceString("Argument_BadTypeInCustomAttribute")); } // Field has to be from the same class or base class as ConstructorInfo. if (namedFields[i].DeclaringType != con.DeclaringType && (!(con.DeclaringType is TypeBuilderInstantiation)) && !con.DeclaringType.IsSubclassOf(namedFields[i].DeclaringType)) { // Might have failed check because one type is a XXXBuilder // and the other is not. Deal with these special cases // separately. if (!TypeBuilder.IsTypeEqual(namedFields[i].DeclaringType, con.DeclaringType)) { // IsSubclassOf is overloaded to do the right thing if // the constructor is a TypeBuilder, but we still need // to deal with the case where the field's declaring // type is one. if (!(namedFields[i].DeclaringType is TypeBuilder) || !con.DeclaringType.IsSubclassOf(((TypeBuilder)namedFields[i].DeclaringType).BakedRuntimeType)) { throw new ArgumentException(Environment.GetResourceString("Argument_BadFieldForConstructorBuilder")); } } } // Make sure the field's type can take the given value. // Note that there will be no coersion. if (fieldValues[i] != null && fldType != typeof(Object) && Type.GetTypeCode(fieldValues[i].GetType()) != Type.GetTypeCode(fldType)) { throw new ArgumentException(Environment.GetResourceString("Argument_ConstantDoesntMatch")); } // First a byte indicating that this is a field. writer.Write((byte)CustomAttributeEncoding.Field); // Emit the field type, name and value. EmitType(writer, fldType); EmitString(writer, namedFields[i].Name); EmitValue(writer, fldType, fieldValues[i]); } // Create the blob array. m_blob = ((MemoryStream)writer.BaseStream).ToArray(); }
/// <devdoc> /// Creates an instance of the CookieParameter class with the specified parameter name, type, and request field. /// </devdoc> public CookieParameter(string name, TypeCode type, string cookieName) : base(name, type) { CookieName = cookieName; }
private static bool IsImplicitNumericConversion(Type source, Type destination) { TypeCode typeCode = Type.GetTypeCode(source); TypeCode typeCode1 = Type.GetTypeCode(destination); TypeCode typeCode2 = typeCode; switch (typeCode2) { case TypeCode.Char: { TypeCode typeCode3 = typeCode1; switch (typeCode3) { case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: { return(true); } } return(false); } case TypeCode.SByte: { TypeCode typeCode4 = typeCode1; switch (typeCode4) { case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: { return(true); } case TypeCode.UInt16: case TypeCode.UInt32: case TypeCode.UInt64: { return(false); } default: { return(false); } } } case TypeCode.Byte: { TypeCode typeCode5 = typeCode1; switch (typeCode5) { case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: { return(true); } } return(false); } case TypeCode.Int16: { TypeCode typeCode6 = typeCode1; switch (typeCode6) { case TypeCode.Int32: case TypeCode.Int64: case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: { return(true); } case TypeCode.UInt32: case TypeCode.UInt64: { return(false); } default: { return(false); } } } case TypeCode.UInt16: { TypeCode typeCode7 = typeCode1; switch (typeCode7) { case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: { return(true); } } return(false); } case TypeCode.Int32: { TypeCode typeCode8 = typeCode1; switch (typeCode8) { case TypeCode.Int64: case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: { return(true); } case TypeCode.UInt64: { return(false); } default: { return(false); } } } case TypeCode.UInt32: { TypeCode typeCode9 = typeCode1; switch (typeCode9) { case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: { return(true); } } return(false); } case TypeCode.Int64: case TypeCode.UInt64: { TypeCode typeCode10 = typeCode1; switch (typeCode10) { case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: { return(true); } } return(false); } case TypeCode.Single: { return(typeCode1 == TypeCode.Double); } } return(false); }
// </snippet2> // <snippet3> // The StaticParameter(string, TypeCode, object) constructor // initializes the DataValue property and calls the // Parameter(string, TypeCode) constructor to initialize the Name and // Type properties. public StaticParameter(string name, TypeCode type, object value) : base(name, type) { DataValue = value; }
protected virtual void UpdateSourceFromTarget() { try { if (this.isUpdatingTarget) { return; } this.isUpdatingSource = true; Type valueType = this.targetProxy.Type; IObtainable obtainable = this.targetProxy as IObtainable; if (obtainable == null) { return; } IModifiable modifier = this.sourceProxy as IModifiable; if (modifier == null) { return; } #if NETFX_CORE TypeCode typeCode = WinRTLegacy.TypeExtensions.GetTypeCode(valueType); #else TypeCode typeCode = Type.GetTypeCode(valueType); #endif switch (typeCode) { case TypeCode.Boolean: { var value = obtainable.GetValue <bool>(); this.SetSourceValue(modifier, value); break; } case TypeCode.Byte: { var value = obtainable.GetValue <byte>(); this.SetSourceValue(modifier, value); break; } case TypeCode.Char: { var value = obtainable.GetValue <char>(); this.SetSourceValue(modifier, value); break; } case TypeCode.DateTime: { var value = obtainable.GetValue <DateTime>(); this.SetSourceValue(modifier, value); break; } case TypeCode.Decimal: { var value = obtainable.GetValue <decimal>(); this.SetSourceValue(modifier, value); break; } case TypeCode.Double: { var value = obtainable.GetValue <double>(); this.SetSourceValue(modifier, value); break; } case TypeCode.Int16: { var value = obtainable.GetValue <Int16>(); this.SetSourceValue(modifier, value); break; } case TypeCode.Int32: { var value = obtainable.GetValue <Int32>(); this.SetSourceValue(modifier, value); break; } case TypeCode.Int64: { var value = obtainable.GetValue <Int64>(); this.SetSourceValue(modifier, value); break; } case TypeCode.SByte: { var value = obtainable.GetValue <sbyte>(); this.SetSourceValue(modifier, value); break; } case TypeCode.Single: { var value = obtainable.GetValue <float>(); this.SetSourceValue(modifier, value); break; } case TypeCode.String: { var value = obtainable.GetValue <string>(); this.SetSourceValue(modifier, value); break; } case TypeCode.UInt16: { var value = obtainable.GetValue <UInt16>(); this.SetSourceValue(modifier, value); break; } case TypeCode.UInt32: { var value = obtainable.GetValue <UInt32>(); this.SetSourceValue(modifier, value); break; } case TypeCode.UInt64: { var value = obtainable.GetValue <UInt64>(); this.SetSourceValue(modifier, value); break; } case TypeCode.Object: { if (valueType.Equals(typeof(Vector2))) { var value = obtainable.GetValue <Vector2>(); this.SetSourceValue(modifier, value); } else if (valueType.Equals(typeof(Vector3))) { var value = obtainable.GetValue <Vector3>(); this.SetSourceValue(modifier, value); } else if (valueType.Equals(typeof(Vector4))) { var value = obtainable.GetValue <Vector4>(); this.SetSourceValue(modifier, value); } else if (valueType.Equals(typeof(Color))) { var value = obtainable.GetValue <Color>(); this.SetSourceValue(modifier, value); } else if (valueType.Equals(typeof(Rect))) { var value = obtainable.GetValue <Rect>(); this.SetSourceValue(modifier, value); } else if (valueType.Equals(typeof(Quaternion))) { var value = obtainable.GetValue <Quaternion>(); this.SetSourceValue(modifier, value); } else if (valueType.Equals(typeof(Version))) { var value = obtainable.GetValue <Version>(); this.SetSourceValue(modifier, value); } else { var value = obtainable.GetValue(); this.SetSourceValue(modifier, value); } break; } default: { var value = obtainable.GetValue(); this.SetSourceValue(modifier, value); break; } } } catch (Exception e) { if (log.IsErrorEnabled) { log.ErrorFormat("An exception occurs when the source property is updated.Please check the binding \"{0}{1}\" in the view \"{2}\".exception: {3}", this.targetTypeName, this.bindingDescription.ToString(), GetViewName(), e); } } finally { this.isUpdatingSource = false; } }
private static void EmitNumericConversion(this ILGenerator il, Type typeFrom, Type typeTo, bool isChecked) { bool isFromUnsigned = typeFrom.IsUnsigned(); bool isFromFloatingPoint = typeFrom.IsFloatingPoint(); if (typeTo == typeof(float)) { if (isFromUnsigned) { il.Emit(OpCodes.Conv_R_Un); } il.Emit(OpCodes.Conv_R4); } else if (typeTo == typeof(double)) { if (isFromUnsigned) { il.Emit(OpCodes.Conv_R_Un); } il.Emit(OpCodes.Conv_R8); } else if (typeTo == typeof(decimal)) { // NB: TypeUtils.IsImplicitNumericConversion makes the promise that implicit conversions // from various integral types and char to decimal are possible. Coalesce allows the // conversion lambda to be omitted in these cases, so we have to handle this case in // here as well, by using the op_Implicit operator implementation on System.Decimal // because there are no opcodes for System.Decimal. Debug.Assert(typeFrom != typeTo); TypeCode tc = typeFrom.GetTypeCode(); MethodInfo method = null; switch (tc) { case TypeCode.Byte: method = Decimal_op_Implicit_Byte; break; case TypeCode.SByte: method = Decimal_op_Implicit_SByte; break; case TypeCode.Int16: method = Decimal_op_Implicit_Int16; break; case TypeCode.UInt16: method = Decimal_op_Implicit_UInt16; break; case TypeCode.Int32: method = Decimal_op_Implicit_Int32; break; case TypeCode.UInt32: method = Decimal_op_Implicit_UInt32; break; case TypeCode.Int64: method = Decimal_op_Implicit_Int64; break; case TypeCode.UInt64: method = Decimal_op_Implicit_UInt64; break; case TypeCode.Char: method = Decimal_op_Implicit_Char; break; default: throw Error.UnhandledConvert(typeTo); } il.Emit(OpCodes.Call, method); } else { TypeCode tc = typeTo.GetTypeCode(); if (isChecked) { // Overflow checking needs to know if the source value on the IL stack is unsigned or not. if (isFromUnsigned) { switch (tc) { case TypeCode.SByte: il.Emit(OpCodes.Conv_Ovf_I1_Un); break; case TypeCode.Int16: il.Emit(OpCodes.Conv_Ovf_I2_Un); break; case TypeCode.Int32: il.Emit(OpCodes.Conv_Ovf_I4_Un); break; case TypeCode.Int64: il.Emit(OpCodes.Conv_Ovf_I8_Un); break; case TypeCode.Byte: il.Emit(OpCodes.Conv_Ovf_U1_Un); break; case TypeCode.UInt16: case TypeCode.Char: il.Emit(OpCodes.Conv_Ovf_U2_Un); break; case TypeCode.UInt32: il.Emit(OpCodes.Conv_Ovf_U4_Un); break; case TypeCode.UInt64: il.Emit(OpCodes.Conv_Ovf_U8_Un); break; default: throw Error.UnhandledConvert(typeTo); } } else { switch (tc) { case TypeCode.SByte: il.Emit(OpCodes.Conv_Ovf_I1); break; case TypeCode.Int16: il.Emit(OpCodes.Conv_Ovf_I2); break; case TypeCode.Int32: il.Emit(OpCodes.Conv_Ovf_I4); break; case TypeCode.Int64: il.Emit(OpCodes.Conv_Ovf_I8); break; case TypeCode.Byte: il.Emit(OpCodes.Conv_Ovf_U1); break; case TypeCode.UInt16: case TypeCode.Char: il.Emit(OpCodes.Conv_Ovf_U2); break; case TypeCode.UInt32: il.Emit(OpCodes.Conv_Ovf_U4); break; case TypeCode.UInt64: il.Emit(OpCodes.Conv_Ovf_U8); break; default: throw Error.UnhandledConvert(typeTo); } } } else { switch (tc) { case TypeCode.SByte: il.Emit(OpCodes.Conv_I1); break; case TypeCode.Byte: il.Emit(OpCodes.Conv_U1); break; case TypeCode.Int16: il.Emit(OpCodes.Conv_I2); break; case TypeCode.UInt16: case TypeCode.Char: il.Emit(OpCodes.Conv_U2); break; case TypeCode.Int32: il.Emit(OpCodes.Conv_I4); break; case TypeCode.UInt32: il.Emit(OpCodes.Conv_U4); break; case TypeCode.Int64: if (isFromUnsigned) { il.Emit(OpCodes.Conv_U8); } else { il.Emit(OpCodes.Conv_I8); } break; case TypeCode.UInt64: if (isFromUnsigned || isFromFloatingPoint) { il.Emit(OpCodes.Conv_U8); } else { il.Emit(OpCodes.Conv_I8); } break; default: throw Error.UnhandledConvert(typeTo); } } } }
public bool runTest() { Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer); try { Boolean testSubject = false; UInt64[] testSubjects = new UInt64[] { UInt64.MinValue, UInt64.MaxValue, (UInt64)(5), (UInt64)(0), (UInt64)(4), (UInt64)(333), (UInt64)(1000), (UInt64)(3333333) }; Type[] typecodes = { typeof(Object), typeof(DBNull), typeof(Boolean), typeof(Char), typeof(SByte), typeof(Byte), typeof(Int16), typeof(UInt16), typeof(Int32), typeof(UInt32), typeof(Int64), typeof(UInt64), typeof(Single), typeof(Double), typeof(Decimal), typeof(DateTime), typeof(String) }; strLoc = "Loc_2y8f8"; testSubject = false; TypeCode t1 = testSubject.GetTypeCode(); iCountTestcases++; if (t1 != TypeCode.Boolean) { iCountErrors++; printerr("Error_298yv! Incorrect typecode returned"); } strLoc = "Loc_498yg"; for (int i = 0; i < testSubjects.Length; i++) { iCountTestcases++; if (!TestToBoolean(testSubjects[i])) { iCountErrors++; printerr("Error_248v8! ToBoolean failed==" + testSubjects[i]); } } strLoc = "Loc_49800"; for (int i = 0; i < testSubjects.Length; i++) { iCountTestcases++; if (!TestToChar(testSubjects[i])) { iCountErrors++; printerr("Error_r8955! ToChar failed==" + testSubjects[i]); } } strLoc = "Loc_49801"; for (int i = 0; i < testSubjects.Length; i++) { iCountTestcases++; if (!TestToSByte(testSubjects[i])) { iCountErrors++; printerr("Error_39r8r! ToSByte failed==" + testSubjects[i]); } } strLoc = "Loc_49802"; for (int i = 0; i < testSubjects.Length; i++) { iCountTestcases++; if (!TestToByte(testSubjects[i])) { iCountErrors++; printerr("Error_298d8! ToByte failed==" + testSubjects[i]); } } strLoc = "Loc_49803"; for (int i = 0; i < testSubjects.Length; i++) { iCountTestcases++; if (!TestToInt16(testSubjects[i])) { iCountErrors++; printerr("Error_20989! ToInt16 failed==" + testSubjects[i]); } } strLoc = "Loc_49804"; for (int i = 0; i < testSubjects.Length; i++) { iCountTestcases++; if (!TestToUInt16(testSubjects[i])) { iCountErrors++; printerr("Error_r498d! ToUInt16 failed==" + testSubjects[i]); } } strLoc = "Loc_49805"; for (int i = 0; i < testSubjects.Length; i++) { iCountTestcases++; if (!TestToInt32(testSubjects[i])) { iCountErrors++; printerr("Error_r4988! ToInt32 failed==" + testSubjects[i]); } } strLoc = "Loc_49806"; for (int i = 0; i < testSubjects.Length; i++) { iCountTestcases++; if (!TestToUInt32(testSubjects[i])) { iCountErrors++; printerr("Error_20992! ToUInt32 failed==" + testSubjects[i]); } } strLoc = "Loc_49807"; for (int i = 0; i < testSubjects.Length; i++) { iCountTestcases++; if (!TestToInt64(testSubjects[i])) { iCountErrors++; printerr("Error_398w8! ToInt64 failed==" + testSubjects[i]); } } strLoc = "Loc_49808"; for (int i = 0; i < testSubjects.Length; i++) { iCountTestcases++; if (!TestToUInt64(testSubjects[i])) { iCountErrors++; printerr("Error_e3298! ToUInt64 failed==" + testSubjects[i]); } } strLoc = "Loc_49809"; for (int i = 0; i < testSubjects.Length; i++) { iCountTestcases++; if (!TestToSingle(testSubjects[i])) { iCountErrors++; printerr("Error_2099s! ToSingle failed==" + testSubjects[i]); } } strLoc = "Loc_49810"; for (int i = 0; i < testSubjects.Length; i++) { iCountTestcases++; if (!TestToDouble(testSubjects[i])) { iCountErrors++; printerr("Error_9848r! ToDouble failed==" + testSubjects[i]); } } strLoc = "Loc_49811"; for (int i = 0; i < testSubjects.Length; i++) { iCountTestcases++; if (!TestToDecimal(testSubjects[i])) { iCountErrors++; printerr("Error_398s9! ToDecimal failed==" + testSubjects[i]); } } strLoc = "Loc_49812"; for (int i = 0; i < testSubjects.Length; i++) { iCountTestcases++; if (!TestToDateTime(testSubjects[i])) { iCountErrors++; printerr("Error_20999! ToDateTime failed==" + testSubjects[i]); } } strLoc = "Loc_49813"; for (int i = 0; i < testSubjects.Length; i++) { iCountTestcases++; if (!TestToString(testSubjects[i])) { iCountErrors++; printerr("Error_298s4! ToString failed==" + testSubjects[i]); } } strLoc = "Loc_49814"; for (int i = 0; i < testSubjects.Length; i++) { for (int j = 0; j < typecodes.Length; j++) { iCountTestcases++; if (!TestToType(testSubjects[i], typecodes[j])) { iCountErrors++; printerr("Error_29888! ToType failed==" + testSubjects[i]); } } } } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " : Error Err_8888yyy! strLoc==" + strLoc + ", exc_general==" + exc_general.ToString()); } if (iCountErrors == 0) { Console.WriteLine("paSs. " + s_strTFName + " ,iCountTestcases==" + iCountTestcases.ToString()); return(true); } else { Console.WriteLine("FAiL! " + s_strTFName + " ,iCountErrors==" + iCountErrors.ToString() + " , BugNums?: " + s_strActiveBugNums); return(false); } }
public object Convert(object value, TypeCode typeCode) { throw new NotImplementedException(); }
public void PrimitiveCollection() { var excludeTypes = new TypeCode[] { TypeCode.Empty, TypeCode.DBNull, TypeCode.DateTime, //DateTime is not managed TypeCode.Object, TypeCode.Boolean, //Bool flattens value to 0 or 1 so hashset differ too much. change the verifier to take care of conversions }; var types = Enum.GetValues(typeof(TypeCode)).Cast <TypeCode>() .Except(excludeTypes) .Select(typeCode => TypeExtensions.GetType(typeCode)).ToList(); foreach (var sourceElementType in types) { foreach (var targetElementType in types) { //for the following pairs a conversion is known //to be harder (not possible or convention-based), //so here we just skip that few cases if (sourceElementType == typeof(string) && targetElementType == typeof(bool)) { continue; } if (sourceElementType == typeof(char) && targetElementType == typeof(bool)) { continue; } if (sourceElementType == typeof(bool) && targetElementType == typeof(char)) { continue; } var sourceType = typeof(GenericCollections <>) .MakeGenericType(sourceElementType); var targetType = typeof(GenericCollections <>) .MakeGenericType(targetElementType); var sourceTypeCtor = ConstructorFactory.CreateConstructor <bool, uint, uint>(sourceType); var targetTypeCtor = ConstructorFactory.CreateConstructor <bool, uint, uint>(targetType); var source = sourceTypeCtor(true, 0, 10); var target = targetTypeCtor(false, 0, 10); var ultraMapper = new Mapper(); ultraMapper.Map(source, target); bool isResultOk = ultraMapper.VerifyMapperResult(source, target); Assert.IsTrue(isResultOk); } } }
/// <summary> /// Get/set the value associated with the specified key. /// </summary> /// <param name="keyword"></param> /// <returns></returns> public override object this [String keyword] { // Look up the ordinal for and return // the value at that position. get { int i = GetOrdinal(keyword); return(_items[i].Value); } set { int i = GetOrdinal(keyword); if (value == null) { this.Remove(keyword); return; } Object nativeValue = value; // assume no conversion needed TypeCode sourceTypeCode = Type.GetTypeCode(value.GetType()); Type targetType = ConnectStringConfig.ConnectBuilderKeywords[i].Value.GetType(); TypeCode targetTypeCode = Type.GetTypeCode(targetType); if (targetTypeCode != sourceTypeCode) { switch (targetTypeCode) { case TypeCode.Int32: nativeValue = Int32.Parse(value.ToString()); break; case TypeCode.Boolean: String valueString = value.ToString().Trim(); String valueLower = ToInvariantLower(valueString); // Catch yes/no literals that Boolean.Parse doesn't if (valueLower == "yes" || valueLower == "1") { nativeValue = true; value = "true"; break; } if (valueLower == "no" || valueLower == "0") { nativeValue = false; value = "false"; break; } nativeValue = Boolean.Parse(valueString); break; case TypeCode.String: nativeValue = value.ToString(); break; default: throw new System.InvalidOperationException( "IngresConnectionStringBuilder internal error: " + "unexpected Type for keyword '" + keyword + "'."); } // end switch } // end if (targetTypeCode != sourceTypeCode) string connectionString = keyword + "=" + (value != null ? value.ToString() : ""); ConnectStringConfig connectStringConfig = ConnectStringConfig.ParseConnectionString(connectionString); if (connectStringConfig.Count > 1) { throw new ArgumentException("Invalid keyword/value pair: '" + connectionString + "'."); } base[_items[i].Key.ToString()] = nativeValue; // Standardize key _items[i].Value = nativeValue; } }
public static object GetDataValue(object value, TypeCode typeCode) { if (value == null) { return(null); } object objectValue = null; switch (typeCode) { case TypeCode.Boolean: objectValue = GetBooleanFlag(value.ToString()); break; case TypeCode.DateTime: var dt = DateTime.MinValue; if (value is DateTime) { dt = (DateTime)value; } else { dt = ParseCurrentDate(value.ToString()); } objectValue = dt; break; case TypeCode.Decimal: if (value is decimal) { objectValue = value; } else { decimal doubleValue; decimal.TryParse(value.ToString(), out doubleValue); objectValue = doubleValue; } break; case TypeCode.Double: if (value is double) { objectValue = value; } else { double doubleValue; double.TryParse(value.ToString(), out doubleValue); objectValue = doubleValue; } break; case TypeCode.Int64: if (value is Int64) { objectValue = value; } else if (value is Int32 || value is Int16) { objectValue = Convert.ToInt64(value); } else { long longValue; Int64.TryParse(value.ToString(), out longValue); objectValue = longValue; } break; case TypeCode.Int32: if (value is Int32) { objectValue = value; } else if (value is Int16 || value is decimal) { objectValue = Convert.ToInt32(value); } else { var valType = value.GetType(); int number = 0; if (valType.IsEnum) { number = Convert.ToInt32(value); } else { int.TryParse(value.ToString(), out number); } objectValue = number; } break; case TypeCode.Int16: if (value is Int16) { objectValue = value; } else if (value is Int32 || value is decimal) { objectValue = Convert.ToInt16(value); } else { var valType = value.GetType(); Int16 number = 0; if (valType.IsEnum) { number = Convert.ToInt16(value); } else { Int16.TryParse(value.ToString(), out number); } objectValue = number; } break; case TypeCode.String: objectValue = value.ToString(); break; default: objectValue = value; break; } return(objectValue); }
public static string FormatToDisplay(string inpData, TypeCode dataTyp, string formatCode = "") { return(FormatToDisplay(inpData, GetCurrentCulture(), dataTyp, formatCode)); }
public static Object ChangeType(Object value, TypeCode typeCode) { return(default(Object)); }
public static string FormatToSave(string inpData, TypeCode dataTyp) { return(FormatToSave(inpData, TypeCode.String, "")); }
private static bool TryNumericConversion <T>(object source, out T result) { TypeCode typeCode = Type.GetTypeCode(source.GetType()); TypeCode typeCode1 = Type.GetTypeCode(typeof(T)); TypeCode typeCode2 = typeCode; switch (typeCode2) { case TypeCode.Char: { char chr = (char)source; TypeCode typeCode3 = typeCode1; switch (typeCode3) { case TypeCode.UInt16: { result = (T)(object)((ushort)chr); return(true); } case TypeCode.Int32: { result = (T)(object)((int)chr); return(true); } case TypeCode.UInt32: { result = (T)(object)((uint)chr); return(true); } case TypeCode.Int64: { result = (T)(object)((long)((ulong)chr)); return(true); } case TypeCode.UInt64: { result = (T)(object)((ulong)chr); return(true); } case TypeCode.Single: { result = (T)(object)((float)chr); return(true); } case TypeCode.Double: { result = (T)(object)((double)chr); return(true); } case TypeCode.Decimal: { result = (T)(object)chr; return(true); } } } break; case TypeCode.SByte: { sbyte num = (sbyte)source; TypeCode typeCode4 = typeCode1; if (typeCode4 == TypeCode.Int16) { result = (T)(object)((short)num); return(true); } else if (typeCode4 == TypeCode.UInt16 || typeCode4 == TypeCode.UInt32 || typeCode4 == TypeCode.UInt64) { break; } else if (typeCode4 == TypeCode.Int32) { result = (T)(object)((int)num); return(true); } else if (typeCode4 == TypeCode.Int64) { result = (T)(object)((long)num); return(true); } else if (typeCode4 == TypeCode.Single) { result = (T)(object)((float)num); return(true); } else if (typeCode4 == TypeCode.Double) { result = (T)(object)((double)num); return(true); } else if (typeCode4 == TypeCode.Decimal) { result = (T)(object)num; return(true); } break; } case TypeCode.Byte: { byte num1 = (byte)source; TypeCode typeCode5 = typeCode1; switch (typeCode5) { case TypeCode.Int16: { result = (T)(object)((short)num1); return(true); } case TypeCode.UInt16: { result = (T)(object)((ushort)num1); return(true); } case TypeCode.Int32: { result = (T)(object)((int)num1); return(true); } case TypeCode.UInt32: { result = (T)(object)((uint)num1); return(true); } case TypeCode.Int64: { result = (T)(object)((long)((ulong)num1)); return(true); } case TypeCode.UInt64: { result = (T)(object)((ulong)num1); return(true); } case TypeCode.Single: { result = (T)(object)((float)num1); return(true); } case TypeCode.Double: { result = (T)(object)((double)num1); return(true); } case TypeCode.Decimal: { result = (T)(object)num1; return(true); } } } break; case TypeCode.Int16: { short num2 = (short)source; TypeCode typeCode6 = typeCode1; if (typeCode6 == TypeCode.Int32) { result = (T)(object)((int)num2); return(true); } else if (typeCode6 == TypeCode.UInt32 || typeCode6 == TypeCode.UInt64) { break; } else if (typeCode6 == TypeCode.Int64) { result = (T)(object)((long)num2); return(true); } else if (typeCode6 == TypeCode.Single) { result = (T)(object)((float)num2); return(true); } else if (typeCode6 == TypeCode.Double) { result = (T)(object)((double)num2); return(true); } else if (typeCode6 == TypeCode.Decimal) { result = (T)(object)num2; return(true); } break; } break; case TypeCode.UInt16: { ushort num3 = (ushort)source; TypeCode typeCode7 = typeCode1; switch (typeCode7) { case TypeCode.Int32: { result = (T)(object)((int)num3); return(true); } case TypeCode.UInt32: { result = (T)(object)((uint)num3); return(true); } case TypeCode.Int64: { result = (T)(object)((long)((ulong)num3)); return(true); } case TypeCode.UInt64: { result = (T)(object)((ulong)num3); return(true); } case TypeCode.Single: { result = (T)(object)((float)num3); return(true); } case TypeCode.Double: { result = (T)(object)((double)num3); return(true); } case TypeCode.Decimal: { result = (T)(object)num3; return(true); } } } break; case TypeCode.Int32: { int num4 = (int)source; TypeCode typeCode8 = typeCode1; if (typeCode8 == TypeCode.Int64) { result = (T)(object)((long)num4); return(true); } else if (typeCode8 == TypeCode.UInt64) { break; } else if (typeCode8 == TypeCode.Single) { result = (T)(object)((float)num4); return(true); } else if (typeCode8 == TypeCode.Double) { result = (T)(object)((double)num4); return(true); } else if (typeCode8 == TypeCode.Decimal) { result = (T)(object)num4; return(true); } break; } break; case TypeCode.UInt32: { uint num5 = (uint)source; TypeCode typeCode9 = typeCode1; switch (typeCode9) { case TypeCode.UInt32: { result = (T)(object)num5; return(true); } case TypeCode.Int64: { result = (T)(object)((long)((ulong)num5)); return(true); } case TypeCode.UInt64: { result = (T)(object)((ulong)num5); return(true); } case TypeCode.Single: { result = (T)(object)((float)((float)num5)); return(true); } case TypeCode.Double: { result = (T)(object)((double)((float)num5)); return(true); } case TypeCode.Decimal: { result = (T)(object)num5; return(true); } } } break; case TypeCode.Int64: { long num6 = (long)source; TypeCode typeCode10 = typeCode1; switch (typeCode10) { case TypeCode.Single: { result = (T)(object)((float)num6); return(true); } case TypeCode.Double: { result = (T)(object)((double)num6); return(true); } case TypeCode.Decimal: { result = (T)(object)num6; return(true); } } } break; case TypeCode.UInt64: { ulong num7 = (ulong)source; TypeCode typeCode11 = typeCode1; switch (typeCode11) { case TypeCode.Single: { result = (T)(object)((float)((float)num7)); return(true); } case TypeCode.Double: { result = (T)(object)((double)((float)num7)); return(true); } case TypeCode.Decimal: { result = (T)(object)num7; return(true); } } } break; case TypeCode.Single: { if (typeCode1 != TypeCode.Double) { break; } result = (T)(object)((double)((float)source)); return(true); } break; } result = default(T); return(false); }
public static Object ChangeType(Object value, TypeCode typeCode, IFormatProvider provider) { return(default(Object)); }
public static List <object> ReadArrayValues(IField f, TypeCode type) { return(ReadArrayValues(f, type.ToSystemTypeCode())); }
internal static bool IsCompatibleWith(this Type source, Type target) { if (source == target) { return(true); } if (!target.IsValueType) { return(target.IsAssignableFrom(source)); } Type st = source.GetNonNullableType(); Type tt = target.GetNonNullableType(); if (st != source && tt == target) { return(false); } TypeCode sc = st.IsEnum ? TypeCode.Object : Type.GetTypeCode(st); TypeCode tc = tt.IsEnum ? TypeCode.Object : Type.GetTypeCode(tt); switch (sc) { case TypeCode.SByte: switch (tc) { case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: return(true); } break; case TypeCode.Byte: switch (tc) { case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: return(true); } break; case TypeCode.Int16: switch (tc) { case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: return(true); } break; case TypeCode.UInt16: switch (tc) { case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: return(true); } break; case TypeCode.Int32: switch (tc) { case TypeCode.Int32: case TypeCode.Int64: case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: return(true); } break; case TypeCode.UInt32: switch (tc) { case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: return(true); } break; case TypeCode.Int64: switch (tc) { case TypeCode.Int64: case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: return(true); } break; case TypeCode.UInt64: switch (tc) { case TypeCode.UInt64: case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: return(true); } break; case TypeCode.Single: switch (tc) { case TypeCode.Single: case TypeCode.Double: return(true); } break; default: if (st == tt) { return(true); } break; } return(false); }
/// <summary> /// Class member. /// </summary> /// <param name="Name">Member name.</param> /// <param name="FieldCode">Field Code.</param> /// <param name="MemberType">Member type.</param> public Member(string Name, ulong FieldCode, Type MemberType) { this.name = Name; this.fieldCode = FieldCode; this.memberType = MemberType; this.memberTypeInfo = MemberType.GetTypeInfo(); if (this.memberTypeInfo.IsGenericType) { Type GT = this.memberType.GetGenericTypeDefinition(); if (GT == typeof(Nullable <>)) { this.nullable = true; this.memberType = this.memberType.GenericTypeArguments[0]; this.memberTypeInfo = this.memberType.GetTypeInfo(); } } this.memberFieldDataTypeCode = ObjectSerializer.GetFieldDataTypeCode(this.memberType); this.isNestedObject = this.memberFieldDataTypeCode == ObjectSerializer.TYPE_OBJECT; switch (this.memberFieldDataTypeCode) { case ObjectSerializer.TYPE_BOOLEAN: this.memberTypeCode = TypeCode.Boolean; break; case ObjectSerializer.TYPE_BYTE: this.memberTypeCode = TypeCode.Byte; break; case ObjectSerializer.TYPE_INT16: this.memberTypeCode = TypeCode.Int16; break; case ObjectSerializer.TYPE_INT32: this.memberTypeCode = TypeCode.Int32; if (this.memberTypeInfo.IsEnum) { this.isEnum = true; this.hasFlags = true; } break; case ObjectSerializer.TYPE_INT64: this.memberTypeCode = TypeCode.Int64; break; case ObjectSerializer.TYPE_SBYTE: this.memberTypeCode = TypeCode.SByte; break; case ObjectSerializer.TYPE_UINT16: this.memberTypeCode = TypeCode.UInt16; break; case ObjectSerializer.TYPE_UINT32: this.memberTypeCode = TypeCode.UInt32; break; case ObjectSerializer.TYPE_UINT64: this.memberTypeCode = TypeCode.UInt64; break; case ObjectSerializer.TYPE_DECIMAL: this.memberTypeCode = TypeCode.Decimal; break; case ObjectSerializer.TYPE_DOUBLE: this.memberTypeCode = TypeCode.Double; break; case ObjectSerializer.TYPE_SINGLE: this.memberTypeCode = TypeCode.Single; break; case ObjectSerializer.TYPE_DATETIME: this.memberTypeCode = TypeCode.DateTime; break; case ObjectSerializer.TYPE_CHAR: this.memberTypeCode = TypeCode.Char; break; case ObjectSerializer.TYPE_STRING: this.memberTypeCode = TypeCode.String; break; case ObjectSerializer.TYPE_MIN: case ObjectSerializer.TYPE_MAX: case ObjectSerializer.TYPE_NULL: this.memberTypeCode = TypeCode.Empty; break; case ObjectSerializer.TYPE_ENUM: this.memberTypeCode = TypeCode.Object; this.isEnum = true; this.hasFlags = this.memberTypeInfo.IsDefined(typeof(FlagsAttribute), false); break; case ObjectSerializer.TYPE_OBJECT: case ObjectSerializer.TYPE_TIMESPAN: case ObjectSerializer.TYPE_BYTEARRAY: case ObjectSerializer.TYPE_GUID: case ObjectSerializer.TYPE_ARRAY: case ObjectSerializer.TYPE_DATETIMEOFFSET: case ObjectSerializer.TYPE_CI_STRING: default: this.memberTypeCode = TypeCode.Object; break; } }
private static object ConvertDynamic(TypeCode code, string value) { try { switch (code) { case TypeCode.Empty: return(string.Empty); case TypeCode.Object: return(value); case TypeCode.Boolean: return(Convert.ToBoolean(value)); case TypeCode.Char: return(Convert.ToChar(value)); case TypeCode.SByte: return(Convert.ToSByte(value)); case TypeCode.Byte: return(Convert.ToByte(value)); case TypeCode.Int16: return(Convert.ToInt16(value)); case TypeCode.UInt16: return(Convert.ToUInt16(value)); case TypeCode.Int32: return(Convert.ToInt32(value)); case TypeCode.UInt32: return(Convert.ToUInt32(value)); case TypeCode.Int64: return(Convert.ToInt64(value)); case TypeCode.UInt64: return(Convert.ToUInt64(value)); case TypeCode.Single: return(Convert.ToSingle(value)); case TypeCode.Double: return(Convert.ToDouble(value)); case TypeCode.Decimal: return(Convert.ToDecimal(value)); case TypeCode.DateTime: return(Convert.ToDateTime(value)); case TypeCode.String: return(value); default: return(null); } } catch (Exception) { return(null); } }
public void GetTypeCode_ValidType_ReturnsExpected(Type t, TypeCode typeCode) { Assert.Equal(typeCode, Type.GetTypeCode(t)); }
/// <summary> /// Attempts to convert a string slice into a value of the given type. /// </summary> static public bool TryConvertTo(StringSlice inSlice, Type inType, out object outValue) { if (inType.IsEnum) { try { outValue = Enum.Parse(inType, inSlice.ToString(), false); return(true); } catch { outValue = null; return(false); } } TypeCode tc = Type.GetTypeCode(inType); switch (tc) { case TypeCode.Boolean: { bool b; if (TryParseBool(inSlice, out b)) { outValue = b; return(true); } break; } case TypeCode.Byte: { byte b; if (TryParseByte(inSlice, out b)) { outValue = b; return(true); } break; } case TypeCode.Char: { if (inSlice.Length > 0) { outValue = inSlice[0]; return(true); } break; } case TypeCode.DateTime: { try { outValue = Convert.ToDateTime(inSlice.ToString()); return(true); } catch { outValue = null; return(false); } } case TypeCode.Decimal: { double d; if (TryParseDouble(inSlice, out d)) { outValue = (decimal)d; return(true); } break; } case TypeCode.Double: { double d; if (TryParseDouble(inSlice, out d)) { outValue = d; return(true); } break; } case TypeCode.Int16: { short s; if (TryParseShort(inSlice, out s)) { outValue = s; return(true); } break; } case TypeCode.Int32: { int i; if (TryParseInt(inSlice, out i)) { outValue = i; return(true); } break; } case TypeCode.Int64: { long l; if (TryParseLong(inSlice, out l)) { outValue = l; return(true); } break; } case TypeCode.Object: { if (inType == typeof(StringSlice) || inType == typeof(object)) { outValue = inSlice; return(true); } if (inType == typeof(StringHash32)) { StringHash32 hash; if (StringHash32.TryParse(inSlice, out hash)) { outValue = hash; return(true); } } if (inType == typeof(StringHash64)) { StringHash64 hash; if (StringHash64.TryParse(inSlice, out hash)) { outValue = hash; return(true); } } else if (inType == typeof(Variant)) { Variant v; if (Variant.TryParse(inSlice, true, out v)) { outValue = v; return(true); } } break; } case TypeCode.SByte: { sbyte s; if (TryParseSByte(inSlice, out s)) { outValue = s; return(true); } break; } case TypeCode.Single: { float f; if (TryParseFloat(inSlice, out f)) { outValue = f; return(true); } break; } case TypeCode.String: { outValue = inSlice.ToString(); return(true); } case TypeCode.UInt16: { ushort u; if (TryParseUShort(inSlice, out u)) { outValue = u; return(true); } break; } case TypeCode.UInt32: { uint u; if (TryParseUInt(inSlice, out u)) { outValue = u; return(true); } break; } case TypeCode.UInt64: { ulong u; if (TryParseULong(inSlice, out u)) { outValue = u; return(true); } break; } } outValue = null; return(false); }
// 0 -> same type or null and !valuetype // 1 -> to == Enum // 2 -> value type that don't lose data // 3 -> to == IsAssignableFrom // 4 -> to == object static int check_type_with_score(Type from, Type to) { if (from == null) { return(to.IsValueType ? -1 : 0); } if (from == to) { return(0); } if (to == typeof(object)) { return(4); } TypeCode fromt = Type.GetTypeCode(from); TypeCode tot = Type.GetTypeCode(to); switch (fromt) { case TypeCode.Char: switch (tot) { case TypeCode.UInt16: return(0); case TypeCode.UInt32: case TypeCode.Int32: case TypeCode.UInt64: case TypeCode.Int64: case TypeCode.Single: case TypeCode.Double: return(2); } return(-1); case TypeCode.Byte: switch (tot) { case TypeCode.Char: case TypeCode.UInt16: case TypeCode.Int16: case TypeCode.UInt32: case TypeCode.Int32: case TypeCode.UInt64: case TypeCode.Int64: case TypeCode.Single: case TypeCode.Double: return(2); } return((from.IsEnum && to == typeof(Enum)) ? 1 : -1); case TypeCode.SByte: switch (tot) { case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: case TypeCode.Single: case TypeCode.Double: return(2); } return((from.IsEnum && to == typeof(Enum)) ? 1 : -1); case TypeCode.UInt16: switch (tot) { case TypeCode.UInt32: case TypeCode.Int32: case TypeCode.UInt64: case TypeCode.Int64: case TypeCode.Single: case TypeCode.Double: return(2); } return((from.IsEnum && to == typeof(Enum)) ? 1 : -1); case TypeCode.Int16: switch (tot) { case TypeCode.Int32: case TypeCode.Int64: case TypeCode.Single: case TypeCode.Double: return(2); } return((from.IsEnum && to == typeof(Enum)) ? 1 : -1); case TypeCode.UInt32: switch (tot) { case TypeCode.UInt64: case TypeCode.Int64: case TypeCode.Single: case TypeCode.Double: return(2); } return((from.IsEnum && to == typeof(Enum)) ? 1 : -1); case TypeCode.Int32: switch (tot) { case TypeCode.Int64: case TypeCode.Single: case TypeCode.Double: return(2); } return((from.IsEnum && to == typeof(Enum)) ? 1 : -1); case TypeCode.UInt64: case TypeCode.Int64: switch (tot) { case TypeCode.Single: case TypeCode.Double: return(2); } return((from.IsEnum && to == typeof(Enum)) ? 1 : -1); case TypeCode.Single: return(tot == TypeCode.Double ? 2 : -1); default: return((to.IsAssignableFrom(from)) ? 3 : -1); } }
public Help() { ArgTypes = new TypeCode[][] { new TypeCode[] { TypeCode.String }, new TypeCode[] { } }; }
private static bool check_type(Type from, Type to) { if (from == to) { return(true); } if (from == null) { return(true); } if (to.IsByRef != from.IsByRef) { return(false); } if (to.IsInterface) { return(to.IsAssignableFrom(from)); } if (to.IsEnum) { to = Enum.GetUnderlyingType(to); if (from == to) { return(true); } } if (to.IsGenericType && to.GetGenericTypeDefinition() == typeof(Nullable <>) && to.GetGenericArguments()[0] == from) { return(true); } TypeCode fromt = Type.GetTypeCode(from); TypeCode tot = Type.GetTypeCode(to); switch (fromt) { case TypeCode.Char: switch (tot) { case TypeCode.UInt16: case TypeCode.UInt32: case TypeCode.Int32: case TypeCode.UInt64: case TypeCode.Int64: case TypeCode.Single: case TypeCode.Double: return(true); } return(to == typeof(object)); case TypeCode.Byte: switch (tot) { case TypeCode.Char: case TypeCode.UInt16: case TypeCode.Int16: case TypeCode.UInt32: case TypeCode.Int32: case TypeCode.UInt64: case TypeCode.Int64: case TypeCode.Single: case TypeCode.Double: return(true); } return(to == typeof(object) || (from.IsEnum && to == typeof(Enum))); case TypeCode.SByte: switch (tot) { case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: case TypeCode.Single: case TypeCode.Double: return(true); } return(to == typeof(object) || (from.IsEnum && to == typeof(Enum))); case TypeCode.UInt16: switch (tot) { case TypeCode.UInt32: case TypeCode.Int32: case TypeCode.UInt64: case TypeCode.Int64: case TypeCode.Single: case TypeCode.Double: return(true); } return(to == typeof(object) || (from.IsEnum && to == typeof(Enum))); case TypeCode.Int16: switch (tot) { case TypeCode.Int32: case TypeCode.Int64: case TypeCode.Single: case TypeCode.Double: return(true); } return(to == typeof(object) || (from.IsEnum && to == typeof(Enum))); case TypeCode.UInt32: switch (tot) { case TypeCode.UInt64: case TypeCode.Int64: case TypeCode.Single: case TypeCode.Double: return(true); } return(to == typeof(object) || (from.IsEnum && to == typeof(Enum))); case TypeCode.Int32: switch (tot) { case TypeCode.Int64: case TypeCode.Single: case TypeCode.Double: return(true); } return(to == typeof(object) || (from.IsEnum && to == typeof(Enum))); case TypeCode.UInt64: case TypeCode.Int64: switch (tot) { case TypeCode.Single: case TypeCode.Double: return(true); } return(to == typeof(object) || (from.IsEnum && to == typeof(Enum))); case TypeCode.Single: return(tot == TypeCode.Double || to == typeof(object)); default: /* TODO: handle valuetype -> byref */ if (to == typeof(object) && from.IsValueType) { return(true); } if (to.IsPointer && from == typeof(IntPtr)) { return(true); } return(to.IsAssignableFrom(from)); } }
/// <summary> /// Initializes a new instance of the <see cref="AppSettingParameter"/> class. /// </summary> /// <param name="name">The name.</param> /// <param name="type">The type.</param> /// <param name="appSettingKey">The app setting key.</param> public AppSettingParameter(string name, TypeCode type, string appSettingKey) : base(name, type) { AppSettingKey = appSettingKey; }
private IProtoSerializer GetCoreSerializer(Type type, out WireType defaultWireType) { #if !NO_GENERICS type = Nullable.GetUnderlyingType(type) ?? type; #endif if (type.IsEnum) { // need to do this before checking the typecode; an int enum will report Int32 etc defaultWireType = WireType.Variant; return(new EnumSerializer(type, model.GetEnumMap(type))); } TypeCode code = Type.GetTypeCode(type); switch (code) { case TypeCode.Int32: defaultWireType = GetIntWireType(dataFormat, 32); return(new Int32Serializer()); case TypeCode.UInt32: defaultWireType = GetIntWireType(dataFormat, 32); return(new UInt32Serializer()); case TypeCode.Int64: defaultWireType = GetIntWireType(dataFormat, 64); return(new Int64Serializer()); case TypeCode.UInt64: defaultWireType = GetIntWireType(dataFormat, 64); return(new UInt64Serializer()); case TypeCode.String: defaultWireType = WireType.String; return(new StringSerializer()); case TypeCode.Single: defaultWireType = WireType.Fixed32; return(new SingleSerializer()); case TypeCode.Double: defaultWireType = WireType.Fixed64; return(new DoubleSerializer()); case TypeCode.Boolean: defaultWireType = WireType.Variant; return(new BooleanSerializer()); case TypeCode.DateTime: defaultWireType = WireType.String; return(new DateTimeSerializer()); case TypeCode.Decimal: defaultWireType = WireType.String; return(new DecimalSerializer()); case TypeCode.Byte: defaultWireType = WireType.Variant; return(new ByteSerializer()); case TypeCode.SByte: defaultWireType = WireType.Variant; return(new SByteSerializer()); case TypeCode.Char: defaultWireType = WireType.Variant; return(new CharSerializer()); case TypeCode.Int16: defaultWireType = WireType.Variant; return(new Int16Serializer()); case TypeCode.UInt16: defaultWireType = WireType.Variant; return(new UInt16Serializer()); } if (type == typeof(TimeSpan)) { defaultWireType = WireType.String; return(new TimeSpanSerializer()); } if (type == typeof(Guid)) { defaultWireType = WireType.String; return(new GuidSerializer()); } if (type == typeof(Uri)) { defaultWireType = WireType.String; return(new StringSerializer()); // treat as string; wrapped in decorator later } if (type == typeof(byte[])) { defaultWireType = WireType.String; return(new BlobSerializer()); } int key = model.GetKey(type, false, true); if (key >= 0) { defaultWireType = WireType.String; return(new SubItemSerializer(type, key, model[type])); } throw new InvalidOperationException("No serializer defined for type: " + type.FullName); }
/// <summary> /// Add a parameter for a project. /// </summary> /// <param name="name">parameter name</param> /// <param name="type">parameter type</param> public Parameter AddProjectParameter(string name, TypeCode type) { Debug.Assert(!string.IsNullOrEmpty(name), @"The parameter name should not be nullable."); return(this.Parameters.Add(name, type)); }
/// <summary> /// serialize value and wrap with <see cref="SerializedObjectWrapper"/> /// </summary> /// <param name="value"></param> /// <returns></returns> SerializedObjectWrapper SerializeToWrapper(object value) { // raw data is a special case when some1 passes in a buffer (byte[] or ArraySegment<byte>) if (value is ArraySegment <byte> ) { // ArraySegment<byte> is only passed in when a part of buffer is being // serialized, usually from a MemoryStream (To avoid duplicating arrays // the byte[] returned by MemoryStream.GetBuffer is placed into an ArraySegment.) // return(new SerializedObjectWrapper(RawDataFlag, (ArraySegment <byte>)value)); } byte[] tmpByteArray = value as byte[]; // - or we just received a byte[]. No further processing is needed. if (tmpByteArray != null) { return(new SerializedObjectWrapper(RawDataFlag, new ArraySegment <byte>(tmpByteArray))); } TypeCode code = value == null ? TypeCode.DBNull : value.GetType().GetTypeCode(); byte[] data; int length = -1; switch (code) { case TypeCode.DBNull: data = EmptyArray; length = 0; break; case TypeCode.String: data = Encoding.UTF8.GetBytes((string)value); break; case TypeCode.Boolean: data = BitConverter.GetBytes((bool)value); break; case TypeCode.Int16: data = BitConverter.GetBytes((short)value); break; case TypeCode.Int32: data = BitConverter.GetBytes((int)value); break; case TypeCode.Int64: data = BitConverter.GetBytes((long)value); break; case TypeCode.UInt16: data = BitConverter.GetBytes((ushort)value); break; case TypeCode.UInt32: data = BitConverter.GetBytes((uint)value); break; case TypeCode.UInt64: data = BitConverter.GetBytes((ulong)value); break; case TypeCode.Char: data = BitConverter.GetBytes((char)value); break; case TypeCode.DateTime: data = BitConverter.GetBytes(((DateTime)value).ToBinary()); break; case TypeCode.Double: data = BitConverter.GetBytes((double)value); break; case TypeCode.Single: data = BitConverter.GetBytes((float)value); break; default: #if NETCORE data = new byte[0]; length = 0; #else using (var ms = new MemoryStream()) { bf.Serialize(ms, value); code = TypeCode.Object; data = ms.GetBuffer(); length = (int)ms.Length; } #endif break; } if (length < 0) { length = data.Length; } return(new SerializedObjectWrapper((ushort)((ushort)code | 0x0100), new ArraySegment <byte>(data, 0, length))); }