Click here to Skip to main content
12,890,954 members (58,642 online)
Click here to Skip to main content

Stats

82.7K views
33 bookmarked
Posted 30 Oct 2008

UI Object Connector Implementation of Mediator Pattern

, 7 Mar 2014 CPOL
UI Object Connector Implementation of Mediator Pattern
UIObjectConnector
Bin
SampleClass.dll
SampleClass.pdb
UIObjectConnector.dll
UIObjectConnector.pdb
SampleClass
bin
Debug
SampleClass.dll
Properties
UIObjectConnector
bin
Debug
SampleClass.dll
UIObjectConnector.dll
Properties
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Web.UI.WebControls;
using SampleClass;
using System.Reflection;
namespace UIObjectConnector
{
    public class clsMediator
    {
        
        private ArrayList objtextboxes = new ArrayList();
        private ArrayList objPropertyInfo = new ArrayList();

        public void Add(TextBox objtextBox, string strPropertyName)
        {
            objtextboxes.Add(objtextBox);
            objPropertyInfo.Add(strPropertyName);
        }
        
        public void setValuesToObject(clsSampleClass objSample)
        {
        // get the object type
        Type objType = objSample.GetType();
        // browse through all the UI object and set the object 
        // from the UI to the corresponding property
        for(int i=0;i<objtextboxes.Count;i++)
        {
            // get the UI object
            PropertyInfo objProperty = objType.GetProperty(objPropertyInfo[i].ToString());
            // set the object property from the UI object
            objProperty.SetValue(objSample,((TextBox)objtextboxes[i]).Text,null);
        }

        }
        public void setValuesToUI(clsSampleClass objSample)
        {
           
            Type objType =  objSample.GetType();
            for (int i = 0; i < objtextboxes.Count; i++)
            {
                PropertyInfo objProperty = objType.GetProperty(objPropertyInfo[i].ToString());
                ((TextBox)objtextboxes[i]).Text= objProperty.GetValue(objSample, null).ToString();
            }

        }
        public void ClearTextBox()
        {
            Type objType = Type.GetType("clsSampleClass");
            for (int i = 0; i < objtextboxes.Count; i++)
            {
                ((TextBox)objtextboxes[i]).Text = "";
            }

        }
    }
    
    
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author


You may also be interested in...

Pro
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170424.1 | Last Updated 7 Mar 2014
Article Copyright 2008 by Shivprasad koirala
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid