Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace CSharpPreparation
  5. {
  6.     public class LambdaExpression
  7.     {
  8.         public LambdaExpression(string selector, string selectorObject, string property)
  9.         {
  10.             this.Selector = selector;
  11.             this.DefaultSelectorObject = selectorObject;
  12.             this.CurrentSelectorObject = selectorObject;
  13.             this.Property = property;
  14.         }
  15.  
  16.         public string Selector { get; }
  17.  
  18.         public string DefaultSelectorObject { get; }
  19.  
  20.         public string CurrentSelectorObject { get; set; }
  21.  
  22.         public string Property { get; set; }
  23.  
  24.         public override string ToString()
  25.         {
  26.             return $"{this.Selector} => {this.CurrentSelectorObject}{this.Property}";
  27.         }
  28.     }
  29.  
  30.     public class Program
  31.     {
  32.         private static void Main(string[] args)
  33.         {
  34.             string input = Console.ReadLine();
  35.             Dictionary<string, LambdaExpression> expressions = new Dictionary<string, LambdaExpression>();
  36.  
  37.             while (input != "lambada")
  38.             {
  39.                 if (input == "dance")
  40.                 {
  41.                     foreach (var expression in expressions)
  42.                     {
  43.                         expression.Value.CurrentSelectorObject += expression.Value.DefaultSelectorObject;
  44.                     }
  45.                 }
  46.                 else
  47.                 {
  48.                     string[] tokens = input.Split(new[] { ' ', '=', '>', '.' }, StringSplitOptions.RemoveEmptyEntries);
  49.                     string selector = tokens[0];
  50.                     string selectorObject = $"{tokens[1]}.";
  51.                     string property = tokens[2];
  52.  
  53.                     if (expressions.ContainsKey(selector))
  54.                     {
  55.                         if (expressions[selector].CurrentSelectorObject == selectorObject)
  56.                         {
  57.                             expressions[selector].Property = property;
  58.                         }
  59.                     }
  60.                     else
  61.                     {
  62.                         expressions.Add(selector, new LambdaExpression(selector, selectorObject, property));
  63.                     }
  64.                 }
  65.  
  66.                 input = Console.ReadLine();
  67.             }
  68.  
  69.             foreach (var expression in expressions)
  70.             {
  71.                 Console.WriteLine(expression.Value);
  72.             }
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement