Skip to content

M_CodeJam_Xml_XNodeExtensions_ElementAltValueOrDefault__1

Andrew Koryavchenko edited this page Jun 17, 2018 · 6 revisions

XNodeExtensions.ElementAltValueOrDefault(T) Method

Returns value of optional element.

Namespace: CodeJam.Xml
Assembly: CodeJam (in CodeJam.dll) Version: 2.1.0.0

Syntax

C#

public static T ElementAltValueOrDefault<T>(
	this XElement parent,
	Func<XElement, T> valueSelector,
	T defaultValue,
	params XName[] names
)

VB

<ExtensionAttribute>
Public Shared Function ElementAltValueOrDefault(Of T) ( 
	parent As XElement,
	valueSelector As Func(Of XElement, T),
	defaultValue As T,
	ParamArray names As XName()
) As T

F#

[<ExtensionAttribute>]
static member ElementAltValueOrDefault : 
        parent : XElement * 
        valueSelector : Func<XElement, 'T> * 
        defaultValue : 'T * 
        names : XName[] -> 'T 

Parameters

 

parent
Type: System.Xml.Linq.XElement
Parent element.
valueSelector
Type: System.Func(XElement, T)
Function to select element value
defaultValue
Type: T
Default value.
names
Type: System.Xml.Linq.XName[]
Array of possible element names.

Type Parameters

 

T
Type of value

Return Value

Type: T
Selected element value or defaultValue if element does not exist.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type XElement. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Exceptions

 

Exception Condition
ArgumentNullException parent or valueSelector or names is null.

See Also

Reference

XNodeExtensions Class
CodeJam.Xml Namespace

Clone this wiki locally