public List <ConnectionEdge> HandleConnectionEdges <TSource>(TSource item, Action <object> entityAction) { var internalConnectionEdgeState = new InternalConnectionEdgeState(entityAction); var connectionEdges = new List <ConnectionEdge>(); var srcType = item.GetType(); var srcTypeAccessor = TypeAccessor.Create(srcType); var id = srcTypeAccessor.GetKey(item); DiscoverConnectionEdges(id, item, connectionEdges, internalConnectionEdgeState, entityAction); internalConnectionEdgeState.InvokeAction(item, id, srcType.Name); return(connectionEdges); }
private void HandleConnectionEdge( string sourceId, Type sourceType, Type edgeType, string sourceFieldName, object edgeObjectInstance, List <ConnectionEdge> connectionEdges, InternalConnectionEdgeState internalConnectionEdgeState, Action <object> entityAction, bool isListEdge) { var edgeTypeAccessor = TypeAccessor.Create(edgeType); var connectionEdge = new ConnectionEdge { SourceType = sourceType.AssemblyQualifiedName, SourceFieldName = sourceFieldName, SourceId = sourceId, MetaType = edgeType.AssemblyQualifiedName }; Member destinationId = null; Member destinationModel = null; foreach (var edgeMember in edgeTypeAccessor.GetMembers()) { var connectionEdgeDestinationKey = edgeMember.GetAttribute(typeof(ConnectionEdgeDestinationKeyAttribute), false) as ConnectionEdgeDestinationKeyAttribute; if (connectionEdgeDestinationKey != null) { destinationId = edgeMember; } else { var connectionEdgeDestination = edgeMember.GetAttribute(typeof(ConnectionEdgeDestinationAttribute), false) as ConnectionEdgeDestinationAttribute; if (connectionEdgeDestination != null) { destinationModel = edgeMember; } } } if (destinationId == null) { throw new InvalidProgramException("Property with ConnectionEdgeDestinationKeyAttribute is required on a Connection."); } if (destinationModel == null) { throw new InvalidProgramException("Property with ConnectionEdgeDestinationAttribute is required on a Connection."); } var destId = edgeTypeAccessor[edgeObjectInstance, destinationId.Name]; if (destId == null) { throw new InvalidProgramException("Value on property with ConnectionEdgeDestinationKeyAttribute is required!"); } // Eval destination model instance first. var destObject = edgeTypeAccessor[edgeObjectInstance, destinationModel.Name]; if (destObject != null) { var id = destId.ToString(); DiscoverConnectionEdges(id, destObject, connectionEdges, internalConnectionEdgeState, entityAction); internalConnectionEdgeState.InvokeAction(destObject, id, destinationModel.Type.Name); edgeTypeAccessor[edgeObjectInstance, destinationModel.Name] = null; } connectionEdge.DestinationId = destId.ToString(); connectionEdge.Id = isListEdge ? $"{connectionEdge.SourceFieldName}_src{connectionEdge.SourceId}_des{connectionEdge.DestinationId}" : $"{connectionEdge.SourceFieldName}_{connectionEdge.SourceId}"; connectionEdge.MetaFieldName = destinationModel.Name; connectionEdge.MetaValue = JsonConvert.SerializeObject(edgeObjectInstance); connectionEdges.Add(connectionEdge); }