History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: COR-1925
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Adriano Verona
Reporter: Roman Stoffel
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
db4o Core

The Db4oTool '-collection' enhancement stops with an error when casting and passing delegate to a method.

Created: 30/Apr/10 02:16 PM   Updated: 14/Sep/10 07:17 PM
Component/s: .NET ByteCode Engineering
Affects Version/s: None
Fix Version/s: None

Time Tracking:
Not Specified

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


 Description  « Hide
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);
        }
    }



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Adriano Verona - 04/May/10 03:03 PM
8.0.145