Inheritance: System.Attribute
Beispiel #1
0
 private void WriteContents(string name, object next_obj, XmlItemDescription xid)
 {
     m_writer.WriteStartElement(name);
     if (xid != null)
     {
         m_writer.WriteAttributeString(xid.AttributeName, xid.Value);
     }
     PrintItemRecurse(next_obj);
     m_writer.WriteEndElement();
 }
Beispiel #2
0
        private void PrintItemRecurse(object obj)
        {
            Type t = obj.GetType();

            if (!TryWriteValueType(obj))
            {
                if (t.IsGenericType)
                {
                    List <int> f         = new List <int>();
                    Type       list_type = f.GetType().GetGenericTypeDefinition();
                    if (t.GetGenericTypeDefinition().Equals(list_type))
                    {
                        Type[] gen = t.GetGenericArguments();
                        if (gen.Length == 1)
                        {
                            PropertyInfo count_property = t.GetProperty("Count", typeof(int));
                            int          count          = (int)count_property.GetValue(obj, new object[] { });
                            Type         returntype     = gen[0];
                            MethodInfo   indexer        = t.GetMethod("get_Item", new Type[] { typeof(int) });
                            string       name           = "";
                            if (returntype.Equals(typeof(Boolean)))
                            {
                                name = "boolean";
                            }
                            else if (returntype.Equals(typeof(DateTime)))
                            {
                                name = "dateTime";
                            }
                            else if (returntype.Equals(typeof(Decimal)))
                            {
                                name = "decimal";
                            }
                            else if (returntype.Equals(typeof(Double)))
                            {
                                name = "double";
                            }
                            else if (returntype.Equals(typeof(Int32)))
                            {
                                name = "int";
                            }
                            else if (returntype.Equals(typeof(Int64)))
                            {
                                name = "long";
                            }
                            else if (returntype.Equals(typeof(Single)))
                            {
                                name = "float";
                            }
                            else if (returntype.Equals(typeof(string)))
                            {
                                name = "string";
                            }
                            else if (returntype.IsEnum)
                            {
                                name = returntype.Name;
                            }
                            if (indexer != null && name != "")
                            {
                                for (int i = 0; i < count; i++)
                                {
                                    object value = indexer.Invoke(obj, new object[] { i });
                                    m_writer.WriteStartElement(name);
                                    TryWriteValueType(value);
                                    m_writer.WriteEndElement();
                                }
                            }
                        }
                    }
                }
                else
                {
                    foreach (FieldInfo fi in t.GetFields())
                    {
                        if (fi.IsPrivate || fi.IsStatic)
                        {
                            continue;
                        }
                        object[]           attr = fi.GetCustomAttributes(typeof(XmlItemDescription), false);
                        XmlItemDescription xid  = null;
                        if (attr.Length > 0)
                        {
                            xid = (XmlItemDescription)attr[0];
                        }
                        WriteContents(fi.Name, fi.GetValue(obj), xid);
                    }
                    foreach (PropertyInfo pi in t.GetProperties())
                    {
                        if (!pi.CanRead | !pi.CanWrite)
                        {
                            continue;
                        }
                        if (!pi.GetSetMethod().IsPublic | !pi.GetGetMethod().IsPublic)
                        {
                            continue;
                        }
                        if (pi.GetSetMethod().IsStatic | pi.GetGetMethod().IsStatic)
                        {
                            continue;
                        }
                        object[]           attr = pi.GetCustomAttributes(typeof(XmlItemDescription), false);
                        XmlItemDescription xid  = null;
                        if (attr.Length > 0)
                        {
                            xid = (XmlItemDescription)attr[0];
                        }
                        WriteContents(pi.Name, pi.GetValue(obj, new object[] { }), xid);
                    }
                }
            }
        }
 private void WriteContents( string name, object next_obj, XmlItemDescription xid ) {
     m_writer.WriteStartElement( name );
     if ( xid != null ) {
         m_writer.WriteAttributeString( xid.AttributeName, xid.Value );
     }
     PrintItemRecurse( next_obj );
     m_writer.WriteEndElement();
 }