Use multi-field List from Deserialized XML file to populate second single field list (Xamarin)





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















This has to be so simple... in T-SQL it would take me a second.



Before I get duplicate flags... I have been trying some similar problems posted and I have been on this for hours, tinkering with various replies involving JTokens, changing to IEnumerable, deserializing one field only to name a few. I keep getting errors such as:




xamarin cannot implicitly convert type
'System.Collections.Generic.List to 'System.Colletions.List




I have deserialized an xml file into a list like so:



        var assembly = IntrospectionExtensions.GetTypeInfo(typeof(LoadResourceText)).Assembly;
Stream stream = assembly.GetManifestResourceStream("papapp.WineCatInfo.xml");

List<WineCategoryInfo> winecategoryinfos;
using (var reader = new StreamReader(stream))
{
var serializer = new XmlSerializer(typeof(List<WineCategoryInfo>));
winecategoryinfos = (List<WineCategoryInfo>)serializer.Deserialize(reader);
}
#endregion

return winecategoryinfos;


The list it populates is defined like so:



public class WineCategoryInfo
{
public string WineTypeNo { get; set; }
public string WineFamily { get; set; }
public string MainStyle { get; set; }
public string StyleType { get; set; }
public string LengthCharacteristic { get; set; }
public string RegionCommonAppelation { get; set; }
}


I would like a query on the deserialized date to place all the values of one particular field from the above list into a second list, defined like so:



public class WineFamilies
{
public string WineFamily { get; set; }
}


Can someone explain to me how to achieve this?



Many thanks.










