Does you has generic operator plan support?

Apr 6, 2012 at 8:12 AM

just like :

var q = new System::Collections::Generic::List<string>();

q.Add("223");

println(q[1]);

only can invoke .net method, not implelementation in your class.

I  needed it .  thanks.

Coordinator
Apr 9, 2012 at 1:21 PM
Edited Apr 9, 2012 at 1:27 PM

At this time, i'm still trying to add generic types (and generic operations) support to AddyScript.

This requires defining a suitable syntax and an efficient handling mechanism for it at runtime.

As soon as those two prerequisites will be statisfied, it will become possible to use .Net generic types from AddyScript.

While waiting, please be patient.

Apr 10, 2012 at 6:00 AM
Edited Apr 11, 2012 at 2:10 AM

Very thank's.  I can write other code instead. 

another question is :

If a .net class implements not standard or partial IConvertable ( I used a nosql daatbase driver  class: MongoDB.Bson.BsonElement or MongoDB.Bson.BsonValue ).

When i create a BsonElement use BsonValue as param, it will report Convert Error  .

in Runtime\Dynamics\Resource.cs :

 public override object ConvertTo(Type targetType)
        {            return handle is IConvertible
                ? ((IConvertible)handle).ToType(targetType, CultureInfo.InvariantCulture)
                : base.ConvertTo(targetType);
            
        }

 Need check a NativeObject.classType eq targetType , or NativeObject class is targetType class  children.

this is i changed code for reference(this code not check interface ,just class  ):

           Type myType = handle.GetType();
            if (myType.IsClass && targetType.IsClass && this.NativeType.IsClass && ((myType == targetType) || myType.IsSubclassOf(targetType)))
            {
                return handle;
            }
            else
            {
            return handle is IConvertible
                ? ((IConvertible)handle).ToType(targetType, CultureInfo.InvariantCulture)
                : base.ConvertTo(targetType);
            }

Apr 10, 2012 at 6:08 AM
Edited Apr 10, 2012 at 6:31 AM

attach:

this is class define:

public abstract class BsonValue : IComparable<BsonValue>,
IConvertible, IEquatable<BsonValue>

public class BsonElement : IComparable<BsonElement>,
IEquatable<BsonElement>

this is sample code:

var docs = new MongoDB::Bson::BsonDocument();  
  var value =  MongoDB::Bson::BsonValue::Create("aaa");
  var elem = MongoDB::Bson::BsonElement::Create("Name", value);   // this line report error : can't convert System::String to  MongoDB::Bson::BsonValue
  docs.Add(elem);

Coordinator
Apr 11, 2012 at 3:58 PM

Thanks for your suggestion on Resource.ConvertTo. Checking that the target type is the same than the original type is absolutely necessary and avoids useless conversion.

Now, for the error message, it's simply that AddyScript cannot convert a string to an instance of BsonValue. I don't know the proptotype of MongoDB.Bson.BsonElement.Create but it seems that at least one argument is not of the right type.

Apr 17, 2012 at 2:14 AM

thanks.

    MongoDB.Bson.BsonElement.Create is  a static create factory, in this line, it's return  a BsonElement,   BsonDocument managered a BsonElement array.

BsonValue::Create("aaa") real return a BsonString , is a BsonValue Child.

   BsonDOcument:

        List<BsonElement> Elements;

  BsonElement :

        string Name;

        BsonValue Value;

BsonValue  like  a  ValueType object ,can store some baseType , it children impl it's action. BsonString store string, BsonBool store bool, BsonDateTime store datetime.

very thank you.