private bool TryGetEncoding(IAttributedInstance symbol, out Encoding encoding) { bool flag = EncodingAttributeConverter.TryGetEncoding(symbol.Attributes, out encoding); if (!flag && (symbol.DataType.Category == DataTypeCategory.String)) { IStringType dataType = (IStringType)symbol.DataType; encoding = dataType.Encoding; flag = true; } return(flag); }
public PERAlphabetAndSizeEffectiveConstraint(Char? min, Char? max, IStringType strType) { if (strType == null) throw new Exception("Internal Error"); if (min ==null && max ==null) throw new Exception("Internal Error"); if (min != null && max != null) { m_from = new CharSet(min.Value, max.Value); } else if (min != null && max == null) { m_from = new CharSet(min.Value, strType.AllowedCharSet[strType.AllowedCharSet.Length - 1]); } else if (min == null && max != null) { m_from = new CharSet(strType.AllowedCharSet[0], max.Value); } }
internal StringInstance(ISymbol parent, IStringType type, string instanceName, int fieldOffset) : base(parent, type, instanceName, fieldOffset, ((ISymbolFactoryServicesProvider)parent).FactoryServices) { base.category = DataTypeCategory.String; }
internal StringInstance(AdsSymbolEntry entry, IStringType type, ISymbol parent, ISymbolFactoryServices factoryServices) : base(entry, type, parent, factoryServices) { base.category = DataTypeCategory.String; }
private Symbol createArrayElement(int[] currentIndex, bool oversample, ISymbol parent, ArrayType arrType, DataType elementType) { bool flag = true; DataTypeCategory unknown = DataTypeCategory.Unknown; if (elementType != null) { unknown = elementType.Category; } Symbol symbol = null; if (unknown == DataTypeCategory.Bitset) { symbol = new Symbol(currentIndex, oversample, parent); } else if (unknown == DataTypeCategory.Primitive) { symbol = new Symbol(currentIndex, oversample, parent); } else if (unknown == DataTypeCategory.Array) { symbol = !arrType.IsOversampled ? new ArrayInstance(currentIndex, false, parent) : new OversamplingArrayInstance(currentIndex, oversample, parent); } else if (unknown == DataTypeCategory.Struct) { symbol = !((IStructType)elementType).HasRpcMethods ? new StructInstance(currentIndex, oversample, parent) : new RpcStructInstance(currentIndex, oversample, parent); } else if (unknown == DataTypeCategory.Union) { symbol = new UnionInstance(currentIndex, oversample, parent); } else if (unknown == DataTypeCategory.Reference) { symbol = new ReferenceInstance(currentIndex, oversample, parent); } else if (unknown == DataTypeCategory.Pointer) { symbol = new PointerInstance(currentIndex, oversample, parent); } else if (unknown == DataTypeCategory.Union) { symbol = new Symbol(currentIndex, oversample, parent); } else if (unknown == DataTypeCategory.Enum) { symbol = new Symbol(currentIndex, oversample, parent); } else if (unknown == DataTypeCategory.Alias) { AliasType type3 = (AliasType)elementType; symbol = new AliasInstance(currentIndex, oversample, parent); } else if (unknown != DataTypeCategory.String) { symbol = new Symbol(currentIndex, oversample, parent); } else { IStringType type4 = (IStringType)elementType; symbol = new StringInstance(currentIndex, oversample, parent); } if (flag) { symbol.SetComment(parent.Comment); } return(symbol); }
protected override ISymbol OnCreateString(ISymbolInfo entry, IStringType stringType, ISymbol parent) => new StringInstance((AdsSymbolEntry)entry, stringType, parent, base.services);
protected abstract ISymbol OnCreateString(ISymbolInfo entry, IStringType stringType, ISymbol parent);
/// <summary> /// Get book info /// </summary> /// <param name="book">Book</param> /// <param name="st">Format type</param> /// <returns>Book info</returns> public string getInfo(Book book, IStringType st) { return(st.getInfo(book)); }
public override void WriteValue(ISymbol symbol, object value, out DateTime utcWriteTime) { if (symbol == null) { throw new ArgumentNullException("symbol"); } if (value == null) { throw new ArgumentNullException("value"); } int num = 0; ISymbol symbol2 = symbol; IDataType dataType = symbol2.DataType; IResolvableType type2 = dataType as IResolvableType; if (type2 != null) { dataType = type2.ResolveType(DataTypeResolveStrategy.AliasReference); } utcWriteTime = DateTime.MinValue; if (dataType.IsBitType) { num = this.tryWriteValue(symbol2, BitTypeConverter.Marshal(dataType.BitSize, value), 0, out utcWriteTime); } else if (!symbol2.IsPrimitiveType) { DynamicValue value2 = (DynamicValue)value; num = this.TryWriteValue(value2, out utcWriteTime); } else if (((dataType.Category == DataTypeCategory.Primitive) || (dataType.Category == DataTypeCategory.SubRange)) || (dataType.Category == DataTypeCategory.Pointer)) { num = this.tryWriteValue(symbol2, PrimitiveTypeConverter.Default.Marshal(symbol2.DataType, value), 0, out utcWriteTime); } else if (dataType.Category == DataTypeCategory.String) { IStringType type3 = (IStringType)symbol2.DataType; byte[] buffer3 = new PrimitiveTypeConverter(type3.Encoding).Marshal(symbol2.DataType, value); if (buffer3.Length >= type3.Size) { Exception ex = new AdsErrorException($"String is too large for symbol '{symbol2.InstancePath}' (Type: {symbol2.TypeName}).", AdsErrorCode.DeviceInvalidSize); Module.Trace.TraceError(ex); throw ex; } num = this.tryWriteValue(symbol2, buffer3, 0, out utcWriteTime); } else if (dataType.Category == DataTypeCategory.Array) { IArrayType type4 = (IArrayType)symbol2.DataType; num = this.tryWriteValue(symbol2, PrimitiveTypeConverter.Default.Marshal(symbol2.DataType, value), 0, out utcWriteTime); } else { if (dataType.Category != DataTypeCategory.Enum) { Exception ex = new SymbolException($"Could not write Symbol '{symbol2.InstancePath}' (Type: {symbol2.TypeName}). Category mismatch!", symbol2); Module.Trace.TraceError(ex); throw ex; } IEnumType type5 = (IEnumType)symbol2.DataType; num = this.tryWriteValue(symbol2, PrimitiveTypeConverter.Default.Marshal(symbol2.DataType, value), 0, out utcWriteTime); } if (num != 0) { Exception ex = new SymbolException($"Could not write Symbol '{symbol2.InstancePath}' (Type: {symbol2.TypeName})! Error: {num}", symbol2); Module.Trace.TraceError(ex); throw ex; } }