internal static bool TryGetTypeIdForType(eTypeIdInfo typeWriteSettings, Type type, out string foundTypeId) { if (type == null) { foundTypeId = null; return(false); } if (typeWriteSettings != eTypeIdInfo.None) { if (typeWriteSettings.HasFlag(eTypeIdInfo.TypeIdAttributed)) { if (TypeIdsForType.TryGetValue(type, out string _typeId)) { foundTypeId = _typeId; return(true); } else { // We've got one NOT registered with the system var _idAttr = type.GetAttributes <JsonTypeIdAttribute>()?.FirstOrDefault(); if (_idAttr != null) { foundTypeId = _idAttr.Id; return(true); } } } if (typeWriteSettings.HasFlag(eTypeIdInfo.SystemTypeName)) { foundTypeId = type.Name; return(true); } else if (typeWriteSettings.HasFlag(eTypeIdInfo.FullyQualifiedSystemType)) { foundTypeId = type.AssemblyQualifiedName; return(true); } } foundTypeId = null; return(false); }
public JsonRuntimeTypeEvalAttribute(eTypeIdInfo typeWriteTarget = eTypeIdInfo.Any) { this.TypeWriteTarget = typeWriteTarget; }