Show / Hide Table of Contents

Class ModelParser

Instances of the ModelParser class parse models written in the DTDL language. This class can be used to determine whether one or more DTDL models are valid, to identify specific modeling errors, and to enable inspection of model contents.

Inheritance
object
ModelParser
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: DTDLParser
Assembly: DTDLParser.dll
Syntax
public class ModelParser
Remarks

The primary methods on this class are Parse(IEnumerable<string>, DtdlParseLocator) and ParseAsync(IAsyncEnumerable<string>, DtdlParseLocator, CancellationToken).

Constructors

| Edit this page View Source

ModelParser(ParsingOptions, ModelParsingQuirk)

Initializes a new instance of the ModelParser class.

Declaration
public ModelParser(ParsingOptions parsingOptions = null, ModelParsingQuirk quirks = ModelParsingQuirk.None)
Parameters
Type Name Description
ParsingOptions parsingOptions

An optional ParsingOptions object whose properties configure the ModelParser behavior.

ModelParsingQuirk quirks

An optional set of ModelParsingQuirk values that control parsing of DTDL models.

Properties

| Edit this page View Source

AllowUndefinedExtensions

Gets a value indicating whether and when the parser will continue parsing if it encounters a reference to an extension that cannot be resolved. If this property is Never, an undefined extension context in a model will result in a ParsingException with a ParsingError indicating a ValidationID of dtmi:dtdl:parsingError:unresolvableContextSpecifier or dtmi:dtdl:parsingError:unresolvableContextVersion. If this property is Always, an undefined extension context in a model will not interrupt parsing, and furthermore the presence of this undefined context will allow the model to use undefined co-types and to use undefined properties in elements that have undefined co-types. If this property is not set or is set to PerDefault, the parsing behavior is determined according to the version of the DTDL context specified by the model.

Declaration
public WhenToAllow AllowUndefinedExtensions { get; }
Property Value
Type Description
WhenToAllow
| Edit this page View Source

MaxDtdlVersion

Gets an integer value that restricts the highest DTDL version the parser should accept; if a higher version model is submitted, a ParsingException will be thrown with a ParsingError indicating a ValidationID of dtmi:dtdl:parsingError:disallowedContextVersion.

Declaration
public int MaxDtdlVersion { get; }
Property Value
Type Description
int

Methods

| Edit this page View Source

GetImplicitElements()

Gets an object model representing all the model-level elements implicitly available for reference.

Declaration
public IReadOnlyDictionary<Dtmi, DTEntityInfo> GetImplicitElements()
Returns
Type Description
IReadOnlyDictionary<Dtmi, DTEntityInfo>

A dictionary that maps each Dtmi to a subclass of DTEntityInfo.

| Edit this page View Source

GetSupplementalTypes()

Returns a collection of DTSupplementalTypeInfo objects, each of which provides information about a type known to the parser that is not materialized as a C# class.

Declaration
public IReadOnlyDictionary<Dtmi, DTSupplementalTypeInfo> GetSupplementalTypes()
Returns
Type Description
IReadOnlyDictionary<Dtmi, DTSupplementalTypeInfo>

A dictionary that maps each Dtmi to a DTSupplementalTypeInfo object that describes the type with the given identifier.

| Edit this page View Source

GetTermOrUri(string)

Get a term from a URI string if defined in the context. If not, return the URI string.

Declaration
public static string GetTermOrUri(string uriString)
Parameters
Type Name Description
string uriString

String representation of the URI for which to get the term.

Returns
Type Description
string

The value of the term or the URI string.

| Edit this page View Source

GetTermOrUri(Uri)

Get a term from a URI if defined in the context. If not, return the URI as a string.

Declaration
public static string GetTermOrUri(Uri uri)
Parameters
Type Name Description
Uri uri

The URI for which to get the term.

Returns
Type Description
string

The value of the term or the URI string.

| Edit this page View Source

Parse(IEnumerable<string>, DtdlParseLocator)

Parse a collection of JSON text strings as DTDL models.

Declaration
public IReadOnlyDictionary<Dtmi, DTEntityInfo> Parse(IEnumerable<string> jsonTexts, DtdlParseLocator dtdlLocator = null)
Parameters
Type Name Description
IEnumerable<string> jsonTexts

The JSON text strings to parse as DTDL models.

DtdlParseLocator dtdlLocator

An optional DtdlParseLocator delegate for converting a parse index and line number into a source name and line number.

Returns
Type Description
IReadOnlyDictionary<Dtmi, DTEntityInfo>

A dictionary that maps each Dtmi to a subclass of DTEntityInfo.

| Edit this page View Source

Parse(string, DtdlParseLocator)

Parse a JSON text string as DTDL models.

Declaration
public IReadOnlyDictionary<Dtmi, DTEntityInfo> Parse(string jsonText, DtdlParseLocator dtdlLocator = null)
Parameters
Type Name Description
string jsonText

