System.Yaml.Serialization.YamlRepresenter.ObjectToNodeSub C# (CSharp) Méthode

ObjectToNodeSub() private méthode

private ObjectToNodeSub ( object obj, Type expect ) : YamlNode
obj object
expect Type
Résultat YamlNode
        YamlNode ObjectToNodeSub(object obj, Type expect)
        {
            // !!null
            if ( obj == null )
                return str("!!null", "null");

            YamlScalar node;
            if ( config.TagResolver.Encode(obj, out node) )
                return node;

            var type = obj.GetType();

            if ( obj is IntPtr || type.IsPointer )
                throw new ArgumentException("Pointer object '{0}' can not be serialized.".DoFormat(obj.ToString()));

            if ( obj is char ) {
                // config.TypeConverter.ConvertToString("\0") does not show "\0"
                var n = str(TypeNameToYamlTag(type), obj.ToString() );
                return n;
            }

            // bool, byte, sbyte, decimal, double, float, int ,uint, long, ulong, short, ushort, string, enum
            if ( type.IsPrimitive || type.IsEnum || type == typeof(decimal) || type == typeof(string) ) {
                var n = str(TypeNameToYamlTag(type), config.TypeConverter.ConvertToString(obj) );
                return n;
            }

            // TypeConverterAttribute
            if ( EasyTypeConverter.IsTypeConverterSpecified(type) )
                return str(TypeNameToYamlTag(type), config.TypeConverter.ConvertToString(obj));

            // array
            if ( type.IsArray )
                return CreateArrayNode((Array)obj);

            if ( type == typeof(Dictionary<object, object>) )
                return DictionaryToMap(obj);

            // class / struct
            if ( type.IsClass || type.IsValueType )
                return CreateMapping(TypeNameToYamlTag(type), obj);

            throw new NotImplementedException(
                "Type '{0}' could not be written".DoFormat(type.FullName)
            );
        }