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("}");
 }
 public override void EmitCaseHandlerBody(CodeGenLib.CodeFormatter cf)
 {
     foreach (KeyValuePair<string, string> pair in mappings)
     {
         string getatt = BuildGetAttributeCode("val", "String");
         cf.FormatLine("if({0} == \"{1}\")", getatt, pair.Value);
         cf.FormatLine("m_dataObject.{0} = true;", pair.Key);
     }
 }
 public override void EmitCaseHandlerBody(CodeGenLib.CodeFormatter cf)
 {
     if (isAdditionalMapping)
     {
         cf.FormatLine("Handle{0}Node{1}AttributeAdditional({2});", NodeName, AttrName, BuildGetAttributeCode(AttrName, "string"));
     }
     else
     {
         cf.FormatLine("Handle{0}Node{1}Attribute({2});", NodeName, AttrName, BuildGetAttributeCode(AttrName, "string"));
     }
 }
        public override void EmitCaseHandlerBody(CodeGenLib.CodeFormatter cf)
        {
            foreach (KeyValuePair<string, AttrFieldMapping> pair in mappings)
            {
                if (pair.Value.listField)
                {
                    if (!pair.Value.rawRead)
                    {
                        cf.FormatLine("m_dataObject.{0}.Add({1});", pair.Key,
                            BuildGetAttributeCode(pair.Value.name, fieldTypes[pair.Key]));
                    }
                    else if(pair.Value.rawRead)
                    {
                        if(string.IsNullOrEmpty(pair.Value.attrNamespace))
                            cf.FormatLine("m_dataObject.{0}.Add(reader.GetAttribute(\"{1}\"));", pair.Key, pair.Value.name);
                        else
                            cf.FormatLine("m_dataObject.{0}.Add(reader.GetAttribute(\"{1}\", \"{2}\"));", pair.Key, pair.Value.name, pair.Value.attrNamespace);

                    }
                }
                else if (!pair.Value.listField)
                {
                    if (HandleCaseInPartialClass)
                    {
                        cf.FormatLine("Handle{0}Node{1}Attribute(reader);", NodeName, pair.Key);
                    }
                    else
                    {
                        if (!pair.Value.rawRead)
                        {
                            cf.FormatLine("m_dataObject.{0} = {1};", pair.Key,
                                BuildGetAttributeCode(pair.Value.name, fieldTypes[pair.Key]));
                        }
                        else if (pair.Value.rawRead)
                        {
                            if (string.IsNullOrEmpty(pair.Value.attrNamespace))
                                cf.FormatLine("m_dataObject.{0} = reader.GetAttribute(\"{1}\");", pair.Key, pair.Value.name);
                            else
                                cf.FormatLine("m_dataObject.{0} = reader.GetAttribute(\"{1}\", \"{2}\");", pair.Key, pair.Value.name, pair.Value.attrNamespace);

                        }
                    }
                }
            }
        }
示例#5
0
        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;");
                        }
                    }
                }
            }
        }
示例#6
0
        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("}");
            }

        }
示例#7
0
 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("}");
 }
示例#8
0
 public virtual void EmitCompleteHandler(CodeGenLib.CodeFormatter cf)
 {
 }
 private void EmitEnumeratedAttributeHandlers(CodeGenLib.CodeFormatter cf)
 {
     foreach (IFieldMapping fm in mappings)
     {
         fm.EmitNodeAttributeHandler(cf);
     }
 }
示例#10
0
 public override void EmitCaseHandlerBody(CodeGenLib.CodeFormatter cf)
 {
     cf.FormatLine("m_dataObject.{0} = {1};", FieldName, FieldValue);
 }
示例#11
0
 public virtual void EmitNodeAttributeHandler(CodeGenLib.CodeFormatter cf)
 { 
 }
示例#12
0
 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;");
     }
 }
示例#13
0
 public override void EmitCaseHandlerEnd(CodeGenLib.CodeFormatter cf)
 {
     throw new Exception("The method or operation is not implemented.");
 }
示例#14
0
 protected override void WriteHeaderFile(CodeGenLib.ClassCreator cc)
 {
     throw new Exception("The method or operation is not implemented.");
 }
示例#15
0
 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("}");
     }
 }
示例#16
0
        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;");
            }
        }
示例#17
0
        private void HandleSimpleAssign(CodeGenLib.CodeFormatter cf)
        { 
            if (FieldIsCollection)
            {
                cf.FormatLine("m_dataObject.{0}.Add({2}{1});", FieldName, BuildGetAttributeCode(AttrName, TypeName), (Invert ? "!" : ""));
            }
            else
            {
                cf.FormatLine("m_dataObject.{0} = {2}{1};", FieldName, BuildGetAttributeCode(AttrName, TypeName), (Invert ? "!" : ""));
                string[] attributes = GenerationContext.ResolveAttributes(SchemaSupport.DefaultDocxNamespace + ":" + NodeName);
                foreach (string attr in attributes)
                {
                    if (attr != AttrName && !string.IsNullOrEmpty(attr))
                        cf.FormatLine("// {0} : Unhandled Attribute", attr);

                }
            }
        }
示例#18
0
 public override void EmitCaseHandlerStart(CodeGenLib.CodeFormatter cf)
 {
     cf.FormatLine("case \"{0}\":", NodeName);
     cf.WriteLine("{");
 }
示例#19
0
 private void EmitDictionaryFieldHandler(CodeGenLib.CodeFormatter cf)
 {
     string handler = GenerationContext.GetRegisteredNodeHandler(NodeName, DeduceDictionaryValueType());
     cf.FormatLine("SubConsumer = new {0}(Context);", handler);
 }
示例#20
0
 public override void EmitCaseHandlerEnd(CodeGenLib.CodeFormatter cf)
 {
     cf.WriteLine("break;");
     cf.WriteLine("}");
 }
示例#21
0
 abstract public void EmitCaseHandlerBody(CodeGenLib.CodeFormatter cf);