Hello,
Is there any way to get the custom attributes of a specific object I am receiving in a method?
I do not want nor can to iterate over Type.GetMembers() and search for my member. I have the object, which is also a member, that has the attribute.
How do I get the attribute?
class Custom
{
[Availability]
private object MyO...
Is there any meaningful distinction between:
class A(object):
foo = 5 # some default value
vs.
class B(object):
def __init__(self, foo=5):
self.foo = foo
If you're creating a lot of instances, is there any difference in performance or space requirements for the two styles? When you read the code, do you consider t...
I have a class which is marked with a custom attribute, like this:
public class OrderLine : Entity
{
...
[Parent]
public Order Order { get; set; }
public Address ShippingAddress{ get; set; }
...
}
I want to write a generic method, where I need to get the Property on a Entity which is marked with the Parent attribu...
I have seen the following code:
[DefaultValue(100)]
[Description("Some descriptive field here")]
public int MyProperty{...}
The functionality from the above snippit seems clear enough, I have no idea as to how I can use it to do useful things. Im not even sure as to what name to give it!
Does anyone know where I can find more informa...
I'm trying to add the jVal attribute to a textbox that I created in the HTML.
<input id="subJobName" type="text" jval="{valid:function (val) { return validateSubJobName(val); }, message:'Name already exists or is longer than 14 characters.', styleType:'cover'}" />
I would let to add /set the jVal in the javascript instead.
2 reasons ...
Possible Duplicate:
Most Useful Attributes in C#
besides:
[DefaultValue(100)]
[Description("Some descriptive field here")]
public int MyProperty{get; set;}
What other C# Attributes are useful for Properties, after learning these I feel like I'm Missing out.
Related Questions
Most Useful Attributes in C#
...
I want to make a generic class that accepts only serializable classes, can it be done with the where constraint?
The concept I'm looking for is this:
public class MyClass<T> where T : //[is serializable/has the serializable attribute]
...
Is there a way in C# or .NET in general to create an attribute on a method which triggers an event when a method is invoked? Ideally, I would be able to run custom actions before and after the invocation of the method.
I mean something like this:
[TriggersMyCustomAction()]
public void DoSomeStuff()
{
}
I am totally clueless how to do...
I'd like to make anchors to every post in my asp.net forum. Every forum's post is rendered using repeater control. How can I render <a name="anchor_name"></a> in asp.net?
...
I am attempting to allow my web designers to use the metadata we have about database fields in the asp.net pages they are creating. The most obvious one is as follows:
<asp:TextBox runat="server" id="txTextBox" MaxLength="<Value From Metadata here>" ... />
All the required metadata is stored in our class objects and is accessible due ...
I have a interface that defines some methods with attributes. These attributes need to be accessed from the calling method, but the method I have does not pull the attributes from the interface. What am I missing?
public class SomeClass: ISomeInterface
{
MyAttribute GetAttribute()
{
StackTrace stackTrace = new StackTra...
Is there a way in C# to:
Get all the properties of a class that have attributes on them (versus having to loop through all properties and then check if attribute exists.
If i want all Public, Internal, and Protected properties but NOT private properties, i can't find a way of doing that. I can only do this:
PropertyInfo[] props = ty...
I am using XmlSerializer to write and read an object to xml in C#. I currently use the attributes XmlElement and XmlIgnore to manipulate the serialization of the object.
If my xml file is missing an xml element that I require, my object still deserializes (xml -> object) just fine. How do I indicate (preferably via Attributes) that a...
We're using Microsoft.Practices.CompositeUI.EventBroker to handle event subscription and publication in our application. The way that works is that you add an attribute to your event, specifying a topic name, like this:
[EventPublication("example", PublicationScope.Global)]
public event EventHandler Example;
then you add another attr...
Is it possible to create an attribute that can be initialized with a variable number of arguments?
For example:
[MyCustomAttribute(new int[3,4,5])] // this doesn't work
public MyClass ...
...
So, if i have:
public class Sedan : Car
{
/// ...
}
public class Car : Vehicle, ITurn
{
[MyCustomAttribute(1)]
public int TurningRadius { get; set; }
}
public abstract class Vehicle : ITurn
{
[MyCustomAttribute(2)]
public int TurningRadius { get; set; }
}
public interface ITurn
{
[MyCustomAttribute(3)]
in...
For some reason I'm not getting this. (Example model below) If I write:
var property = typeof(sedan).GetProperty("TurningRadius");
Attribute.GetCustomAttributes(property,typeof(MyAttribute), false)
the call will return MyAttribute(2) despite indicating I don't want to search the inheritance chain. Does anyone know what code I can wri...
So I've got a case where I'd like to be able to apply attributes to a (virtual) method in a derived class, but I'd like to be able to give a default implementation that uses those attributes in my base class.
My original plan for doing this was to override the method in the derived class and just call the base implementation, applying t...
I realize you can't get the target entity in the Attribute itself, but what about in an associated Permission object when using a CodeAccessSecurityAttribute? The Permission object gets called at runtime so it seems there should be a way but I'm at a loss.
public sealed class MySecurityAttribute : CodeAccessSecurityAttribute
{
public ...
Suppose I have a python object x and a string s, how do I set the attribute s on x? So:
>>> x = SomeObject()
>>> attr = 'myAttr'
>>> # magic goes here
>>> x.myAttr
'magic'
What's the magic? The goal of this, incidentally, is to cache calls to x.__getattr__().
...