public static Expression GetPathToChild([NotNull] this Expression path, [NotNull] ModelConfigurationEdge edge) { if (edge.IsArrayIndex) { return(path.MakeArrayIndex((int)edge.Value)); } if (edge.IsMemberAccess) { return(path.MakeMemberAccess((MemberInfo)edge.Value)); } if (edge.IsEachMethod) { return(path.MakeEachCall()); } if (edge.IsConvertation) { return(path.MakeTypeConversion((Type)edge.Value)); } if (edge.IsIndexerParams) { return(path.MakeIndexerCall((object[])edge.Value, path.Type)); } throw new InvalidOperationException($"Unknown edge value: {edge.Value}"); }
internal ModelConfigurationNode(Type rootType, Type nodeType, ModelConfigurationNode root, ModelConfigurationNode parent, ModelConfigurationEdge edge, Expression path) { RootType = rootType; NodeType = nodeType; Root = root ?? this; Parent = parent; Edge = edge; Path = path; mutators = new List <KeyValuePair <Expression, MutatorConfiguration> >(); children = new Dictionary <ModelConfigurationEdge, ModelConfigurationNode>(); }
public static ModelConfigurationNode GotoIndexer([NotNull] this ModelConfigurationNode node, [NotNull] object[] parameters, bool create) { var edge = new ModelConfigurationEdge(parameters); var property = node.NodeType.GetProperty("Item", BindingFlags.Public | BindingFlags.Instance); if (property == null) { throw new InvalidOperationException("Type '" + node.NodeType + "' doesn't contain indexer"); } if (!property.CanRead || !property.CanWrite) { throw new InvalidOperationException("Type '" + node.NodeType + "' has indexer that doesn't contain either getter or setter"); } return(node.GetChild(edge, create)); }
public NodeBuilder this[[NotNull] ModelConfigurationEdge edge] { set => children.Add((edge, value));
private static ModelConfigurationNode GetChild([NotNull] this ModelConfigurationNode node, [NotNull] ModelConfigurationEdge edge, bool create) { if (node.children.TryGetValue(edge, out var child)) { return(child); } if (!create) { return(null); } var childPath = node.Path.GetPathToChild(edge); child = new ModelConfigurationNode(node.ConfiguratorType, node.RootType, childPath.Type, node.Root, node, edge, childPath); node.children.Add(edge, child); return(child); }