hi there,

I'm trying to build a task that includes a [BuildElementCollection] property
that returns a null ref on first access.  ie:

[TaskName("foo")]
class Foo {
  MyCollection col = null;

  [BuildElementCollection("bits", "bit")]
  public property MyBits {
    get { return col; }
    set { col = value; }
  }
}

I think Element.cs has a bug on line 868.  It's tries to set the property
value onto the AttributeConfigurator instead of onto the element:

// if value of property is null, create new instance of collection
object collection = propertyInfo.GetValue(Element, 
  BindingFlags.Default, 
  null, 
  null, 
  CultureInfo.InvariantCulture);
if (collection == null) {
  if (!propertyInfo.CanWrite) {
    throw new BuildException(string.Format(CultureInfo.InvariantCulture, 
      "BuildElementArrayAttribute cannot be applied to read-only property
with" +
      " uninitialized collection-based value '{0}' element for <{1} ...
/>.", 
      buildElementArrayAttribute.Name, Name), 
      Location);
  }
  object instance = Activator.CreateInstance(propertyInfo.PropertyType, 
    BindingFlags.Public | BindingFlags.Instance, 
    null, 
    null, 
    CultureInfo.InvariantCulture);
  
  // borked?
  propertyInfo.SetValue(this, 
    instance, 
    BindingFlags.Default, 
    null, 
    null, 
    CultureInfo.InvariantCulture);
}

I think that last line should be:

  propertyInfo.SetValue(this.Element, 
    instance, 
    BindingFlags.Default, 
    null, 
    null, 
    CultureInfo.InvariantCulture);

Thanks,

--b
  



-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
_______________________________________________
Nant-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/nant-users

Reply via email to