public static Array CreatePrimitiveArray(PrimitiveTypeEnum code, int length) { if (Activator.CreateInstance((Type)s_PrimitiveTypeToArrayTypeLookup[code], length) is Array success) { return(success); } return(default);
public PrimitiveArray(PrimitiveTypeEnum code, Array array) { _code = code; switch (code) { case PrimitiveTypeEnum.Boolean: _booleanA = (bool[])array; return; case PrimitiveTypeEnum.Byte: case PrimitiveTypeEnum.Currency: case PrimitiveTypeEnum.Decimal: case PrimitiveTypeEnum.TimeSpan: case PrimitiveTypeEnum.DateTime: break; case PrimitiveTypeEnum.Char: _charA = (char[])array; return; case PrimitiveTypeEnum.Double: _doubleA = (double[])array; return; case PrimitiveTypeEnum.Int16: _int16A = (short[])array; return; case PrimitiveTypeEnum.Int32: _int32A = (int[])array; return; case PrimitiveTypeEnum.Int64: _int64A = (long[])array; return; case PrimitiveTypeEnum.SByte: _sbyteA = (sbyte[])array; return; case PrimitiveTypeEnum.Single: _singleA = (float[])array; return; case PrimitiveTypeEnum.UInt16: _uint16A = (ushort[])array; return; case PrimitiveTypeEnum.UInt32: _uint32A = (uint[])array; return; case PrimitiveTypeEnum.UInt64: _uint64A = (ulong[])array; break; default: return; } }
internal PrimitiveTypeEnum ToCode(Type type) { if (object.ReferenceEquals(this._previousType, type)) { return(this._previousCode); } PrimitiveTypeEnum ee = Converter.ToCode(type); if (ee != PrimitiveTypeEnum.Invalid) { this._previousType = type; this._previousCode = ee; } return(ee); }
internal void Init() { this._fullName = null; this._objectId = 0L; this._assemId = 0L; this._primitiveTypeEnum = PrimitiveTypeEnum.Invalid; this._type = null; this._isSealed = false; this._transmitTypeOnObject = false; this._transmitTypeOnMember = false; this._isParentTypeOnObject = false; this._isArray = false; this._isArrayItem = false; this._arrayEnum = ArrayTypeEnum.Empty; this._sealedStatusChecked = false; }
private NameInfo TypeToNameInfo(Type type, WriteObjectInfo objectInfo, PrimitiveTypeEnum code, NameInfo nameInfo) { if (nameInfo == null) { nameInfo = this.GetNameInfo(); } else { nameInfo.Init(); } if ((code == PrimitiveTypeEnum.Invalid) && (objectInfo != null)) { nameInfo.NIname = objectInfo.GetTypeFullName(); nameInfo._assemId = objectInfo._assemId; } nameInfo._primitiveTypeEnum = code; nameInfo._type = type; return(nameInfo); }
public static BinaryTypeEnum GetParserBinaryTypeInfo(Type type, out object typeInformation) { BinaryTypeEnum objectArray; typeInformation = null; if (ReferenceEquals(type, Converter.s_typeofString)) { objectArray = BinaryTypeEnum.String; } else if (ReferenceEquals(type, Converter.s_typeofObject)) { objectArray = BinaryTypeEnum.Object; } else if (ReferenceEquals(type, Converter.s_typeofObjectArray)) { objectArray = BinaryTypeEnum.ObjectArray; } else if (ReferenceEquals(type, Converter.s_typeofStringArray)) { objectArray = BinaryTypeEnum.StringArray; } else if (Converter.IsPrimitiveArray(type, out PrimitiveTypeEnum primitive)) { typeInformation = primitive; objectArray = BinaryTypeEnum.PrimitiveArray; } else { PrimitiveTypeEnum ee = Converter.ToCode(type); if (ee == PrimitiveTypeEnum.Invalid) { objectArray = type.Assembly == Converter.s_urtAssembly ? BinaryTypeEnum.ObjectUrt : BinaryTypeEnum.ObjectUser; typeInformation = type.FullName; } else { objectArray = BinaryTypeEnum.Primitive; typeInformation = ee; } } return(objectArray); }
/// <summary> /// Initialize the look up tables before anyone comes a calling /// </summary> static Converter() { Hashtable PrimitiveTypeToTypeLookup = new Hashtable(), PrimitiveTypeToArrayTypeLookup = new Hashtable(), PrimitiveTypeToStringLookup = new Hashtable(), PrimitiveTypeToTypeCodeLookup = new Hashtable(), TypeCodeToPrimitiveTypeLookup = new Hashtable(); foreach (string type in Enum.GetNames(typeof(PrimitiveTypeEnum))) { PrimitiveTypeEnum primitiveType = type.Parse <PrimitiveTypeEnum>(); PrimitiveTypeToStringLookup[primitiveType] = type; if (type.Equals(nameof(PrimitiveTypeEnum.Invalid), StringComparison.Ordinal)) { continue; } Type realType = Type.GetType($"System.{type}"); TypeCode typeCode = Type.GetTypeCode(realType); PrimitiveTypeToTypeLookup[primitiveType] = realType; PrimitiveTypeToTypeCodeLookup[primitiveType] = typeCode; TypeCodeToPrimitiveTypeLookup[typeCode] = primitiveType; if (type.Equals(nameof(PrimitiveTypeEnum.Null), StringComparison.Ordinal)) { continue; } PrimitiveTypeToArrayTypeLookup[primitiveType] = realType.MakeArrayType(); } s_PrimitiveTypeToTypeLookup = PrimitiveTypeToTypeLookup; s_PrimitiveTypeToArrayTypeLookup = PrimitiveTypeToArrayTypeLookup; s_PrimitiveTypeToStringLookup = PrimitiveTypeToStringLookup; s_PrimitiveTypeToTypeCodeLookup = PrimitiveTypeToTypeCodeLookup; s_TypeCodeToPrimitiveTypeLookup = TypeCodeToPrimitiveTypeLookup; }
public void Read(Stream src) { PrimitiveTypeEnum primitiveType = (PrimitiveTypeEnum)src.ReadByte(); if (primitiveType == PrimitiveTypeEnum.Int) { _value = StreamHelper.ReadInt32(src); } else if (primitiveType == PrimitiveTypeEnum.UInt) { _value = StreamHelper.ReadUInt32(src); } else if (primitiveType == PrimitiveTypeEnum.Bool) { _value = StreamHelper.ReadBool(src); } else if (primitiveType == PrimitiveTypeEnum.String) { _value = StreamHelper.ReadString(src); } else if (primitiveType == PrimitiveTypeEnum.Byte) { _value = src.ReadByte(); } else if (primitiveType == PrimitiveTypeEnum.ByteA) { _value = StreamHelper.ReadBytesSafe(src); } else if (primitiveType == PrimitiveTypeEnum.UShort) { _value = StreamHelper.ReadUInt16(src); } else { throw new NotSupportedException(string.Format("The type '{0}' is not supported by TypedPrimitive", primitiveType)); } }
public void Init() { parseTypeEnum = ParseTypeEnum.Empty; objectTypeEnum = ObjectTypeEnum.Empty; arrayTypeEnum = ArrayTypeEnum.Empty; memberTypeEnum = MemberTypeEnum.Empty; memberValueEnum = MemberValueEnum.Empty; objectPositionEnum = ObjectPositionEnum.Empty; name = null; value = null; keyDt = null; dtType = null; dtTypeCode = PrimitiveTypeEnum.Invalid; objectId = 0L; idRef = 0L; arrayElementTypeString = null; arrayElementType = null; isArrayVariant = false; arrayElementTypeCode = PrimitiveTypeEnum.Invalid; rank = 0; lengthA = null; lowerBoundA = null; indexMap = null; memberIndex = 0; linearlength = 0; rectangularMap = null; isLowerBound = false; isValueTypeFixup = false; newObj = null; objectA = null; primitiveArray = null; objectInfo = null; isRegistered = false; memberData = null; si = null; consecutiveNullArrayEntryCount = 0; }
internal void WriteMember(NameInfo memberNameInfo, NameInfo typeNameInfo, object value) { this.InternalWriteItemNull(); PrimitiveTypeEnum primitiveTypeEnum = typeNameInfo._primitiveTypeEnum; if (memberNameInfo._transmitTypeOnMember) { if (this._memberPrimitiveTyped == null) { this._memberPrimitiveTyped = new MemberPrimitiveTyped(); } this._memberPrimitiveTyped.Set(primitiveTypeEnum, value); this._memberPrimitiveTyped.Write(this); } else { if (this._memberPrimitiveUnTyped == null) { this._memberPrimitiveUnTyped = new MemberPrimitiveUnTyped(); } this._memberPrimitiveUnTyped.Set(primitiveTypeEnum, value); this._memberPrimitiveUnTyped.Write(this); } }
public static void TypeFromInfo(BinaryTypeEnum binaryTypeEnum, object typeInformation, ObjectReader objectReader, BinaryAssemblyInfo assemblyInfo, out PrimitiveTypeEnum primitiveTypeEnum, out string typeString, out Type type, out bool isVariant) { isVariant = false; primitiveTypeEnum = PrimitiveTypeEnum.Invalid; typeString = null; type = null; switch (binaryTypeEnum) { case BinaryTypeEnum.Primitive: primitiveTypeEnum = (PrimitiveTypeEnum)typeInformation; typeString = Converter.ToComType(primitiveTypeEnum); type = Converter.ToType(primitiveTypeEnum); return; case BinaryTypeEnum.String: type = Converter.s_typeofString; return; case BinaryTypeEnum.Object: type = Converter.s_typeofObject; isVariant = true; return; case BinaryTypeEnum.ObjectUrt: case BinaryTypeEnum.ObjectUser: if (typeInformation != null) { typeString = typeInformation.ToString(); type = objectReader.GetType(assemblyInfo, typeString); if (type == Converter.s_typeofObject) { isVariant = true; return; } } return; case BinaryTypeEnum.ObjectArray: type = Converter.s_typeofObjectArray; return; case BinaryTypeEnum.StringArray: type = Converter.s_typeofStringArray; return; case BinaryTypeEnum.PrimitiveArray: primitiveTypeEnum = (PrimitiveTypeEnum)typeInformation; type = Converter.ToArrayType(primitiveTypeEnum); return; } throw new SerializationException(RemotingResources.SerializationTypeRead.Format(binaryTypeEnum)); }
internal void Set(PrimitiveTypeEnum primitiveTypeEnum, object value) { this.PrimitiveTypeEnum = primitiveTypeEnum; this.Value = value; }
public static BinaryTypeEnum GetBinaryTypeInfo(Type type, WriteObjectInfo objectInfo, ObjectWriter objectWriter, out object typeInformation, out int assemId) { BinaryTypeEnum stringArray; assemId = 0; typeInformation = null; if (ReferenceEquals(type, Converter.s_typeofString)) { stringArray = BinaryTypeEnum.String; } else if ((objectInfo == null || objectInfo != null && !objectInfo._isSi) && ReferenceEquals(type, Converter.s_typeofObject)) { stringArray = BinaryTypeEnum.Object; } else if (ReferenceEquals(type, Converter.s_typeofStringArray)) { stringArray = BinaryTypeEnum.StringArray; } else if (ReferenceEquals(type, Converter.s_typeofObjectArray)) { stringArray = BinaryTypeEnum.ObjectArray; } else if (Converter.IsPrimitiveArray(type, out PrimitiveTypeEnum primitive)) { typeInformation = primitive; stringArray = BinaryTypeEnum.PrimitiveArray; } else { PrimitiveTypeEnum ee = objectWriter.ToCode(type); if (ee != PrimitiveTypeEnum.Invalid) { stringArray = BinaryTypeEnum.Primitive; typeInformation = ee; } else { string fullName; if (objectInfo == null) { fullName = type.Assembly.FullName; typeInformation = type.FullName; } else { fullName = objectInfo.GetAssemblyString(); typeInformation = objectInfo.GetTypeFullName(); } if (fullName.Equals(Converter.s_urtAssemblyString) || fullName.Equals(Converter.s_urtAlternativeAssemblyString)) { stringArray = BinaryTypeEnum.ObjectUrt; assemId = 0; } else { stringArray = BinaryTypeEnum.ObjectUser; assemId = (int)objectInfo._assemId; if (assemId == 0) { throw new SerializationException(RemotingResources.SerializationAssemblyId.Format(typeInformation)); } } } } return(stringArray); }
internal void Set(PrimitiveTypeEnum typeInformation) { this._typeInformation = typeInformation; }
internal void Set(PrimitiveTypeEnum typeInformation, object value) { this._typeInformation = typeInformation; this._value = value; }
internal object ReadValue(PrimitiveTypeEnum code) { object obj2; #pragma warning disable IDE0066 // Convert switch statement to expression switch (code) #pragma warning restore IDE0066 // Convert switch statement to expression { case PrimitiveTypeEnum.Boolean: obj2 = ReadBoolean(); break; case PrimitiveTypeEnum.Byte: obj2 = ReadByte(); break; case PrimitiveTypeEnum.Char: obj2 = ReadChar(); break; case PrimitiveTypeEnum.Decimal: obj2 = ReadDecimal(); break; case PrimitiveTypeEnum.Double: obj2 = (double)ReadDouble(); break; case PrimitiveTypeEnum.Int16: obj2 = ReadInt16(); break; case PrimitiveTypeEnum.Int32: obj2 = ReadInt32(); break; case PrimitiveTypeEnum.Int64: obj2 = ReadInt64(); break; case PrimitiveTypeEnum.SByte: obj2 = ReadSByte(); break; case PrimitiveTypeEnum.Single: obj2 = (float)ReadSingle(); break; case PrimitiveTypeEnum.TimeSpan: obj2 = ReadTimeSpan(); break; case PrimitiveTypeEnum.DateTime: obj2 = ReadDateTime(); break; case PrimitiveTypeEnum.UInt16: obj2 = ReadUInt16(); break; case PrimitiveTypeEnum.UInt32: obj2 = ReadUInt32(); break; case PrimitiveTypeEnum.UInt64: obj2 = ReadUInt64(); break; default: throw new SerializationException(RemotingResources.SerializationTypeCode.Format(code.ToString())); } return(obj2); }
public void WriteValue(PrimitiveTypeEnum code, object value) { switch (code) { case PrimitiveTypeEnum.Boolean: this.Write(Utilities.Cast <bool>(value)); return; case PrimitiveTypeEnum.Byte: this.Write(Utilities.Cast <byte>(value)); return; case PrimitiveTypeEnum.Char: this.Write(Utilities.Cast <char>(value)); return; case PrimitiveTypeEnum.Decimal: this.Write(Utilities.Cast <decimal>(value)); return; case PrimitiveTypeEnum.Double: this.Write(Utilities.Cast <double>(value)); return; case PrimitiveTypeEnum.Int16: this.Write(Utilities.Cast <short>(value)); return; case PrimitiveTypeEnum.Int32: this.Write(Utilities.Cast <int>(value)); return; case PrimitiveTypeEnum.Int64: this.Write(Utilities.Cast <long>(value)); return; case PrimitiveTypeEnum.SByte: this.Write(Utilities.Cast <sbyte>(value)); return; case PrimitiveTypeEnum.Single: this.Write(Utilities.Cast <float>(value)); return; case PrimitiveTypeEnum.TimeSpan: this.Write(Utilities.Cast <TimeSpan>(value).Ticks); return; case PrimitiveTypeEnum.DateTime: this.Write(Utilities.Cast <DateTime>(value)); return; case PrimitiveTypeEnum.UInt16: this.Write(Utilities.Cast <ushort>(value)); return; case PrimitiveTypeEnum.UInt32: this.Write(Utilities.Cast <uint>(value)); return; case PrimitiveTypeEnum.UInt64: this.Write(Utilities.Cast <ulong>(value)); return; } throw new SerializationException(RemotingResources.SerializationTypeCode.Format(code.ToString())); }