share|improve this question





























    0















    This has to be so simple... in T-SQL it would take me a second.



    Before I get duplicate flags... I have been trying some similar problems posted and I have been on this for hours, tinkering with various replies involving JTokens, changing to IEnumerable, deserializing one field only to name a few. I keep getting errors such as:




    xamarin cannot implicitly convert type
    'System.Collections.Generic.List to 'System.Colletions.List




    I have deserialized an xml file into a list like so:



            var assembly = IntrospectionExtensions.GetTypeInfo(typeof(LoadResourceText)).Assembly;
    Stream stream = assembly.GetManifestResourceStream("papapp.WineCatInfo.xml");

    List<WineCategoryInfo> winecategoryinfos;
    using (var reader = new StreamReader(stream))
    {
    var serializer = new XmlSerializer(typeof(List<WineCategoryInfo>));
    winecategoryinfos = (List<WineCategoryInfo>)serializer.Deserialize(reader);
    }
    #endregion

    return winecategoryinfos;


    The list it populates is defined like so:



    public class WineCategoryInfo
    {
    public string WineTypeNo { get; set; }
    public string WineFamily { get; set; }
    public string MainStyle { get; set; }
    public string StyleType { get; set; }
    public string LengthCharacteristic { get; set; }
    public string RegionCommonAppelation { get; set; }
    }


    I would like a query on the deserialized date to place all the values of one particular field from the above list into a second list, defined like so:



    public class WineFamilies
    {
    public string WineFamily { get; set; }
    }


    Can someone explain to me how to achieve this?



    Many thanks.










    share|improve this question

























      0












      0








      0








      This has to be so simple... in T-SQL it would take me a second.



      Before I get duplicate flags... I have been trying some similar problems posted and I have been on this for hours, tinkering with various replies involving JTokens, changing to IEnumerable, deserializing one field only to name a few. I keep getting errors such as:




      xamarin cannot implicitly convert type
      'System.Collections.Generic.List to 'System.Colletions.List




      I have deserialized an xml file into a list like so:



              var assembly = IntrospectionExtensions.GetTypeInfo(typeof(LoadResourceText)).Assembly;
      Stream stream = assembly.GetManifestResourceStream("papapp.WineCatInfo.xml");

      List<WineCategoryInfo> winecategoryinfos;
      using (var reader = new StreamReader(stream))
      {
      var serializer = new XmlSerializer(typeof(List<WineCategoryInfo>));
      winecategoryinfos = (List<WineCategoryInfo>)serializer.Deserialize(reader);
      }
      #endregion

      return winecategoryinfos;


      The list it populates is defined like so:



      public class WineCategoryInfo
      {
      public string WineTypeNo { get; set; }
      public string WineFamily { get; set; }
      public string MainStyle { get; set; }
      public string StyleType { get; set; }
      public string LengthCharacteristic { get; set; }
      public string RegionCommonAppelation { get; set; }
      }


      I would like a query on the deserialized date to place all the values of one particular field from the above list into a second list, defined like so:



      public class WineFamilies
      {
      public string WineFamily { get; set; }
      }


      Can someone explain to me how to achieve this?



      Many thanks.










      share|improve this question














      This has to be so simple... in T-SQL it would take me a second.



      Before I get duplicate flags... I have been trying some similar problems posted and I have been on this for hours, tinkering with various replies involving JTokens, changing to IEnumerable, deserializing one field only to name a few. I keep getting errors such as:




      xamarin cannot implicitly convert type
      'System.Collections.Generic.List to 'System.Colletions.List




      I have deserialized an xml file into a list like so:



              var assembly = IntrospectionExtensions.GetTypeInfo(typeof(LoadResourceText)).Assembly;
      Stream stream = assembly.GetManifestResourceStream("papapp.WineCatInfo.xml");

      List<WineCategoryInfo> winecategoryinfos;
      using (var reader = new StreamReader(stream))
      {
      var serializer = new XmlSerializer(typeof(List<WineCategoryInfo>));
      winecategoryinfos = (List<WineCategoryInfo>)serializer.Deserialize(reader);
      }
      #endregion

      return winecategoryinfos;


      The list it populates is defined like so:



      public class WineCategoryInfo
      {
      public string WineTypeNo { get; set; }
      public string WineFamily { get; set; }
      public string MainStyle { get; set; }
      public string StyleType { get; set; }
      public string LengthCharacteristic { get; set; }
      public string RegionCommonAppelation { get; set; }
      }


      I would like a query on the deserialized date to place all the values of one particular field from the above list into a second list, defined like so:



      public class WineFamilies
      {
      public string WineFamily { get; set; }
      }


      Can someone explain to me how to achieve this?



      Many thanks.







      c# xamarin xamarin.forms xml-parsing json-deserialization






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 26 '18 at 17:44









      MarkMark

      74211




      74211
























          1 Answer
          1






          active

          oldest

          votes


















          1














          use LINQ



          using System.Linq;

          var family = (from x in winecategoryinfos select x.WineFamily).ToList<string>();


          or to eliminate duplicates



          var family = (from x in winecategoryinfos select x.WineFamily).Distinct().ToList<string>();


          if you want to use your WineFamilies class instead of string, try



          var family = (from x in winecategoryinfos select new WineFamilies() { WineFamily = x.WineFamily }).ToList();





          share|improve this answer


























          • Thanks @Jason, But this does not work for me for some reason. I'm sooo glad you replied that as I had tried that and could not see what the prob was. Inserting your suggestion exactly, typing "return family;" in a "public class List<WineFamilies> winefamilies()" gives me the dreaded "Cannot implicitly convert type 'Systems.Collections.Generic.List<string>' to 'Systems.Collections.Generic.List<pappapp.WineFamilies>'

            – Mark
            Nov 26 '18 at 18:15













          • see my additional example

            – Jason
            Nov 26 '18 at 18:34











          • Unfortunately that's not working, the resulting array is populated purely with lines of "papapp.Winefamilies". So if I put this in the picker: BindingContext = new TodoListPageViewModel WinecatList = GetWineInfo() }; All I get is "papapp.WineFamilies" throughout the picker.

            – Mark
            Nov 26 '18 at 19:05













          • that is most likely a problem with how your Picker bindings are setup, and has nothing to do with how you're generating the data

            – Jason
            Nov 26 '18 at 19:06






          • 1





            Picker has a ItemDisplayBinding property that you can use to specify which property to display. If you don't use this, it will just call ToString() on the class, which by default returns the name of the class

            – Jason
            Nov 26 '18 at 19:08












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53486438%2fuse-multi-field-list-from-deserialized-xml-file-to-populate-second-single-fiel%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          use LINQ



          using System.Linq;

          var family = (from x in winecategoryinfos select x.WineFamily).ToList<string>();


          or to eliminate duplicates



          var family = (from x in winecategoryinfos select x.WineFamily).Distinct().ToList<string>();


          if you want to use your WineFamilies class instead of string, try



          var family = (from x in winecategoryinfos select new WineFamilies() { WineFamily = x.WineFamily }).ToList();





          share|improve this answer


























          • Thanks @Jason, But this does not work for me for some reason. I'm sooo glad you replied that as I had tried that and could not see what the prob was. Inserting your suggestion exactly, typing "return family;" in a "public class List<WineFamilies> winefamilies()" gives me the dreaded "Cannot implicitly convert type 'Systems.Collections.Generic.List<string>' to 'Systems.Collections.Generic.List<pappapp.WineFamilies>'

            – Mark
            Nov 26 '18 at 18:15













          • see my additional example

            – Jason
            Nov 26 '18 at 18:34











          • Unfortunately that's not working, the resulting array is populated purely with lines of "papapp.Winefamilies". So if I put this in the picker: BindingContext = new TodoListPageViewModel WinecatList = GetWineInfo() }; All I get is "papapp.WineFamilies" throughout the picker.

            – Mark
            Nov 26 '18 at 19:05













          • that is most likely a problem with how your Picker bindings are setup, and has nothing to do with how you're generating the data

            – Jason
            Nov 26 '18 at 19:06






          • 1





            Picker has a ItemDisplayBinding property that you can use to specify which property to display. If you don't use this, it will just call ToString() on the class, which by default returns the name of the class

            – Jason
            Nov 26 '18 at 19:08
















          1














          use LINQ



          using System.Linq;

          var family = (from x in winecategoryinfos select x.WineFamily).ToList<string>();


          or to eliminate duplicates



          var family = (from x in winecategoryinfos select x.WineFamily).Distinct().ToList<string>();


          if you want to use your WineFamilies class instead of string, try



          var family = (from x in winecategoryinfos select new WineFamilies() { WineFamily = x.WineFamily }).ToList();





          share|improve this answer


























          • Thanks @Jason, But this does not work for me for some reason. I'm sooo glad you replied that as I had tried that and could not see what the prob was. Inserting your suggestion exactly, typing "return family;" in a "public class List<WineFamilies> winefamilies()" gives me the dreaded "Cannot implicitly convert type 'Systems.Collections.Generic.List<string>' to 'Systems.Collections.Generic.List<pappapp.WineFamilies>'

            – Mark
            Nov 26 '18 at 18:15













          • see my additional example

            – Jason
            Nov 26 '18 at 18:34











          • Unfortunately that's not working, the resulting array is populated purely with lines of "papapp.Winefamilies". So if I put this in the picker: BindingContext = new TodoListPageViewModel WinecatList = GetWineInfo() }; All I get is "papapp.WineFamilies" throughout the picker.

            – Mark
            Nov 26 '18 at 19:05













          • that is most likely a problem with how your Picker bindings are setup, and has nothing to do with how you're generating the data

            – Jason
            Nov 26 '18 at 19:06






          • 1





            Picker has a ItemDisplayBinding property that you can use to specify which property to display. If you don't use this, it will just call ToString() on the class, which by default returns the name of the class

            – Jason
            Nov 26 '18 at 19:08














          1












          1








          1







          use LINQ



          using System.Linq;

          var family = (from x in winecategoryinfos select x.WineFamily).ToList<string>();


          or to eliminate duplicates



          var family = (from x in winecategoryinfos select x.WineFamily).Distinct().ToList<string>();


          if you want to use your WineFamilies class instead of string, try



          var family = (from x in winecategoryinfos select new WineFamilies() { WineFamily = x.WineFamily }).ToList();





          share|improve this answer















          use LINQ



          using System.Linq;

          var family = (from x in winecategoryinfos select x.WineFamily).ToList<string>();


          or to eliminate duplicates



          var family = (from x in winecategoryinfos select x.WineFamily).Distinct().ToList<string>();


          if you want to use your WineFamilies class instead of string, try



          var family = (from x in winecategoryinfos select new WineFamilies() { WineFamily = x.WineFamily }).ToList();






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 26 '18 at 18:41

























          answered Nov 26 '18 at 17:53









          JasonJason

          52.8k1292120




          52.8k1292120













          • Thanks @Jason, But this does not work for me for some reason. I'm sooo glad you replied that as I had tried that and could not see what the prob was. Inserting your suggestion exactly, typing "return family;" in a "public class List<WineFamilies> winefamilies()" gives me the dreaded "Cannot implicitly convert type 'Systems.Collections.Generic.List<string>' to 'Systems.Collections.Generic.List<pappapp.WineFamilies>'

            – Mark
            Nov 26 '18 at 18:15













          • see my additional example

            – Jason
            Nov 26 '18 at 18:34











          • Unfortunately that's not working, the resulting array is populated purely with lines of "papapp.Winefamilies". So if I put this in the picker: BindingContext = new TodoListPageViewModel WinecatList = GetWineInfo() }; All I get is "papapp.WineFamilies" throughout the picker.

            – Mark
            Nov 26 '18 at 19:05













          • that is most likely a problem with how your Picker bindings are setup, and has nothing to do with how you're generating the data

            – Jason
            Nov 26 '18 at 19:06






          • 1





            Picker has a ItemDisplayBinding property that you can use to specify which property to display. If you don't use this, it will just call ToString() on the class, which by default returns the name of the class

            – Jason
            Nov 26 '18 at 19:08



















          • Thanks @Jason, But this does not work for me for some reason. I'm sooo glad you replied that as I had tried that and could not see what the prob was. Inserting your suggestion exactly, typing "return family;" in a "public class List<WineFamilies> winefamilies()" gives me the dreaded "Cannot implicitly convert type 'Systems.Collections.Generic.List<string>' to 'Systems.Collections.Generic.List<pappapp.WineFamilies>'

            – Mark
            Nov 26 '18 at 18:15













          • see my additional example

            – Jason
            Nov 26 '18 at 18:34











          • Unfortunately that's not working, the resulting array is populated purely with lines of "papapp.Winefamilies". So if I put this in the picker: BindingContext = new TodoListPageViewModel WinecatList = GetWineInfo() }; All I get is "papapp.WineFamilies" throughout the picker.

            – Mark
            Nov 26 '18 at 19:05













          • that is most likely a problem with how your Picker bindings are setup, and has nothing to do with how you're generating the data

            – Jason
            Nov 26 '18 at 19:06






          • 1





            Picker has a ItemDisplayBinding property that you can use to specify which property to display. If you don't use this, it will just call ToString() on the class, which by default returns the name of the class

            – Jason
            Nov 26 '18 at 19:08

















          Thanks @Jason, But this does not work for me for some reason. I'm sooo glad you replied that as I had tried that and could not see what the prob was. Inserting your suggestion exactly, typing "return family;" in a "public class List<WineFamilies> winefamilies()" gives me the dreaded "Cannot implicitly convert type 'Systems.Collections.Generic.List<string>' to 'Systems.Collections.Generic.List<pappapp.WineFamilies>'

          – Mark
          Nov 26 '18 at 18:15







          Thanks @Jason, But this does not work for me for some reason. I'm sooo glad you replied that as I had tried that and could not see what the prob was. Inserting your suggestion exactly, typing "return family;" in a "public class List<WineFamilies> winefamilies()" gives me the dreaded "Cannot implicitly convert type 'Systems.Collections.Generic.List<string>' to 'Systems.Collections.Generic.List<pappapp.WineFamilies>'

          – Mark
          Nov 26 '18 at 18:15















          see my additional example

          – Jason
          Nov 26 '18 at 18:34





          see my additional example

          – Jason
          Nov 26 '18 at 18:34













          Unfortunately that's not working, the resulting array is populated purely with lines of "papapp.Winefamilies". So if I put this in the picker: BindingContext = new TodoListPageViewModel WinecatList = GetWineInfo() }; All I get is "papapp.WineFamilies" throughout the picker.

          – Mark
          Nov 26 '18 at 19:05







          Unfortunately that's not working, the resulting array is populated purely with lines of "papapp.Winefamilies". So if I put this in the picker: BindingContext = new TodoListPageViewModel WinecatList = GetWineInfo() }; All I get is "papapp.WineFamilies" throughout the picker.

          – Mark
          Nov 26 '18 at 19:05















          that is most likely a problem with how your Picker bindings are setup, and has nothing to do with how you're generating the data

          – Jason
          Nov 26 '18 at 19:06





          that is most likely a problem with how your Picker bindings are setup, and has nothing to do with how you're generating the data

          – Jason
          Nov 26 '18 at 19:06




          1




          1





          Picker has a ItemDisplayBinding property that you can use to specify which property to display. If you don't use this, it will just call ToString() on the class, which by default returns the name of the class

          – Jason
          Nov 26 '18 at 19:08





          Picker has a ItemDisplayBinding property that you can use to specify which property to display. If you don't use this, it will just call ToString() on the class, which by default returns the name of the class

          – Jason
          Nov 26 '18 at 19:08




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53486438%2fuse-multi-field-list-from-deserialized-xml-file-to-populate-second-single-fiel%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Wiesbaden

          Marschland

          Dieringhausen