public override CodeNode VisitFieldAssignmentBlock(FieldAssignmentBlockNode node) { _Writer.WriteStartElement("FieldAssignmentBlock"); Visit(node.Block); _Writer.WriteEndElement(); return(node); }
public override CodeNode VisitFieldAssignmentBlock(FieldAssignmentBlockNode node) { _InFieldAssignmentBlock = true; _EndLabel = ILGen.DefineLabel(); try { var visitedBlock = VisitBlock(node.Block); ILGen.MarkLabel(_EndLabel); if (visitedBlock == node.Block) { return(node); } else { return(new FieldAssignmentBlockNode(visitedBlock as BlockNode ?? new BlockNode(visitedBlock))); } } finally { _InFieldAssignmentBlock = false; } }
/// <summary> /// Does the work of generating the appropriate code. /// </summary> internal void GenerateConverter() { List <KeyValuePair <FieldLayoutAttribute, PropertyInfo> > fields = GetFieldLayoutsAndAssignments(_Type); //pick up any fields that are required to parse the fields we need if (_Fields != null) { foreach (var pair in fields) { //if it's an assigned field that we are parsing if (pair.Value != null && _Fields.Contains(pair.Value.Name)) { //if it's an optional field if (pair.Key is FlaggedFieldLayoutAttribute op) { //if the flag index is an assigned field, add it to our list of parsed fields var prop = fields[op.FlagIndex].Value; if (prop != null) { _Fields.Add(prop.Name); } } else { if (pair.Key is DependencyProperty dep) { var prop = fields[dep.DependentOnIndex].Value; if (prop != null) { _Fields.Add(prop.Name); } } } } } } //generate the assignment nodes var assignments = from pair in fields //don't generate code for dependency properties where !(pair.Key is DependencyProperty) //this call through reflection is icky, but marginally better than the hard-coded table //we're just binding to the generic GenerateAssignment method for the field's type select GenerateAssignment(pair); //add the end label to the end of the assignments var assignmentBlock = new FieldAssignmentBlockNode(new BlockNode(assignments)); //This is the list of nodes to emit to create the converter var block = new BlockNode( new InitializeRecordNode(), new EnsureCompatNode(), new InitReaderNode(), //TODO: Replace TryFinally with something more semantic like BinaryReaderScopeBlock new TryFinallyNode( assignmentBlock, new DisposeReaderNode()), new ReturnRecordNode()); //visit the block with an emitting visitor new ConverterEmittingVisitor() { ILGen = _ILGen, ConcreteType = _Type, EnableLog = ConverterLog.IsLogging, }.Visit(block); }
public virtual CodeNode VisitFieldAssignmentBlock(FieldAssignmentBlockNode node) { return(node); }