public override void Apply(T ruleContext) { Assert.ArgumentNotNull(ruleContext, nameof(ruleContext)); if (string.IsNullOrWhiteSpace(PathA) || string.IsNullOrWhiteSpace(PathB)) { return; } // normalize input, ensure initial slash, avoid trailing slash PathA = StringUtil.EnsurePrefix('/', PathA.TrimEnd('/')); PathB = StringUtil.EnsurePrefix('/', PathB.TrimEnd('/')); // Ensure Path A is the longer path (most specific in case of matching nested placeholder paths) if (PathB.Length > PathA.Length) { var x = PathA; PathA = PathB; PathB = x; } // Use all renderings of selected device var renderings = ruleContext.SelectedRenderings; // Set PathA to temporary PathX var pathX = "XXXSWAPXXX"; foreach (var r in renderings) { if ( TrySwapPath(r, PathA, pathX) ) { ruleContext.HasLayoutChange = true; } } // Set PathB to PathA, PathX to PathB foreach (var r in renderings) { if ( TrySwapPath(r, PathB, PathA) ) { ruleContext.HasLayoutChange = true; } else { TrySwapPath(r, pathX, PathB); } } }
/// <summary> /// Apply this property mapping to transfer data /// between object b and object a /// </summary> /// <param name="a"></param> /// <param name="b"></param> public void ApplyBtoA(object a, object b) { //Tokenise property path string[] pathATokens = PathA.Split('.'); string[] pathBTokens = PathB.Split('.'); //Find resolved source and target objects object source = GetPathEnd(b, pathBTokens); object target = GetPathEnd(a, pathATokens); if (source != null && target != null) { string sourceProp = pathBTokens.Last(); string targetProp = pathATokens.Last(); CopyPropertyData(source, target, sourceProp, targetProp); } }
static void Main(string[] args) { StreamReader Reader = new StreamReader(@"/Work/AoC/Day 3/day3.in"); StreamWriter Writer = new StreamWriter(@"/Work/AoC/Day 3/day3.out"); String[] FirstLine = Reader.ReadLine().Split(","); String[] SecondLine = Reader.ReadLine().Split(","); GetPath(out PathA, FirstLine); GetPath(out PathB, SecondLine); List <KeyValuePair <(int, int), int> > Intersect = PathA.Where(d => PathB.ContainsKey(d.Key)).ToList(); int minIntersection = Intersect.Min(e => Math.Abs(e.Key.Item1) + Math.Abs(e.Key.Item2)); int bestIntersection = Intersect.Min(e => PathA[e.Key] + PathB[e.Key]); Console.WriteLine("Minimum intersection: {0}", minIntersection); Console.WriteLine("Best intersection: {0}", bestIntersection); Writer.WriteLine(minIntersection); Writer.WriteLine(bestIntersection); Writer.Close(); Reader.Close(); }
public override int GetHashCode() { return(PathA.GetHashCode() ^ PathB.GetHashCode() ^ base.GetHashCode()); }