public override void EmitNodeAttributeHandler(CodeGenLib.CodeFormatter cf) { if (isAdditionalMapping) { cf.FormatLine("private void Handle{0}Node{1}AttributeAdditional(string sValue)", NodeName, AttrName); } else { cf.FormatLine("private void Handle{0}Node{1}Attribute(string sValue)", NodeName, AttrName); } cf.WriteLine("{"); cf.WriteLine("switch (sValue)"); cf.WriteLine("{"); foreach (string key in attrValueMappings.Keys) { cf.FormatLine("case \"{0}\":", key); cf.WriteLine("{"); cf.FormatLine("m_dataObject.{0} = {1};", FieldName, attrValueMappings[key]); cf.WriteLine("break;"); cf.WriteLine("}"); } if(!string.IsNullOrEmpty(MissingFieldValue)) { cf.WriteLine("default:"); cf.WriteLine("{"); cf.FormatLine("m_dataObject.{0} = {1};", FieldName, MissingFieldValue); cf.WriteLine("break;"); cf.WriteLine("}"); } cf.WriteLine("}"); cf.WriteLine("}"); }
internal void EmitHandler(CodeGenLib.CodeFormatter cf) { if (attrValueMappings.Count == 0) { if(String.IsNullOrEmpty(NodeNameSpace)) { cf.FormatLine("m_dataObject.{0} = {1};", FieldName, BuildGetAttributeCode(AttrName, TypeName)); } else if(!RawReadAttribute ) { cf.FormatLine("m_dataObject.{0} = {1};", FieldName, BuildGetAttributeCode(AttrName, TypeName, NodeNameSpace)); } else if(RawReadAttribute) { cf.FormatLine("m_dataObject.{0} = reader.GetAttribute(\"{1}\");", FieldName, AttrName); } } else { cf.FormatLine("switch ({0})", BuildGetAttributeCode(AttrName, "string")); cf.WriteLine("{"); foreach (string key in attrValueMappings.Keys) { cf.BeginCase("\"" + key + "\""); cf.FormatLine("m_dataObject.{0} = {1};", FieldName, attrValueMappings[key]); cf.EndCase(); } cf.WriteLine("}"); } }
public override void EmitCaseHandlerBody(CodeGenLib.CodeFormatter cf) { if (IsDictionaryField()) { EmitDictionaryFieldHandler(cf); } else { string handler = GenerationContext.GetRegisteredNodeHandler(NodeName, TypeName); if (handler == null && !DispatchStartElementWhenNodeStarted) { HandleSimpleAssign(cf); } else if(handler != null && (DispatchStartElementWhenNodeStarted || NullStartElementWhenNodeStarted) ) { HandleSimpleNodeHandler(cf); } else { EnsureFieldNotNull(cf); if (ListField) { HandleListField(cf, handler); } else { cf.FormatLine("SubConsumer = new {0}(m_dataObject.{1}, Context);", handler, FieldName, IsHasContentField ? "true" : ""); if (StopParentElementDispatch) { cf.WriteLine(); cf.FormatLine("m_dispatchThis = false;"); } } } } }
public override void EmitCaseHandlerEnd(CodeGenLib.CodeFormatter cf) { cf.WriteLine("break;"); cf.WriteLine("}"); }
public override void EmitCaseHandlerStart(CodeGenLib.CodeFormatter cf) { cf.FormatLine("case \"{0}\":", NodeName); cf.WriteLine("{"); }
private void HandleSimpleNodeHandler(CodeGenLib.CodeFormatter cf) { cf.FormatLine("SubConsumer = new {0}_Handler(Context);", NodeName); if (DispatchStartElementWhenNodeStarted) { cf.WriteLine("AddCompletedObject(m_dataObject);"); } cf.FormatLine("m_dataObject = null;"); if (StopParentElementDispatch) { cf.WriteLine(); cf.FormatLine("m_dispatchThis = false;"); } }
private void EnsureFieldNotNull(CodeGenLib.CodeFormatter cf) { cf.FormatLine("if (m_dataObject.{0} == null)", FieldName); cf.WriteLine("{"); if(ListField) cf.FormatLine("m_dataObject.{0} = new {1}();", FieldName, TypeName.Replace("^", "")); else cf.FormatLine("m_dataObject.{0} = new {1}({2});", FieldName, TypeName.Replace("^", ""), IsHasContentField ? "true" : ""); cf.WriteLine("}"); }
public override void EmitCompleteHandler(CodeGenLib.CodeFormatter cf) { if (IsDictionaryField()) { cf.FormatLine("if(m_dataObject == null || m_dataObject.{0} == null)", FieldName); cf.WriteLine("{"); cf.WriteLine("return;"); cf.WriteLine("}"); cf.FormatLine("if (subConsumerOutput is {0})", DeduceDictionaryValueType()); cf.WriteLine("{"); cf.FormatLine("{0} output = subConsumerOutput as {0};", DeduceDictionaryValueType()); cf.FormatLine("if( output.{0} == null )", DictionaryIndexProperty); cf.WriteLine("{"); cf.WriteLine( "return;" ); cf.WriteLine( "}" ); cf.FormatLine("m_dataObject.{0}.Add(output.{1}, output);", FieldName, DictionaryIndexProperty); cf.WriteLine("}"); } else if (DispatchStartElementWhenNodeComplete) { cf.FormatLine("if (subConsumerOutput is {0})", TypeName); cf.WriteLine("{"); cf.WriteLine("AddCompletedObject(m_dataObject);"); cf.FormatLine("m_dataObject = null;"); cf.WriteLine("}"); } }
private void HandleListField(CodeGenLib.CodeFormatter cf, string handler) { string NoHatType = TypeName; if (NoHatType.StartsWith("List<")) // in case you change the rules elsewhere { int iClosed = NoHatType.LastIndexOf('>'); if (iClosed < 6) throw new Exception("Unmatched <> in " + TypeName); NoHatType = NoHatType.Substring(5, iClosed - 5); } NoHatType = NoHatType.Replace("^", ""); cf.FormatLine("{0} item = new {1}({2});", NoHatType, NoHatType, IsHasContentField ? "true" : ""); cf.FormatLine("m_dataObject.{0}.Add(item);", FieldName); cf.FormatLine("SubConsumer = new {0}(item, Context);", handler); if (StopParentElementDispatch) { cf.WriteLine(); cf.FormatLine("m_dispatchThis = false;"); } }