using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace JoeySearchObject { publicpartialclass Form1 : Form { public Form1() { InitializeComponent(); } privatevoid Form1_Load(object sender, EventArgs e) { //UniversalSearchObject uso = UniversalSearchObject.Create(UniversalSearchAttribute.ChildClassEnum.UserIDSearchObject); UniversalSearchObject uso = UniversalSearchObject.Create("UserIDSearchObject"); uso.SetSearchParameter("UserID", 1); this.label1.Text += uso.Search()[0].ToString()+""; //uso = UniversalSearchObject.Create(UniversalSearchAttribute.ChildClassEnum.UserNameSearchObject); uso = UniversalSearchObject.Create("UserNameSearchObject"); uso.SetSearchParameter("UserName", "Joey"); this.label1.Text += uso.Search()[0].ToString(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace JoeySearchObject { [AttributeUsage(AttributeTargets.Class)] publicclass UniversalSearchAttribute : Attribute { publicenum ChildClassEnum { UserIDSearchObject, UserNameSearchObject } public ChildClassEnum[] Children { get; set; } public UniversalSearchAttribute() { this.Children =null; } public UniversalSearchAttribute(ChildClassEnum[] Children) { this.Children = Children; } } }
using System; using System.Collections.Generic; using System.Text; using System.Collections; using System.Reflection; namespace Entities { publicabstractclass UniversalSearchObject { "instance method"#region "instance method" publicabstract ArrayList Search(); #endregion "static methods"#region "static methods" "Create"#region "Create" publicstatic UniversalSearchObject Create(String childClass) { UniversalSearchObject uso =null; String Namespace =typeof(UniversalSearchObject).Namespace; Module module =typeof(UniversalSearchObject).Module; uso = (UniversalSearchObject)Activator.CreateInstance(module.GetType(Namespace +"."+ childClass)); return uso; } #endregion "SetSearchParameter"#region "SetSearchParameter" publicvoid SetSearchParameter(string parameterName, object parameterValue) { Type type =this.GetType(); type.GetProperty(parameterName).SetValue(this, parameterValue, null); } #endregion "GetResultParameter"#region "GetResultParameter" publicobject GetResultParameter(string parameterName) { Type type =this.GetType(); return type.GetProperty(parameterName).GetValue(this, null); } #endregion #endregion } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace JoeySearchObject { publicclass UserIDSearchObject : UniversalSearchObject { publicint UserID { set; get; } publicoverride ArrayList Search() { ArrayList al =new ArrayList(); al.Add(this.UserID); return al; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace JoeySearchObject { publicclass UserNameSearchObject : UniversalSearchObject { publicstring UserName { set; get; } publicoverride ArrayList Search() { ArrayList al =new ArrayList(); al.Add(this.UserName); return al; } } }