MCPcopy Create free account
hub / github.com/apache/fory / GetOrCreateTypeInfo

Method GetOrCreateTypeInfo

csharp/src/Fory/TypeResolver.cs:243–273  ·  view source on GitHub ↗
(Type type, TypeInfo? explicitTypeInfo)

Source from the content-addressed store, hash-verified

241 }
242
243 private TypeInfo GetOrCreateTypeInfo(Type type, TypeInfo? explicitTypeInfo)
244 {
245 ulong typeKey = TypeMapKey.Get(type);
246 if (_typeInfos.TryGetValue(typeKey, out TypeInfo? existing))
247 {
248 if (explicitTypeInfo is null || ReferenceEquals(existing, explicitTypeInfo))
249 {
250 return existing;
251 }
252
253 if (existing.IsRegistered)
254 {
255 throw new InvalidDataException($"cannot override serializer for registered type {type}");
256 }
257 }
258
259 TypeInfo typeInfo = explicitTypeInfo ?? CreateBindingCore(type);
260 if (typeInfo.Type != type)
261 {
262 throw new InvalidDataException($"serializer type mismatch for {type}, got {typeInfo.Type}");
263 }
264
265 if (_typeInfos.TryGetValue(typeKey, out TypeInfo? previous))
266 {
267 typeInfo = typeInfo.WithRegistrationFrom(previous);
268 }
269
270 _typeInfos.Set(typeKey, typeInfo);
271 InvalidateFinalizedVersion();
272 return typeInfo;
273 }
274
275 internal TypeInfo RegisterSerializer<T, TSerializer>()
276 where TSerializer : Serializer<T>, new()

Callers

nothing calls this directly

Calls 4

WithRegistrationFromMethod · 0.80
GetMethod · 0.45
TryGetValueMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected