parameters: (self, cpp_namespace, type_)
return_statement: return c
docstring: Generates a function that serializes the type into a |DictionaryValue|.
  
      E.g. for type "Foo" generates Foo::ToValue()
docstring_summary: Generates a function that serializes the type into a |DictionaryValue|.
docstring_tokens: Generates a function that serializes the type into a |DictionaryValue| .
function: def _GenerateTypeToValue(self, cpp_namespace, type_):
      """Generates a function that serializes the type into a |DictionaryValue|.
  
      E.g. for type "Foo" generates Foo::ToValue()
      """
      c = Code()
      (c.Sblock('scoped_ptr<DictionaryValue> %s::ToValue() const {' %
            cpp_namespace)
          .Append('scoped_ptr<DictionaryValue> value(new DictionaryValue());')
          .Append()
      )
      for prop in type_.properties.values():
        if prop.type_ == PropertyType.ADDITIONAL_PROPERTIES:
          c.Append('value->MergeDictionary(&%s);' % prop.unix_name)
        else:
          if prop.optional:
            if prop.type_ == PropertyType.ENUM:
              c.Sblock('if (%s != %s)' %
                  (prop.unix_name,
                      self._cpp_type_generator.GetEnumNoneValue(prop)))
            else:
              c.Sblock('if (%s.get())' % prop.unix_name)
          c.Append('value->SetWithoutPathExpansion("%s", %s);' % (
              prop.name,
              self._CreateValueFromProperty(prop, 'this->' + prop.unix_name)))
          if prop.optional:
            c.Eblock();
      (c.Append()
        .Append('return value.Pass();')
        .Eblock('}')
      )
      return c
function_tokens: def _GenerateTypeToValue ( self , cpp_namespace , type_ ) : c = Code ( ) ( c . Sblock ( 'scoped_ptr<DictionaryValue> %s::ToValue() const {' % cpp_namespace ) . Append ( 'scoped_ptr<DictionaryValue> value(new DictionaryValue());' ) . Append ( ) ) for prop in type_ . properties . values ( ) : if prop . type_ == PropertyType . ADDITIONAL_PROPERTIES : c . Append ( 'value->MergeDictionary(&%s);' % prop . unix_name ) else : if prop . optional : if prop . type_ == PropertyType . ENUM : c . Sblock ( 'if (%s != %s)' % ( prop . unix_name , self . _cpp_type_generator . GetEnumNoneValue ( prop ) ) ) else : c . Sblock ( 'if (%s.get())' % prop . unix_name ) c . Append ( 'value->SetWithoutPathExpansion("%s", %s);' % ( prop . name , self . _CreateValueFromProperty ( prop , 'this->' + prop . unix_name ) ) ) if prop . optional : c . Eblock ( ) ( c . Append ( ) . Append ( 'return value.Pass();' ) . Eblock ( '}' ) ) return c