Home All Groups Group Topic Archive Search About

Duplicate property information

Author
5 Jan 2007 3:04 PM
Kevin Burton
I am trying to reflect on a class that has two indexed accessors. One taking
an integer argument and one taking a string. If I reflect on the type and
execute GetProperties I get an array of PropertyInfo objects. The problem is
that the indexed accessor properties appear twice. I can't see any difference
in the two sets of properties. This is being called from C# if that makes a
difference. Any ideas on why the idexed accessor properties appear twice?

Thank you.

Kevin Burton

Author
5 Jan 2007 3:34 PM
Joanna Carter [TeamB]
"Kevin Burton" <KevinBur***@discussions.microsoft.com> a écrit dans le
message de news: 35617DB2-09E6-4C95-8A0E-3A5992ABC***@microsoft.com...

|I am trying to reflect on a class that has two indexed accessors. One
taking
| an integer argument and one taking a string. If I reflect on the type and
| execute GetProperties I get an array of PropertyInfo objects. The problem
is
| that the indexed accessor properties appear twice. I can't see any
difference
| in the two sets of properties. This is being called from C# if that makes
a
| difference. Any ideas on why the idexed accessor properties appear twice?

Well, I just tried this :

  public class Test
  {
    public string this[int index]
    {
      get { return null; }
    }

    public string this[string index]
    {
      get { return null; }
    }
  }

  class Program
  {
    [STAThread]
    static void Main(string[] args)
    {
      PropertyInfo[] infos = typeof(Test).GetProperties();

      foreach (PropertyInfo info in infos)
      {
        Console.WriteLine(info.Name);

        ParameterInfo[] ps = info.GetIndexParameters();

        if (ps.GetLength(0) > 0)
          Console.WriteLine(ps[0].ParameterType);
      }
    }
  }

.... and only got one PropertyInfo per property.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Author
5 Jan 2007 7:26 PM
Kevin Burton
Then I guess the question is why are there duplicates for this object. For
this simple test case I also don't see the duplicate accessor properties. I
don't know if you have Commerce Server installed but the type I am reflecting
on is Microsoft.CommerceServer.Catalog.ProductCollection and each of the
indexed accessor properties are repeated.  The indexers both return
Microsoft.CommerceServer.Catalog.ProductItem. I can send you a screen shot if
you give me an email address.

Kevin

Show quote
"Joanna Carter [TeamB]" wrote:

> "Kevin Burton" <KevinBur***@discussions.microsoft.com> a écrit dans le
> message de news: 35617DB2-09E6-4C95-8A0E-3A5992ABC***@microsoft.com...
>
> |I am trying to reflect on a class that has two indexed accessors. One
> taking
> | an integer argument and one taking a string. If I reflect on the type and
> | execute GetProperties I get an array of PropertyInfo objects. The problem
> is
> | that the indexed accessor properties appear twice. I can't see any
> difference
> | in the two sets of properties. This is being called from C# if that makes
> a
> | difference. Any ideas on why the idexed accessor properties appear twice?
>
> Well, I just tried this :
>
>   public class Test
>   {
>     public string this[int index]
>     {
>       get { return null; }
>     }
>
>     public string this[string index]
>     {
>       get { return null; }
>     }
>   }
>
>   class Program
>   {
>     [STAThread]
>     static void Main(string[] args)
>     {
>       PropertyInfo[] infos = typeof(Test).GetProperties();
>
>       foreach (PropertyInfo info in infos)
>       {
>         Console.WriteLine(info.Name);
>
>         ParameterInfo[] ps = info.GetIndexParameters();
>
>         if (ps.GetLength(0) > 0)
>           Console.WriteLine(ps[0].ParameterType);
>       }
>     }
>   }
>
> .... and only got one PropertyInfo per property.
>
> Joanna
>
> --
> Joanna Carter [TeamB]
> Consultant Software Engineer
>
>
>
Author
5 Jan 2007 8:05 PM
Joanna Carter [TeamB]
"Kevin Burton" <KevinBur***@discussions.microsoft.com> a écrit dans le
message de news: D8D5E031-7C7C-4880-BC2F-5715E6A22***@microsoft.com...

| Then I guess the question is why are there duplicates for this object. For
| this simple test case I also don't see the duplicate accessor properties.
I
| don't know if you have Commerce Server installed but the type I am
reflecting
| on is Microsoft.CommerceServer.Catalog.ProductCollection and each of the
| indexed accessor properties are repeated.  The indexers both return
| Microsoft.CommerceServer.Catalog.ProductItem.

Have you read this :

http://msdn2.microsoft.com/en-us/library/microsoft.commerceserver.catalog.productcollection.item.aspx

There would appear to be two overloads of each of two indexers, one pair for
Product and one for ProductFamily.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Author
5 Jan 2007 8:35 PM
Kevin Burton
It appears something to do with Generics and inheritance. If I just make a
non generic base class from your sample I don't get any duplicates. But if I
modify the test case that you supplied as follows:

    public class TestBase<T>
    {
        public T this[int index]
        {
            get { return default(T); }
        }

        public T this[string index]
        {
            get { return default(T); }
        }
    }
    public class Test : TestBase<string>
    {
        public string this[int index]
        {
            get { return null; }
        }

        public string this[string index]
        {
            get { return null; }
        }
    }

I now get duplicate properties. It is not what I expect but that is probably
from lack of understanding.

Kevin

Show quote
"Joanna Carter [TeamB]" wrote:

> "Kevin Burton" <KevinBur***@discussions.microsoft.com> a écrit dans le
> message de news: D8D5E031-7C7C-4880-BC2F-5715E6A22***@microsoft.com...
>
> | Then I guess the question is why are there duplicates for this object. For
> | this simple test case I also don't see the duplicate accessor properties.
> I
> | don't know if you have Commerce Server installed but the type I am
> reflecting
> | on is Microsoft.CommerceServer.Catalog.ProductCollection and each of the
> | indexed accessor properties are repeated.  The indexers both return
> | Microsoft.CommerceServer.Catalog.ProductItem.
>
> Have you read this :
>
> http://msdn2.microsoft.com/en-us/library/microsoft.commerceserver.catalog.productcollection.item.aspx
>
> There would appear to be two overloads of each of two indexers, one pair for
> Product and one for ProductFamily.
>
> Joanna
>
> --
> Joanna Carter [TeamB]
> Consultant Software Engineer
>
>
>
Author
5 Jan 2007 8:38 PM
Kevin Burton
Since ProductFamily is derived from Product the return type is not casuing
the duplication. From my other post it seems to be some relation to
inheriting from a generic class.

Show quote
"Joanna Carter [TeamB]" wrote:

> "Kevin Burton" <KevinBur***@discussions.microsoft.com> a écrit dans le
> message de news: D8D5E031-7C7C-4880-BC2F-5715E6A22***@microsoft.com...
>
> | Then I guess the question is why are there duplicates for this object. For
> | this simple test case I also don't see the duplicate accessor properties.
> I
> | don't know if you have Commerce Server installed but the type I am
> reflecting
> | on is Microsoft.CommerceServer.Catalog.ProductCollection and each of the
> | indexed accessor properties are repeated.  The indexers both return
> | Microsoft.CommerceServer.Catalog.ProductItem.
>
> Have you read this :
>
> http://msdn2.microsoft.com/en-us/library/microsoft.commerceserver.catalog.productcollection.item.aspx
>
> There would appear to be two overloads of each of two indexers, one pair for
> Product and one for ProductFamily.
>
> Joanna
>
> --
> Joanna Carter [TeamB]
> Consultant Software Engineer
>
>
>

AddThis Social Bookmark Button