public HandleSumWriteAnyEntity(uint handle, System.Type tp, PrimitiveTypeConverter converter) : base(handle, 0, -1, converter) { this.Type = tp; if (tp == typeof(string)) { base.writeLength = -1; } else { base.writeLength = PrimitiveTypeConverter.MarshalSize(tp); } }
private void CheckType(IDataType type, Type targetType) { List <IDataType> list = null; if (this._checkedTypesDict.TryGetValue(targetType, out list) && list.Contains(type)) { return; } switch (type.Category) { case DataTypeCategory.Primitive: case DataTypeCategory.Pointer: case DataTypeCategory.Reference: if (type.ByteSize > PrimitiveTypeConverter.MarshalSize(targetType)) { throw new MarshalException($"Source type '{type.Name}' is larger than target type '{targetType.Name}'!"); } goto TR_0007; case DataTypeCategory.Alias: { IAliasType type2 = (IAliasType)type; try { this.CheckType(type2.BaseType, targetType); } catch (MarshalException exception) { throw new MarshalException($"Cannot Marshal Alias '{type2.Name}' !", exception); } goto TR_0007; } case DataTypeCategory.Enum: { IEnumType type3 = (IEnumType)type; if (!targetType.IsEnum) { IManagedMappableType baseType = type3.BaseType as IManagedMappableType; bool flag = false; if (baseType == null) { throw new MarshalException($"Type '{targetType.Name}' is not an enum type or enum base type!"); } flag = baseType.ManagedType == targetType; } else { string[] names = type3.EnumValues.GetNames(); string[] strArray2 = Enum.GetNames(targetType); if (names.Length > strArray2.Length) { throw new MarshalException($"Enum Types '{type.Name}' and '{targetType.Name}' are not compatible!"); } StringComparer ordinalIgnoreCase = StringComparer.OrdinalIgnoreCase; string[] strArray3 = names; int index = 0; while (index < strArray3.Length) { string x = strArray3[index]; bool flag2 = false; string[] strArray4 = strArray2; int num5 = 0; while (true) { if (num5 < strArray4.Length) { string y = strArray4[num5]; if (ordinalIgnoreCase.Compare(x, y) != 0) { num5++; continue; } flag2 = true; } if (!flag2) { throw new MarshalException($"Enum Types '{type.Name}' and '{targetType.Name}' are not compatible!"); } index++; break; } } } goto TR_0007; } case DataTypeCategory.Array: { IArrayType type4 = (IArrayType)type; if (!targetType.IsArray) { throw new MarshalException($"Type '{targetType.Name}' is not an array type!"); } int arrayRank = targetType.GetArrayRank(); if (type4.Dimensions.Count != arrayRank) { throw new MarshalException($"Array Types '{type.Name}' and '{targetType.Name}' are not compatible!"); } Type elementType = targetType.GetElementType(); try { this.CheckType(type4.ElementType, elementType); } catch (MarshalException exception2) { throw new MarshalException($"Cannot Marshal Elements of Array '{type4.Name}'!", exception2); } goto TR_0007; } case DataTypeCategory.Struct: foreach (IMember member in ((IStructType)type).AllMembers) { PropertyInfo property = targetType.GetProperty(member.InstanceName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase); if (property != null) { this.CheckType(member.DataType, property.PropertyType); continue; } FieldInfo field = targetType.GetField(member.InstanceName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase); if (field != null) { Type fieldType = field.FieldType; try { this.CheckType(member.DataType, fieldType); } catch (MarshalException exception3) { IStructType type6; throw new MarshalException($"Cannot Marshal Member '{member.InstanceName}' of Source Struct '{type6.Name}' to field '{field.Name}' of target struct '{targetType.Name}'!", exception3); } } } goto TR_0007; case DataTypeCategory.SubRange: { ISubRangeType type9 = (ISubRangeType)type; try { this.CheckType(type9.BaseType, targetType); } catch (MarshalException exception4) { throw new MarshalException($"Cannot Marshal Subrange '{type9.Name}'!", exception4); } goto TR_0007; } case DataTypeCategory.String: break; case DataTypeCategory.Bitset: case DataTypeCategory.Union: goto TR_0007; default: throw new NotSupportedException(); } if (targetType != typeof(string)) { throw new MarshalException($"Type mismatch! Target Type '{type.Name}' is not a string (Marshalling AdsType '{targetType.Name}')!"); } TR_0007: if (list == null) { list = new List <IDataType>(); if (!this._checkedTypesDict.ContainsKey(targetType)) { this._checkedTypesDict.Add(targetType, list); } } list.Add(type); }
public HandleSumReadAnyEntity(uint handle, Type tp, PrimitiveTypeConverter converter) : base(handle, converter) { base.readLength = PrimitiveTypeConverter.MarshalSize(tp); base.writeLength = 0; this.TypeSpec = new AnyTypeSpecifier(tp); }
public HandleSumReadAnyEntity(uint handle, int strLen, PrimitiveTypeConverter converter) : base(handle, -1, 0, converter) { this.TypeSpec = new AnyTypeSpecifier(typeof(string), strLen); base.readLength = converter.MarshalSize(strLen); }