ConvertAnother() private method

private ConvertAnother ( object value ) : void
value object
return void
コード例 #1
0
ファイル: Marshaller.cs プロジェクト: rollandx/xstream.net
 private void MarshalAs(object value, Type type)
 {
     if (type.Equals(typeof(object)))
     {
         return;
     }
     FieldInfo[] fields = type.GetFields(Constants.BINDINGFlags);
     foreach (var field in fields)
     {
         string nodeName = field.Name;
         Match  match    = Constants.AutoPropertyNamePattern.Match(field.Name);
         if (match.Success)
         {
             nodeName = match.Result("$1");
         }
         if (field.GetCustomAttributes(typeof(DontSerialiseAttribute), true).Length != 0)
         {
             continue;
         }
         if (field.GetCustomAttributes(typeof(XmlIgnoreAttribute), true).Length != 0)
         {
             continue;
         }
         if (typeof(MulticastDelegate).IsAssignableFrom(field.FieldType))
         {
             continue;
         }
         writer.StartNode(nodeName);
         WriteClassNameIfNeedBe(value, field);
         context.ConvertAnother(field.GetValue(value));
         writer.EndNode();
     }
     MarshalAs(value, type.BaseType);
 }
コード例 #2
0
 private void MarshalAs(object containingObject, Type type, XStreamWriter writer, MarshallingContext context)
 {
     if (type.Equals(typeof(object))) return;
     foreach (var field in mapper.GetSerializableFieldsIn(type))
     {
         field.WriteValueOn(writer, containingObject);
         context.ConvertAnother(field.GetObjectFrom(containingObject));
         writer.EndNode();
     }
     MarshalAs(containingObject, type.BaseType, writer, context);
 }
コード例 #3
0
        private void MarshalAs(object value, Type type)
        {
            if (type.Equals(typeof(object)) || value == null)
            {
                return;
            }

            FieldInfo[] fields = type.GetFields(Constants.BINDINGFlags);
            foreach (FieldInfo field in fields)
            {
                if (field.GetCustomAttributes(typeof(DontSerialiseAttribute), true).Length != 0)
                {
                    continue;
                }
                if (field.GetCustomAttributes(typeof(XmlIgnoreAttribute), true).Length != 0)
                {
                    continue;
                }
                if (typeof(MulticastDelegate).IsAssignableFrom(field.FieldType))
                {
                    continue;
                }

                string nodeName = field.Name;
                if (nodeName.StartsWith("__") || nodeName == "_id")
                {
                    // Skip internal/private autogenerated members
                    continue;
                }

                Match autoPropertyMatch = Constants.AutoPropertyNamePattern.Match(field.Name);
                Match javaPropertyMatch = Constants.JavaInternalPropertyNamePattern.Match(field.Name);
                if (autoPropertyMatch.Success)
                {
                    nodeName = autoPropertyMatch.Result("$1");
                }
                else if (javaPropertyMatch.Success)
                {
                    nodeName = javaPropertyMatch.Result("$1");
                }

                object fieldValue = field.GetValue(value);
                if (fieldValue != null)
                {
                    writer.StartNode(nodeName);
                    WriteClassNameIfNeedBe(value, field);
                    context.ConvertAnother(fieldValue);
                    writer.EndNode();
                }
            }

            PropertyInfo[] properties = type.GetProperties(Constants.BINDINGFlags);
            foreach (PropertyInfo property in properties)
            {
                // Only serialize propertied that are explicitly set
                if (property.GetCustomAttributes(typeof(SerialisedProperty), true).Length != 1)
                {
                    continue;
                }

                object fieldValue = property.GetValue(value);
                if (fieldValue != null)
                {
                    writer.StartNode(property.Name);
                    context.ConvertAnother(fieldValue);
                    writer.EndNode();
                }
            }

            MarshalAs(value, type.BaseType);
        }