Click or drag to resize

HpSvExtensionsGetOrCreateTSource, TResult Method

Extension method allowing to recursively navigate to a child structure or leaf value in a safe manner, preventing NullReferenceException on accessing missing data.

It traverses the path sequentially. When a child structure does not exist then it is created using a default constructor. Leaf values (like number or string) are not initialized.

Array items could be addressed using constant literals or simple int variable access.

Namespace:  HP.SV.DotNetRuleApi
Assembly:  HP.SV.DotNetRuleApi (in HP.SV.DotNetRuleApi.dll) Version:
public static TResult GetOrCreate<TSource, TResult>(
	this TSource instance,
	Expression<Func<TSource, TResult>> path
where TSource : class, IHpsvObject


Type: TSource
The root object where to start navigation.
Type: System.Linq.ExpressionsExpressionFuncTSource, TResult
The path to navigate using "lambda" syntax.

Type Parameters

Type of root object, inferred from usage.
Type inferred from usage.

Return Value

Type: TResult
The result of navigation of the path.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type . 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).
var result = hpsv.GetOrCreate(r => r.Response.getMemberDetailResponse.getMemberDetailResult);
var index = 0;

var member = hpsv.GetOrCreate(r => r.Response.memberSearchResponse.memberSearchResult.Member[index]);

See Also