             value is undefined or
             value is vDefaultValue)
         value = vDefaultValue if value is undefined
-        aOptions[v] = value
+        v = k unless aSerialized
+        aObject[v] = value
+      if aNameRequired
+        k = if aSerialized then vAttributes.names.name else 'name'
+        aObject[k] = @name
     else
-      extend aOptions, @, (key, value)->
-        result = not aOptions.hasOwnProperty(key) and not (key in aExclude)
+      extend aObject, @, (key, value)->
+        result = not aObject.hasOwnProperty(key) and not (key in aExclude)
         if aSerialized
           result = result and key[0] isnt '$' and value isnt undefined
         result
-    aOptions
+      aObject.name = @name if aNameRequired
+    aObject
   _validate: (aValue, aOptions)->true
   error: (aMessage, aOptions)->
     name = (aOptions && (aOptions[NAME] || aOptions.name)) || String(@)

  #   skip some properties, custom filter.
  isSame: (aOptions)->
    #deepEqual @, aOptions
    for k,v of @mergeOptions()
      return false unless deepEqual aOptions[k], v
    return true

  createValue: (aValue, aOptions)->
    if aOptions and not @isSame(aOptions)
      aOptions = @mergeOptions(aOptions)
      # TODO: seperate the cache-able ability
      if isFunction Type.getCacheItem
        # this Type Factory is cache-able.


  ###
  encode: (aOptions)->
    aOptions = @mergeTo(aOptions, null, true)
    aOptions.encoding.encode @toObject(aOptions)
  decode: (aEncoded, aOptions) ->
    aOptions = aOptions.encoding.decode aEncoded
    aOptions = @mergeTo(aOptions)
  ###

  # Get(create) a global Type class or create new Value from the parametric
  # type object.
  # it will create a new type object if options is not the original(default)
  # type options.
  @from: (aObject) ->
    result = Type aObject
    if aObject.value? and result
