Click here to Skip to main content
15,919,341 members
Home / Discussions / C#
   

C#

 
GeneralFunction Keys Pin
Riaan van der Westhuizen16-Jul-03 20:40
Riaan van der Westhuizen16-Jul-03 20:40 
GeneralRe: Function Keys Pin
fool16-Jul-03 23:55
fool16-Jul-03 23:55 
GeneralRe: Function Keys Pin
Jim Stewart17-Jul-03 5:18
Jim Stewart17-Jul-03 5:18 
QuestionVertical Text? Pin
peenu16-Jul-03 18:59
peenu16-Jul-03 18:59 
AnswerRe: Vertical Text? Pin
fool17-Jul-03 0:01
fool17-Jul-03 0:01 
GeneralCalling an objects method by an attribute Pin
Ista16-Jul-03 16:45
Ista16-Jul-03 16:45 
GeneralRe: Calling an objects method by an attribute Pin
Anonymous16-Jul-03 16:46
Anonymous16-Jul-03 16:46 
GeneralRe: Calling an objects method by an attribute Pin
Jim Stewart17-Jul-03 5:36
Jim Stewart17-Jul-03 5:36 
C#
using System;
using System.Reflection;

namespace SolidAvatar
{
	public class TestAttribute : Attribute
	{
		private string m_FieldName;
		
		public TestAttribute(string fieldName)
		{
			m_FieldName = fieldName;
		}

		public string FieldName
		{
			get
			{ return m_FieldName; }
		}

		public static string GetFieldValue(object candidate, string fieldName)
		{

			System.Type type = candidate.GetType ();
			foreach (PropertyInfo propInfo in type.GetProperties())
			{
				object[] attribs = propInfo.GetCustomAttributes (typeof (TestAttribute), true);
				if (attribs.Length > 0)
				{
					TestAttribute testAttrib = (TestAttribute)attribs[0];
					if (testAttrib.FieldName == fieldName)
					{
						return (string)propInfo.GetValue (candidate, null);
					}						
				}
			}

			// couldn't find it
			return string.Empty;
		}
	}

	class MyClass
	{
		[Test ("ID")]
		public string ID
		{
			get
			{ return string.Empty; }
			set
			{}
		}

		public static void Main()
		{
			MyClass myClass = new MyClass ();

			string idValue = TestAttribute.GetFieldValue (myClass, "ID");
		}
	}
}


α.γεεκ

Fortune passes everywhere.
Duke Leto Atreides


GeneralGDI+ performance Pin
peterchen16-Jul-03 14:28
peterchen16-Jul-03 14:28 
GeneralRe: GDI+ performance Pin
Stephane Rodriguez.17-Jul-03 2:44
Stephane Rodriguez.17-Jul-03 2:44 
GeneralRe: GDI+ performance Pin
peterchen17-Jul-03 2:58
peterchen17-Jul-03 2:58 
GeneralRe: GDI+ performance Pin
Stephane Rodriguez.17-Jul-03 3:18
Stephane Rodriguez.17-Jul-03 3:18 
GeneralRe: GDI+ performance Pin
Russell Morris17-Jul-03 7:31
Russell Morris17-Jul-03 7:31 
GeneralRe: GDI+ performance Pin
peterchen17-Jul-03 7:56
peterchen17-Jul-03 7:56 
GeneralNetwork Connect Pin
MrJJKoolJ16-Jul-03 10:54
MrJJKoolJ16-Jul-03 10:54 
GeneralRe: Network Connect Pin
RB@Emphasys17-Jul-03 3:05
RB@Emphasys17-Jul-03 3:05 
GeneralRe: Network Connect Pin
MrJJKoolJ17-Jul-03 4:40
MrJJKoolJ17-Jul-03 4:40 
QuestionHow to make an automated phone call? Pin
Alvaro Mendez16-Jul-03 9:53
Alvaro Mendez16-Jul-03 9:53 
GeneralMicrosoft Web Browser control Pin
Meysam Mahfouzi16-Jul-03 6:22
Meysam Mahfouzi16-Jul-03 6:22 
GeneralRe: Microsoft Web Browser control Pin
J. Dunlap16-Jul-03 8:25
J. Dunlap16-Jul-03 8:25 
GeneralRe: Microsoft Web Browser control Pin
Meysam Mahfouzi16-Jul-03 19:54
Meysam Mahfouzi16-Jul-03 19:54 
GeneralDetecting CD Drive and Name Pin
Meysam Mahfouzi16-Jul-03 6:08
Meysam Mahfouzi16-Jul-03 6:08 
GeneralRe: Detecting CD Drive and Name Pin
Mazdak16-Jul-03 10:21
Mazdak16-Jul-03 10:21 
GeneralSingle.Parse(string) problem... Pin
Luc Bergeron16-Jul-03 5:32
Luc Bergeron16-Jul-03 5:32 
GeneralRe: Single.Parse(string) problem... Pin
Luc Bergeron16-Jul-03 5:54
Luc Bergeron16-Jul-03 5:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.