HpSvExtensionsGetOrCreateTSource, TResult Method | ![](../icons/opentext-logo.png) |
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: 6.0.0.72-
Syntaxpublic static TResult GetOrCreate<TSource, TResult>(
this TSource instance,
Expression<Func<TSource, TResult>> path
)
where TSource : class, IHpsvObject
Parameters
- instance
- Type: TSource
The root object where to start navigation. - path
- Type: System.Linq.ExpressionsExpressionFuncTSource, TResult
The path to navigate using "lambda" syntax.
Type Parameters
- TSource
- Type of root object, inferred from usage.
- TResult
- Type inferred from usage.
Return Value
Type:
TResultThe 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).
Examples
var result = hpsv.GetOrCreate(r => r.Response.getMemberDetailResponse.getMemberDetailResult);
Examples
var index = 0;
var member = hpsv.GetOrCreate(r => r.Response.memberSearchResponse.memberSearchResult.Member[index]);
See Also