Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom attribute internal properties null c#
    primarykey
    data
    text
    <p>I have a problem with a custom property. This is the property in question:</p> <pre><code>[AttributeUsage(AttributeTargets.Property, Inherited = true, AllowMultiple = false)] public class UIProperty : Attribute { public UIProperty(string property, Type target) { Property = property; TargetType = target; } private string property; public string Property { get{return property;} set{property = value;} } private PropertyInfo targetProperty; public PropertyInfo TargetProperty { get { return targetProperty; } protected set { targetProperty = value; } } private Type targetType; public Type TargetType { get{ return targetType; } set{ targetType = value; } } private object target; public object Target { get{return target; } set{ target = value;} } public void SetTargetProperty(PropertyInfo targetPropertyInfo, object target) { targetProperty = targetPropertyInfo; this.target = target; } public object TargetValue { get { return targetProperty.GetValue(target, null); } set { if (!value.Equals(TargetValue)) targetProperty.SetValue(target, value, null); } } } </code></pre> <p>So, if I set the custom attribute with SetTargetProperty after taking out in this way:</p> <pre><code>UIProperty uip = this.GetType (). GetProperty ("name"). GetCustomAttributes (typeof (UIProperty), true) [0] as UIProperty; uip.SetTargetProperty (...); </code></pre> <p>My attribute has correctly set its target and its properties. Nothing is null or not set. But when I go to pick up that property elsewhere in the code everything is back to null as if I had never set ...</p> <p>The classes Attribute are instantiated when i get from a PropertyInfo dynamically or they have a physical instance set to the property?</p> <p>What is wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload