score:3
Accepted answer
cartype cartype = getenumvalue<cartype>(xelement, tag);
score:0
myviewmodel.mode = node.element("mymode")?.toenumvalue<modeenum>() ?? modeenum.mode1;
score:1
using system;
using system.xml;
using system.xml.linq;
public class program
{
public enum testtypes { test1, test2, test3};
private static testtypes getenumvalue(xelement x, string tag)
{
if (x.element(tag)!=null) {
var v = x.element(tag).value.tostring();
var testenums = enum.getvalues(typeof(testtypes));
foreach (testtypes enumtype in testenums) {
if (v.equals((testtypes) enumtype)) return enumtype;
}
}
return (testtypes) 0;
}
public static void main()
{
xelement x = new xelement("mytype","test1");
var enumval = getenumvalue(x, "mytype");
console.writeline("type is {0}",(testtypes) enumval);
}
}
Source: stackoverflow.com
Related Query
- LINQ XML - Retrieve unknown name and value from XElement
- XML Linq - find a value of XElement from nested Descendants
- Get max attribute value from XML using LINQ
- get key value pairs from xml using linq
- how to get value from xml by Linq
- How would I use LINQ to XML to get the value from example XML
- Linq to XML - set Xelement value depending on if Statement
- LINQ to XML - filter XElement based on its node value compared to another XElement?
- LINQ to XML set value if it is not null otherwise use default value from the constructor
- Last node is not being return when iterating from Xelement List using Linq to XML in C#
- Get value from XML through linq
- How to get the Inner Element value from Elements in xml linq
- Linq to xml how to get XElement by value in c#
- LINQ XML Getting combobox value from another form c#
- How to fetch value against list of strings from xml using linq and xpath?
- LINQ to XML - Populate/Update the XElement with data from a DataTable
- Linq query select a particular value from xml
- Create XML from CSV using LINQ and XELEMENT
- LINQ XML Get value of element from multiple where statement
- LINQ to XML - Unable to read Elements or Descendants from XDocument or XElement
- Filter a query using value of XElement within XML using LINQ C#
- c# LINQ get Attribute value from XElement
- Linq to XML select distinct value from
- C# LINQ to XML: "Safe" enum value from an XElement?
- C# Linq XML Query where multiple elements of same name from a parent node based on a child node value
- replacing value only from an Xelement using linq
- Using LINQ to retrieve value from XML (Multiple selection)
- How to assign value from properties to enum in Linq
- how to take desired value from the multiple same elements in the xml by using LInq c#
- C# LINQ returning value from parent node in xml
More Query from same tag
- c# linq if item is in list and get matching items from list
- Self registered factory using reflection in c#
- Dynamic Linq with dictionary keys
- LINQ & SQL query help: Doing a distinct on two columns together?
- Order string contains number (Linq, C#)
- LINQ To Entities and how to make this simple query work
- Linq to SQL: Updating dataGridView after SubmitChanges isn't working
- C# merge two properties into a list and filter unique values
- Linq Distinct in one line
- Exclude some items from a list with Lambda
- Call function inside linq query
- RavenDB SelectMany alternative
- List all duplicates in List object including quantity
- How do you catch a Save or Load event on a Linq-to-SQL class?
- Need guidance on creating a new object that stores user information after comparing it
- checking value in datatable
- How can I make this LINQ query of an Enumerable DataTable of GTFS data faster?
- Linq to xml, when child nodes meet a certain condition
- Linq getting count with condition
- C#: If condition in Linq where clause
- Getting the Error in my code when framing LINQ
- How can I get the index of an item in a list in a single step?
- Unable to cast object of type 'System.Collections.Generic.List TO System.Collections.Generic.IList
- C# SELECT GROUP by SUM LINQ
- How do i do the following using LINQ feature of C#?
- System.Linq.IQueryable Error
- Compare efficiency of two different LINQ statements
- Group By variable ceiling value with catch-all maximum using LINQ To NHibernate
- RavenDB Session > 30
- Select Only one row per user and date