none
Except Extension - Translate to VB.NET RRS feed

  • Question

  •    

    Hi.

    Someone can help me to convert this extension for the except method to VB.NET. I've tried several online translators but all conversion are wrong.

       public static IEnumerable<T> Except<T, TKey>(this IEnumerable<T> items, IEnumerable<T> other, Func<T, TKey> getKey)
            {
    
                return from item in items
                       join otherItem in other on getKey(item)
                       equals getKey(otherItem) into tempItems
                       from temp in tempItems.DefaultIfEmpty()
                       where ReferenceEquals(null, temp) || temp.Equals(default(T))
                       select item;
            
            }

    Thanks in advance

    Antonio


    Wednesday, May 22, 2013 1:51 AM

All replies

  • Did you try this?

    http://www.developerfusion.com/tools/convert/csharp-to-vb/


    Please Mark as Answer and Vote as Helpful if I helped.

    Also please visit my blog http://msguy.me/


    Wednesday, May 22, 2013 11:51 AM
  • Yes, of course but the conversion is not correct.
    Wednesday, May 22, 2013 12:20 PM
  •     {
            private static readonly int[] Values = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
            
            
            static void Main(string[] args)
            {
                var query = Values.AsQueryable();

                var except = query.Except(query.Where(x => x % 2 == 0));

                foreach (var value in except)
                {
                    Console.WriteLine(value);
                }
                Console.ReadLine();
            }
        }

        public static class Extension
        {
            public static IEnumerable<T> Except<T>(IQueryable<T> root, IQueryable<T> exclude)
            {
                var rootParam = Expression.Parameter(typeof(T));
                var excludedItem = exclude.Expression;
                var not = Expression.Not(excludedItem);
                var lambda = (Expression<Func<T, bool>>)Expression.Lambda(not, rootParam);
                return root.Where(lambda);
            }
        }
    • Proposed as answer by Brian Bu Monday, October 20, 2014 11:13 PM
    Thursday, December 19, 2013 3:36 PM