title: Custom attribute internal properties null c#
body: <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>