static MessageInfo CreateMessageInfo <T>() where T : class { var objectInfo = ObjectInfoCache.GetObjectInfo <T>(); return(new CachedMessageInfo(objectInfo, TypeMetadataCache <T> .MessageTypeNames)); }
static Type GetPropertyType(string propertyType, PropertyKind kind) { if (kind.HasFlag(PropertyKind.Object)) { if (ObjectInfoCache.TryGetObjectInfo(propertyType, out var propertyObjectInfo)) { var contract = GetOrAddContract(propertyObjectInfo); return(ContractCache.GetContractType(contract)); } } else { var type = Type.GetType(propertyType, true); if (kind.HasFlag(PropertyKind.Nullable)) { type = typeof(Nullable <>).MakeGenericType(type); } return(type); } throw new ArgumentException($"Unable to determine type for property: {propertyType}", nameof(propertyType)); }
public static ObjectInfo[] GetMessageObjectInfo(params MessageInfo[] messageInfos) { var graph = new DependencyGraph <ObjectInfo>(messageInfos.Length); var seen = new HashSet <ObjectInfo>(); void ApplyProperties(ObjectInfo sourceInfo) { if (seen.Contains(sourceInfo)) { return; } seen.Add(sourceInfo); graph.Add(sourceInfo); foreach (var propertyInfo in sourceInfo.Properties) { if ((propertyInfo.Kind & PropertyKind.Object) == PropertyKind.Object) { if (ObjectInfoCache.TryGetObjectInfo(propertyInfo.PropertyType, out var objectInfo)) { graph.Add(sourceInfo, objectInfo); ApplyProperties(objectInfo); } } } } foreach (var messageInfo in messageInfos) { if (ObjectInfoCache.TryGetObjectInfo(messageInfo.ObjectType, out var objectInfo)) { ApplyProperties(objectInfo); } } return(graph.GetItemsInOrder().ToArray()); }