What are the purposes of using attributes?

I know that Attributes are usefull in reflecting, is there any usecase else?

with thanks

[101 byte] By [mohammadMirmostafa] at [2007-12-24]
# 1

Any time you want to attach extra information to an assembly, type or type member. Reflection is just the way to read those attributes at runtime. The actual uses are many. Just look at how the framework are using them for serialization, security, designer support etc.

MattiasSj?gren at 2007-10-8 > top of Msdn Tech,Visual C#,Visual C# Language...
# 2
Look at Brendan's post (the second one, not the question)...he describes a unique way to use attributes on enums to help with error messages.
OmegaMan at 2007-10-8 > top of Msdn Tech,Visual C#,Visual C# Language...
# 3

Thanks dear.

Look at hear:

using System;

using System.Collections.Generic;

using System.Text;

using Atinegar.Library.ObjectModel;

namespace Atinegar.Library.ObjectModel

{

[Creator("Mohammad"), Construct(ConstructProgressive.UnderTesting)]

publicstaticclassAttributeHelper

{

publicstaticAttribute GetAttribute(Type attributeType, Type objectType)

{

object[] attributes = objectType.GetCustomAttributes(attributeType, false);

if (attributes == null || attributes.Length == 0) returnnull;

foreach (Attribute attribute in attributes) if (attribute.GetType() == attributeType) return attribute;

returnnull;

}

}

publicenumConstructProgressive

{

None,

ForTest,

Obsoleted,

NotStarted,

InProgress,

ErrorOccured,

Completed,

UnderTesting

}

[Creator("Mohammad"), Construct(ConstructProgressive.InProgress), AttributeUsage(AttributeTargets.All)]

publicclassConstructAttribute : System.Attribute

{

#region ctors

public ConstructAttribute(ConstructProgressive progressive)

{

this.Progressive = progressive;

}

public ConstructAttribute()

{

this.Progressive = ConstructProgressive.None;

}

#endregion

#region Progressive

privateConstructProgressive progressive;

publicConstructProgressive Progressive

{

get { return progressive; }

privateset { progressive = value; }

}

#endregion

#region GetAttribute

publicstaticConstructAttribute GetAttribute(Type type)

{

ConstructAttribute result = (ConstructAttribute)AttributeHelper.GetAttribute(typeof(ConstructAttribute), type);

if (result == null) result = newConstructAttribute();

return result;

}

#endregion

}

[Creator("Mohammad"), Construct(ConstructProgressive.Completed)]

[AttributeUsage(AttributeTargets.All)]

publicclassCreatorAttribute : System.Attribute

{

privatestring name;

publicvirtualstring Name

{

get { return name; }

privateset { this.name = value; }

}

public CreatorAttribute(string name)

{

this.name = name;

}

private CreatorAttribute()

{

this.Name = "Unknown";

}

#region GetAttribute

publicstaticCreatorAttribute GetAttribute(Type type)

{

CreatorAttribute result = (CreatorAttribute)AttributeHelper.GetAttribute(typeof(CreatorAttribute), type);

if (result == null) result = newCreatorAttribute();

return result;

}

#endregion

}

}

mohammadMirmostafa at 2007-10-8 > top of Msdn Tech,Visual C#,Visual C# Language...
# 4
If you feel the issue is resolved to your liking...mark the post(s) that helped you as the answer(s), so when others search the forums, they might be more inclined to look at a successful post than a non successful one...in the search results the Answered posts are bubbled to the top before the unanswered.

Or post if you need more help! Thanks

OmegaMan at 2007-10-8 > top of Msdn Tech,Visual C#,Visual C# Language...