Solved

How do I use C# convertion types?

Posted on 2011-09-21
5
355 Views
Last Modified: 2013-12-17
Hi,

I have the below collection...

[CollectionDataContract]
    public class ImageLinkCollection : List<ImageLinkItem>
    {
        public void Add(SPBrandImageLink spImageLinks)
        {
            string strUrl = spImageLinks.URL.IndexOf(',') > 0 ? spImageLinks.URL.Split(',')[0].Trim() : "";

            ImageLinkItem i = new ImageLinkItem(Converters.ConvertNullableInt(spImageLinks.Id), spImageLinks.Title,
                                                spImageLinks.Path,
                                                Converters.ConvertNullableDate(spImageLinks.Created),
                                                Converters.ConvertNullableDate(spImageLinks.Modified));

            SPFieldUrlValue spLogo = spImageLinks.Logo as SPFieldUrlValue;
            if (spLogo != null)
                i.Logo = new ImageDownload(i.Id, spLogo.Description, spLogo.Url, i.Created, i.Modified);
            i.Url = strUrl;
            i.Order = (int)Converters.ConvertNullableDouble(spImageLinks.Order);

            Add(i);
        }
    }

I am attempting to add to the collection with the below but I receive the error "Cannot implicitly convert type System.Collections.Generic.List<SPBrandImageLink> to SPBrandImageLink"?...

var query = from SPBrandImageLink in DAL.BrandOnTheInternet.Cast<SPBrandImageLink>()
                            orderby SPBrandImageLink.Order
                            select SPBrandImageLink;

                SPBrandImageLink spImageLinks = query.ToList<SPBrandImageLink>();

                Logger.LogInfo("Found " + query.Count().ToString() + " On The Internet Links for " + HttpContext.Current.User.Identity.Name);

                result.Add(spImageLinks);
0
Comment
Question by:aspnet-scotland
5 Comments
 
LVL 10

Assisted Solution

by:oxyoo
oxyoo earned 300 total points
ID: 36572454
Instead of:  SPBrandImageLink spImageLinks = query.ToList<SPBrandImageLink>();
Try this:


IList<SPBrandImageLink> spImageLinks = query.ToList<SPBrandImageLink>();

Open in new window

0
 

Accepted Solution

by:
aspnet-scotland earned 0 total points
ID: 36572475
I also had to add the below as a method within ImageLinkCollection changing the initial Add method variable to spImageLink...

public void Add(List<SPBrandImageLink> spImageLinks)
        {
            foreach (SPBrandImageLink spImageLink in spImageLinks)
            {
                Add(spImageLink);
            }
        }

Thanks.
0
 
LVL 16

Assisted Solution

by:Easwaran Paramasivam
Easwaran Paramasivam earned 200 total points
ID: 36572525
Use below code:              

 List<SPBrandImageLink> spImageLinks = query.ToList<SPBrandImageLink>();

0
 
LVL 1

Expert Comment

by:RG59
ID: 36572563
You could just use a var (assuming .Net 3.5 or later) and let .Net take care of it...

var spImageLinks = query.ToList<SPBrandImageLink>();
0
 

Author Closing Comment

by:aspnet-scotland
ID: 36597764
Partially solved myself
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now