
|
If you were logged in you would be able to see more operations.
|
|
|
| Peers: |
Carl Rosenberger
|
| Order: |
7
|
| Iteration: |
145
|
| Resolution Date: |
04/May/10 03:03 PM
|
| First Response Date: |
04/May/10 03:03 PM
|
| Labels: |
|
| Participants: |
Adriano Verona and Roman Stoffel
|
| Number of Attachments: |
0
|
| Number of Comments: |
1
|
|
The Db4oTool '-collection' enhancement stops with an error when casting and passing delegate to a method.
Normally (stupid) cast is actually correctly enhanched. For example:
public void SortList()
{
((List<string>)_list).Sort((x,y)=>x.CompareTo(y));
}
is turned into:
public void SortList()
{
((ActivatableList<string>) this._list)..Sort((x,y)=>x.CompareTo(y));
}
However when you just pass a 'method-delegate' (and not a lambda/closure or regular) argument, and then the Db4oTool on it, an error occurs. For example:
public void SortList()
{
((List<string>)_list).Sort(Compare);
}
Causes Error:
Error: [System.Void TestMe.Db4oToolAndCollections::SortList()] Invalid use of cast result: 'newobj System.Void System.Co
mparison`1<System.String>::.ctor(System.Object,System.IntPtr)'. Cast to List<T> are allowed only for property access or
method call.
Example-Class:
class Db4oToolAndCollections
{
private IList<string> _list = new List<string>();
/// <summary>
/// Works with class instance
/// </summary>
public void SortList1()
{
((List<string>)_list).Sort(StringComparer.OrdinalIgnoreCase);
}
/// <summary>
/// Works with closure
/// </summary>
public void SortList2()
{
((List<string>)_list).Sort((x,y)=>x.CompareTo(y));
}
/// <summary>
/// But doesn't work when passing a delegate to a method?
/// </summary>
public void SortList3()
{
((List<string>)_list).Sort(Compare);
}
private int Compare(string a,string b)
{
return a.CompareTo(b);
}
private bool IsTrue(string x)
{
return "true".Equals(x);
}
}
|
|
Description
|
The Db4oTool '-collection' enhancement stops with an error when casting and passing delegate to a method.
Normally (stupid) cast is actually correctly enhanched. For example:
public void SortList()
{
((List<string>)_list).Sort((x,y)=>x.CompareTo(y));
}
is turned into:
public void SortList()
{
((ActivatableList<string>) this._list)..Sort((x,y)=>x.CompareTo(y));
}
However when you just pass a 'method-delegate' (and not a lambda/closure or regular) argument, and then the Db4oTool on it, an error occurs. For example:
public void SortList()
{
((List<string>)_list).Sort(Compare);
}
Causes Error:
Error: [System.Void TestMe.Db4oToolAndCollections::SortList()] Invalid use of cast result: 'newobj System.Void System.Co
mparison`1<System.String>::.ctor(System.Object,System.IntPtr)'. Cast to List<T> are allowed only for property access or
method call.
Example-Class:
class Db4oToolAndCollections
{
private IList<string> _list = new List<string>();
/// <summary>
/// Works with class instance
/// </summary>
public void SortList1()
{
((List<string>)_list).Sort(StringComparer.OrdinalIgnoreCase);
}
/// <summary>
/// Works with closure
/// </summary>
public void SortList2()
{
((List<string>)_list).Sort((x,y)=>x.CompareTo(y));
}
/// <summary>
/// But doesn't work when passing a delegate to a method?
/// </summary>
public void SortList3()
{
((List<string>)_list).Sort(Compare);
}
private int Compare(string a,string b)
{
return a.CompareTo(b);
}
private bool IsTrue(string x)
{
return "true".Equals(x);
}
}
|
Show » |
|