public override CodeNode VisitReadFixedString(ReadFixedStringNode node) { _Writer.WriteStartElement("ReadFixedString"); _Writer.WriteAttributeString("Length", node.Length.ToString()); _Writer.WriteEndElement(); return(node); }
public override CodeNode VisitReadFixedString(ReadFixedStringNode node) { if (_FieldLocal == null) { throw new InvalidOperationException("Cannot read string outside a FieldAssignmentNode"); } ILGen.Ldloc(_Reader); ILGen.Ldc_I4(node.Length); ILGen.Callvirt(_ReadFixedStringMethod); ILGen.Stloc(_FieldLocal); return(node); }
CodeNode GenerateAssignment(KeyValuePair <FieldLayoutAttribute, PropertyInfo> pair) { var fieldType = pair.Key.FieldType; //if this is an array, defer to GenerateArrayAssignment if (pair.Key is ArrayFieldLayoutAttribute) { // TODO: Why do we need these fieldType checks at all? if (fieldType == typeof(string)) { // TODO: Accept string arrays throw new InvalidOperationException(Resources.NoStringArrays); } if (fieldType == typeof(BitArray)) { throw new InvalidOperationException(Resources.NoBitArrayArrays); } return(GenerateArrayAssignment(pair)); } //get the length if this is a fixed-length string var stringLength = -1; if (pair.Key is StringFieldLayoutAttribute stringLayout && stringLayout.Length > 0) { stringLength = stringLayout.Length; } //just skip this field if we have an assignment, but shouldn't be parsing it if (pair.Value != null && !ShouldParseField(pair.Value.Name)) { if (stringLength > 0) { return(new SkipRawBytesNode(stringLength)); } else { return(new SkipTypeNode(fieldType)); } } //determine how we'll read the field CodeNode readerNode; if (stringLength > 0) { readerNode = new ReadFixedStringNode(stringLength); } else { readerNode = new ReadTypeNode(fieldType); } BlockNode assignmentBlock = null; //if we have a property to assign to, generate the appropriate assignment statements if (pair.Value != null) { var assignmentNodes = new List <CodeNode>(); //if this is optional, set us up to skip if the missing flag is set if (pair.Key is FlaggedFieldLayoutAttribute optionalLayout) { assignmentNodes.Add(new SkipAssignmentIfFlagSetNode(optionalLayout.FlagIndex, optionalLayout.FlagMask)); } //if we have a missing value, set us up to skip if the value matches the missing value else if (pair.Key.MissingValue != null && !pair.Key.PersistMissingValue) { if (!(fieldType.IsAssignableFrom(pair.Key.MissingValue.GetType()))) { throw new InvalidOperationException(string.Format("Missing value {0} is not assignable to {1}.", pair.Key.MissingValue, fieldType)); } assignmentNodes.Add(new SkipAssignmentIfMissingValueNode(pair.Key.MissingValue)); } //set us up to assign to the property assignmentNodes.Add(new AssignFieldToPropertyNode(fieldType, pair.Value)); assignmentBlock = new BlockNode(assignmentNodes); } return(new FieldAssignmentNode(fieldType, pair.Key.FieldIndex, readerNode, assignmentBlock)); }
public virtual CodeNode VisitReadFixedString(ReadFixedStringNode node) { return(node); }