Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

UI Object Connector Implementation of Mediator Pattern

, 7 Mar 2014
UI Object Connector Implementation of Mediator Pattern
UIObjectConnector.zip
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

Shivprasad koirala
Architect http://www.questpond.com
India India

I am a Microsoft MVP for ASP/ASP.NET and currently a CEO of a small
E-learning company in India. We are very much active in making training videos ,
writing books and corporate trainings. Do visit my site for 
.NET, C# , design pattern , WCF , Silverlight
, LINQ , ASP.NET , ADO.NET , Sharepoint , UML , SQL Server  training 
and Interview questions and answers


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