Solved

How do I use C# convertion types?

Posted on 2011-09-21
5
357 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

773 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