• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 665
  • Last Modified:

X is not a 'type' but is used like a 'variable' GetType Help

I am trying to return an array of items based on a categoryID.  Basically in the main list of Items there are duplicate categories, I would like to return a list of items with each category list one time (eliminate the duplicates).  In the method below I get a list of items (with the correct category) from the cache, if the list does not exist in cache I then get the Main list with duplicates (an array) and build a new list for that category and store it in cache.  in VB the code would be something like this:
Return CType(newList.ToArray(GetType(ProductCategoryBrandProdLineListItemsInfo)), ProductCategoryBrandProdLineListItemsInfo[])

Please help!


ERROR:
ProductCategoryBrandProdLineListItemsInfo' is a 'type' but is used like a 'variable'

CODE:
        public static ProductCategoryBrandProdLineListItemsInfo[] GetProductCatBrandProdLineListListItems_ByCategoryID(int categoryID)
        {
            if (primitiveCache != null)
            {
                ProductCategoryBrandProdLineListItemsInfo[] list;
                list = (ProductCategoryBrandProdLineListItemsInfo[])(primitiveCache.GetData("ProductCatBrandProdLines." + categoryID.ToString()));
                if (list == null)
                {
                    // This section has not been loaded yet.
                    ArrayList newList;
                    //ProductCategoryBrandProdLineListItemsInfo[] newList;
                    list = GetProductCatBrandProdLineListListItems_All();
                    foreach (ProductCategoryBrandProdLineListItemsInfo item in newList)
                    {
                        if (!newList.Contains(item))
                        {
                            newList.Add(item);
                        }
                    }
                    list = (ProductCategoryBrandProdLineListItemsInfo[]) (newList.ToArray(GetType(ProductCategoryBrandProdLineListItemsInfo())));
                    AddToCache("ProductCatBrandProdLines." + categoryID.ToString(), list);
                }
                return list;
            }
            return null;

        }  
0
wenyonk
Asked:
wenyonk
  • 3
  • 2
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I guess on this line:

list = (ProductCategoryBrandProdLineListItemsInfo[]) (newList.ToArray(GetType(ProductCategoryBrandProdLineListItemsInfo())));

what are you trwing to achieve there?
0
 
2266180Commented:
Hi wenyonk,

the line with error is probably:
> list = (ProductCategoryBrandProdLineListItemsInfo[])
> (newList.ToArray(GetType(ProductCategoryBrandProdLineListItemsInfo())));

you should not use paranthesis after a type. so replace it with
> list = (ProductCategoryBrandProdLineListItemsInfo[])
> (newList.ToArray(GetType(ProductCategoryBrandProdLineListItemsInfo)));
and you should be fine
Cheers!
0
 
2266180Commented:
@angelIII: didn't see your response :) I just installed quickpost and playing around with it. dunno why it didn't get your response just after I posted. guess still need to configure it a little.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
wenyonkAuthor Commented:
Changed to the following:
list = (ProductCategoryBrandProdLineListItemsInfo[]) (newList.ToArray(GetType(ProductCategoryBrandProdLineListItemsInfo)));

Still same error!


I am trying to copy the arraylist to an array
0
 
2266180Commented:
maybe instead of GetType you should use typeof ? check the parameter of GetType. I don't have an IDE handy, but as I remember typeof should do the job for class-es where as gettype is for objects (instances).
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>I am trying to copy the arraylist to an array
then you have to copy the items one by one...
0
 
wenyonkAuthor Commented:
the correct syntax is:
  list = (ProductCategoryBrandProdLineListItemsInfo[]) newList.ToArray(typeof(ProductCategoryBrandProdLineListItemsInfo));

Thank you for all your help and quick response.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now