Esempio n. 1
0
 private void Form3_Load(object sender, EventArgs e)
 {
     XmlTextReader reader = new XmlTextReader(flrt.DName);
     reader.ReadToFollowing("Name");
     textBox4.Text = (string)reader.ReadElementContentAs(typeof(string), null);
     reader.ReadToNextSibling("Mask");
     textBox4.Text += (string)reader.ReadElementContentAs(typeof(string), null);
     textBox2.Text = Func.FName;
     Funcs.ReadXml(flrt.DName);
     dataGridView1.DataSource = Funcs;
     dataGridView1.DataMember = "function";
 }
Esempio n. 2
0
        public override void Deserialize(Node node, string data)
        {
            TextReader tr = new StringReader(data);
            Dictionary<string, object> properties = new Dictionary<string, object>();

            using(XmlReader xmlReader = new XmlTextReader(tr))
            {
                xmlReader.ReadStartElement("root");
                do {
                    if (xmlReader.NodeType == XmlNodeType.Element) {
                        string name = xmlReader.Name;
                        if (xmlReader.Read()) {
                            switch (xmlReader.NodeType) {
                            case XmlNodeType.Text:
                                properties.Add(name, xmlReader.ReadContentAs(xmlReader.ValueType, null));
                                break;
                            case XmlNodeType.Element:
                                List<object> objs = new List<object>();
                                while(xmlReader.Read() && xmlReader.NodeType != XmlNodeType.EndElement) {
                                    if (xmlReader.Name == "item")
                                        objs.Add(xmlReader.ReadElementContentAs(xmlReader.ValueType, null));
                                }
                                properties.Add(name, objs.ToArray());
                                break;
                            }

                        }

                    }
                } while(xmlReader.Read());
            }

            UpdateNode (node, properties);
        }
Esempio n. 3
0
		public void ReadElementContentAs ()
		{
			// as System.Object

			XmlTextReader r = new XmlTextReader (
				"<root/>", XmlNodeType.Document, null);
			r.Read ();
			Assert.AreEqual (String.Empty, r.ReadElementContentAs (typeof (object), null), "#1");
			Assert.AreEqual (XmlNodeType.None, r.NodeType, "#2");

			// regardless of its value, the return value is string.
			r = new XmlTextReader ("<root>1</root>", XmlNodeType.Document, null);
			r.Read ();
			Assert.AreEqual ("1", r.ReadElementContentAs (typeof (object), null), "#3");
			Assert.AreEqual (XmlNodeType.None, r.NodeType, "#4");
		}
Esempio n. 4
0
 public static Index LoadIndexXml(string name, Type type)
 {
     TextReader m = File.OpenText (name);
     XmlReader R = new XmlTextReader (m);
     // Type type = obj.GetType ();
     Index obj = (Index)Activator.CreateInstance (type);
     R.ReadStartElement ();
     while (!R.EOF) {
         R.Read ();
         if (R.NodeType != XmlNodeType.Element) {
             continue;
         }
         var pname = R.Name;
         // Console.WriteLine (pname);
         object v = null;
         var prop = type.GetProperty (pname);
         var field = type.GetField (pname);
         if (prop != null) {
             // v = R.ReadContentAs (prop.PropertyType, null);
             // v = R.ReadElementContentAsString ();
             v = R.ReadElementContentAs (prop.PropertyType, null);
             prop.SetValue (obj, v, null);
             //Console.WriteLine ("PROPERTY*** pname: {0}, {1}, val: {2}", pname, prop.ReflectedType, v);
         } else if (field != null) {
             // Console.WriteLine ("FIELD****** pname: {0}, field-reflector: {1}, field-type: {2}", pname, field.ReflectedType, field.FieldType);
             v = R.ReadElementContentAs (field.FieldType, null);
             field.SetValue (obj, v);
         } else {
             throw new ArgumentException (String.Format ("Property or field {0} was not found for type", pname));
         }
     }
     // Console.WriteLine (obj.GetType().Name);
     m.Close ();
     return obj;
 }
Esempio n. 5
0
 float GetFloat(XmlTextReader textReader)
 {
     return (float) textReader.ReadElementContentAs(typeof(float), null);
 }
        public static ExpandoObject FromXml( string xml , string root )
        {
            var bag = new ExpandoObject();

            if ( string.IsNullOrEmpty( xml ) )
            {
                return bag;
            }

            using ( var reader = new XmlTextReader( xml , XmlNodeType.Document , null ) )
            {
                // ルート要素を探す
                while ( reader.Read() )
                {
                    if ( (reader.NodeType == XmlNodeType.Element) && (reader.Name == root) )
                    {
                        // 見つけた
                        break;
                    }
                }
                if ( reader.EOF )
                {
                    // 見つからなかった
                    return bag;
                }

                // 項目読み込み
                var thisdic = bag as IDictionary<string , object>;
                while ( reader.Read() )
                {
                    // 項目エレメントに移動
                    if ( reader.NodeType != XmlNodeType.Element )
                    {
                        continue;
                    }
                    string name = reader.Name;

                    // アトリビュートを取得、こいつには戻す型が書いてあるはず
                    // アトリビュートには「type」しかないことに決め打っている
                    string xmlType = null;
                    if ( reader.MoveToNextAttribute() )
                    {
                        xmlType = reader.Value;
                    }

                    // 具に移動
                    reader.MoveToContent();

                    object value;
                    if ( xmlType == "nil" )
                    {
                        // nullは特別なことをしていたのだった
                        value = default( object );
                    }
                    else if ( string.IsNullOrEmpty( xmlType ) )
                    {
                        // アトリビュートが無いのはstringとしていたのさ
                        value = reader.ReadString();
                    }
                    else
                    {
                        var type = GetTypeFromName( xmlType );
                        if ( type == null )
                        {
                            // アプリ内にその型情報は無い
                            continue;
                        }
                        else if ( type.GetInterface( "System.IConvertible" ) != null )
                        {
                            // 単純変換できるのものは変換読み込み
                            value = reader.ReadElementContentAs( type , null );
                        }
                        else
                        {
                            // 複雑な型はデシリアライザに丸投げするので
                            // まずデシリアライズするエレメントまで移動
                            while ( reader.Read() && reader.NodeType != XmlNodeType.Element )
                            { }

                            // デシリアライズ
                            XmlSerializer ser = new XmlSerializer( type );
                            value = ser.Deserialize( reader );
                        }
                    }

                    // 項目追加
                    thisdic.Add( name , value );
                }
            }

            return bag;
        }