@@ -29,6 +29,7 @@ internal static class KnownAzureTypes
2929 private const string ETagId = "Azure.Core.eTag" ;
3030 private const string AzureLocationId = "Azure.Core.azureLocation" ;
3131 private const string ArmIdId = "Azure.Core.armResourceIdentifier" ;
32+ private const string AzureError = "Azure.Core.Foundations.Error" ;
3233
3334 private static MethodBodyStatement SerializeTypeWithImplicitOperatorToString ( ValueExpression value , ScopedApi < Utf8JsonWriter > writer , ScopedApi < ModelReaderWriterOptions > options , SerializationFormat format )
3435 => writer . WriteStringValue ( value ) ;
@@ -42,6 +43,14 @@ private static MethodBodyStatement SerializeTypeWithToString(ValueExpression val
4243 private static ValueExpression DeserializeParsableStringLikeType ( CSharpType valueType , ScopedApi < JsonElement > element , SerializationFormat format )
4344 => Static ( valueType ) . Invoke ( "Parse" , element . GetString ( ) ) ;
4445
46+ private static MethodBodyStatement SerializeResponseError ( ValueExpression value , ScopedApi < Utf8JsonWriter > writer , ScopedApi < ModelReaderWriterOptions > options , SerializationFormat format )
47+ => Static ( typeof ( JsonSerializer ) ) . Invoke ( nameof ( JsonSerializer . Serialize ) , writer , value ) . Terminate ( ) ;
48+
49+ private static ValueExpression DeserializeResponseError ( CSharpType valueType ,
50+ ScopedApi < JsonElement > element ,
51+ SerializationFormat format )
52+ => Static ( typeof ( JsonSerializer ) ) . Invoke ( nameof ( JsonSerializer . Deserialize ) , arguments : [ element . GetRawText ( ) ] , typeArguments : [ valueType ] , callAsAsync : false ) ;
53+
4554 private static readonly IReadOnlyDictionary < string , CSharpType > _idToTypes = new Dictionary < string , CSharpType >
4655 {
4756 [ UuidId ] = typeof ( Guid ) ,
@@ -50,6 +59,7 @@ private static ValueExpression DeserializeParsableStringLikeType(CSharpType valu
5059 [ ETagId ] = typeof ( ETag ) ,
5160 [ AzureLocationId ] = typeof ( AzureLocation ) ,
5261 [ ArmIdId ] = typeof ( ResourceIdentifier ) ,
62+ [ AzureError ] = typeof ( ResponseError ) ,
5363 } ;
5464
5565 private static readonly IReadOnlyDictionary < Type , SerializationExpression > _typeToSerializationExpression = new Dictionary < Type , SerializationExpression >
@@ -59,6 +69,7 @@ private static ValueExpression DeserializeParsableStringLikeType(CSharpType valu
5969 [ typeof ( ETag ) ] = SerializeTypeWithToString ,
6070 [ typeof ( AzureLocation ) ] = SerializeTypeWithImplicitOperatorToString ,
6171 [ typeof ( ResourceIdentifier ) ] = SerializeTypeWithImplicitOperatorToString ,
72+ [ typeof ( ResponseError ) ] = SerializeResponseError ,
6273 } ;
6374
6475 private static readonly IReadOnlyDictionary < Type , DeserializationExpression > _typeToDeserializationExpression = new Dictionary < Type , DeserializationExpression >
@@ -68,9 +79,20 @@ private static ValueExpression DeserializeParsableStringLikeType(CSharpType valu
6879 [ typeof ( ETag ) ] = DeserializeNewInstanceStringLikeType ,
6980 [ typeof ( AzureLocation ) ] = DeserializeNewInstanceStringLikeType ,
7081 [ typeof ( ResourceIdentifier ) ] = DeserializeNewInstanceStringLikeType ,
82+ [ typeof ( ResponseError ) ] = DeserializeResponseError ,
7183 } ;
7284
73- public static bool TryGetPrimitiveType ( string id , [ MaybeNullWhen ( false ) ] out CSharpType type ) => _idToTypes . TryGetValue ( id , out type ) ;
85+ public static bool IsModelTypeWithoutSerialization ( CSharpType type )
86+ {
87+ if ( type . Equals ( typeof ( ResponseError ) ) )
88+ {
89+ return true ;
90+ }
91+
92+ return false ;
93+ }
94+
95+ public static bool TryGetKnownType ( string id , [ MaybeNullWhen ( false ) ] out CSharpType type ) => _idToTypes . TryGetValue ( id , out type ) ;
7496
7597 public static bool TryGetJsonSerializationExpression ( Type type , [ MaybeNullWhen ( false ) ] out SerializationExpression expression ) => _typeToSerializationExpression . TryGetValue ( type , out expression ) ;
7698
0 commit comments