Solved

How do I use C# convertion types?

Posted on 2011-09-21
5
362 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

627 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