The JSON text string to parse as DTDL models.

DtdlParseLocator dtdlLocator

An optional DtdlParseLocator delegate for converting a parse index and line number into a source name and line number.

Returns
Type Description
IReadOnlyDictionary<Dtmi, DTEntityInfo>

A dictionary that maps each Dtmi to a subclass of DTEntityInfo.

| Edit this page View Source

ParseAsync(IAsyncEnumerable<string>, DtdlParseLocator, CancellationToken)

Asynchronously parse a collection of JSON text strings as DTDL models.

Declaration
public Task<IReadOnlyDictionary<Dtmi, DTEntityInfo>> ParseAsync(IAsyncEnumerable<string> jsonTexts, DtdlParseLocator dtdlLocator = null, CancellationToken cancellationToken = default)
Parameters
Type Name Description
IAsyncEnumerable<string> jsonTexts

The JSON text strings to parse as DTDL models.

DtdlParseLocator dtdlLocator

An optional DtdlParseLocator delegate for converting a parse index and line number into a source name and line number.

CancellationToken cancellationToken

A CancellationToken to cancel the parsing prematurely.

Returns
Type Description
Task<IReadOnlyDictionary<Dtmi, DTEntityInfo>>

A Task object whose Result property is a dictionary that maps each Dtmi to a subclass of DTEntityInfo.

| Edit this page View Source

ParseAsync(string, DtdlParseLocator, CancellationToken)

Asynchronously parse a JSON text string as DTDL models.

Declaration
public Task<IReadOnlyDictionary<Dtmi, DTEntityInfo>> ParseAsync(string jsonText, DtdlParseLocator dtdlLocator = null, CancellationToken cancellationToken = default)
Parameters
Type Name Description
string jsonText

The JSON text string to parse as DTDL models.

DtdlParseLocator dtdlLocator

An optional DtdlParseLocator delegate for converting a parse index and line number into a source name and line number.

CancellationToken cancellationToken

A CancellationToken to cancel the parsing prematurely.

Returns
Type Description
Task<IReadOnlyDictionary<Dtmi, DTEntityInfo>>

A Task object whose Result property is a dictionary that maps each Dtmi to a subclass of DTEntityInfo.

| Edit this page View Source

ParseToJson(IEnumerable<string>, bool)

Parse a collection of JSON text strings as DTDL models and return the result as a JSON object model.

Declaration
public string ParseToJson(IEnumerable<string> jsonTexts, bool indent = false)
Parameters
Type Name Description
IEnumerable<string> jsonTexts

The JSON text strings to parse as DTDL models.

bool indent

Optional boolean parameter to indent the returned JSON text for improved readability; defaults to false.

Returns
Type Description
string

A string representing a JSON object that maps each DTMI as a string to a DTDL element encoded as a JSON object in accordance with DtdlOm.d.ts.

| Edit this page View Source

ParseToJson(string, bool)

Parse a JSON text string as DTDL models and return the result as a JSON object model.

Declaration
public string ParseToJson(string jsonText, bool indent = false)
Parameters
Type Name Description
string jsonText

The JSON text string to parse as DTDL models.

bool indent

Optional boolean parameter to indent the returned JSON text for improved readability; defaults to false.

Returns
Type Description
string

A string representing a JSON object that maps each DTMI as a string to a DTDL element encoded as a JSON object in accordance with DtdlOm.d.ts.

| Edit this page View Source

ParseToJsonAsync(IAsyncEnumerable<string>, bool)

Asynchronously parse a collection of JSON text strings as DTDL models and return the result as a JSON object model.

Declaration
public Task<string> ParseToJsonAsync(IAsyncEnumerable<string> jsonTexts, bool indent = false)
Parameters
Type Name Description
IAsyncEnumerable<string> jsonTexts

The JSON text strings to parse as DTDL models.

bool indent

Optional boolean parameter to indent the returned JSON text for improved readability; defaults to false.

Returns
Type Description
Task<string>

A Task object whose Result property is a string representing a JSON object that maps each DTMI as a string to a DTDL element encoded as a JSON object in accordance with DtdlOm.d.ts.

| Edit this page View Source

ParseToJsonAsync(string, bool)

Asynchronously parse a JSON text string as DTDL models and return the result as a JSON object model.

Declaration
public Task<string> ParseToJsonAsync(string jsonText, bool indent = false)
Parameters
Type Name Description
string jsonText

The JSON text string to parse as DTDL models.

bool indent

Optional boolean parameter to indent the returned JSON text for improved readability; defaults to false.

Returns
Type Description
Task<string>

A Task object whose Result property is a string representing a JSON object that maps each DTMI as a string to a DTDL element encoded as a JSON object in accordance with DtdlOm.d.ts.

  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX