Lecture – XML-Reflection-Inheritance

 XML – Inheritance – Reflection

Prerequisites

Part of Topic – Creating a Single Table Database Object Storage

Topic – Getting Started with Web Form Applications

next video: Lecture – XML-Reflection-Inheritance Part 2

Summary

Topics Covered in this Video;

-XML
-Reflection
-Handling Dangerous Request Forms
-ValidateRequest
-SamplePropertiesInherited
-tbResults
-\n
-asXML

Video 

Reference Materials

Class Code for SampleProperties

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Reflection;
namespace DatabaseSample1.App_Code
{
    public class SampleProperties
    {
        private string myName;
        public string Name
        {
            get { return myName; }
            set { myName = value; }
        }
        private string myDescription;
        public string Description
        {
            get { return myDescription; }
            set { myDescription = value; }
        }
        public string asXML()
        {
            string s = String.Empty;
            string fc = this.GetType().ToString();
            while (fc.Contains("."))
            {
                fc = fc.Substring(fc.IndexOf(".")+1);
            }
            s += "<" + fc + ">\n"; 
            foreach(var property in this.GetType().GetProperties())
            {
                s += " <" + property.Name + ">";
                s += property.GetValue(this);
                s += "</" + property.Name + ">";
                s += "\n";
            }
            s += "</" + fc + ">"; 
            return s;
        }
    }
    public class SamplePropertiesInherited : SampleProperties
    {
        private string myContent;
        public string Content
        {
            get { return myContent; }
            set { myContent = value; }
        }
    }
} 

Code for Form Creation

Name: <asp:TextBox ID="tbName" runat="server"></asp:TextBox><br />
    Description: <asp:TextBox ID="tbDescription" runat="server"></asp:TextBox><br />
    <asp:Button ID="btnGo" runat="server" Text="Go" OnClick="btnGo_Click" /><br />
    Content: <asp:TextBox ID="tbContent" runat="server"></asp:TextBox><br />
    <asp:Button ID="btnGo2" runat="server" Text="Go" OnClick="btnGo2_Click" /><br />
    <asp:TextBox ID="tbResults" runat="server" TextMode="MultiLine" Height="200" Width="400"></asp:TextBox> 

Code for Buttons

protected void btnGo_Click(object sender, EventArgs e)
        {
            SampleProperties s = new SampleProperties
            {
                Name = tbName.Text,
                Description = tbDescription.Text
            };
            tbResults.Text = s.asXML();
        }
        protected void btnGo2_Click(object sender, EventArgs e)
        {
            SamplePropertiesInherited s = new SamplePropertiesInherited
            {
                Name = tbName.Text,
                Description = tbDescription.Text,
                Content = tbContent.Text
            };
            tbResults.Text = s.asXML();
        } 

Additional Information

COP 4834 Lectures Page