示例#1
0
        private static void GenerateAndPrintCouple(God god)
        {
            IHasName human1 = god.CreateHuman();
            IHasName human2 = god.CreateHuman();

            human1.ToConsole();
            human2.ToConsole();

            try
            {
                IHasName result = god.MakeCouple((Human)human1, (Human)human2);
                if (result == null)
                {
                    Console.WriteLine("They didn't like each other");
                }
                else
                {
                    result.ToConsole();
                }
            }
            catch (WrongCoupleException)
            {
                Console.WriteLine("Wrong couple");
            }
        }
示例#2
0
 public void PrintChild(IHasName obj)
 {
     Console.ForegroundColor = ConsoleColor.Green;
     Console.WriteLine(child + separator + obj.ToString());
     Console.WriteLine(string.Empty);
     Console.ForegroundColor = ConsoleColor.Gray;
 }
示例#3
0
        private IReadOnlyList <IHasName>?ParseGetHeroHeroFriendsNodes(
            JsonElement parent,
            string field)
        {
            if (!parent.TryGetProperty(field, out JsonElement obj))
            {
                return(null);
            }

            if (obj.ValueKind == JsonValueKind.Null)
            {
                return(null);
            }

            int objLength = obj.GetArrayLength();
            var list      = new IHasName[objLength];

            for (int objIndex = 0; objIndex < objLength; objIndex++)
            {
                JsonElement element = obj[objIndex];
                list[objIndex] = new HasName
                                 (
                    DeserializeNullableString(element, "name")
                                 );
            }

            return(list);
        }
        public override void Click(CompletionFunctionality hostItemList)
        {
            Block reference = emptyBlock;

            ReadOnlyCollection <Block> blocksToInsert = Factory.CreateBlocks();

            if (reference != null &&
                blocksToInsert != null &&
                blocksToInsert.Count > 0)
            {
                string        modifiers = emptyBlock.Modifiers.GetModifierString();
                IHasModifiers result    = blocksToInsert[0] as IHasModifiers;
                if (result != null)
                {
                    result.Modifiers.SetMany(modifiers);
                    if (this.Text == "void")
                    {
                        result.Modifiers.Set("void");
                    }
                }
                IHasName named = blocksToInsert[0] as IHasName;
                if (named != null)
                {
                    named.Name = emptyBlock.Name;
                }

                reference.Replace(blocksToInsert);
            }
        }
        private static ApiObject FindObject(IHasName apiObject, IDictionary <string, ApiObject> objects, string key)
        {
            var foundKey = objects.Keys.FirstOrDefault(k => string.Equals(k, key));
            var obj      = foundKey != null ? objects[foundKey] : objects.FirstOrDefault(o => o.Value.Name == apiObject.Name).Value;

            return(obj);
        }
示例#6
0
            void AssertEqualsN(IHasName hn1, IHasName hn2)
            {
                if (hn1 is null)
                {
                    Assert.IsNull(hn2);
                }

                else if (hn1 is ITypeInfo t1)
                {
                    var t2 = hn2 as ITypeInfo;

                    Assert.NotNull(t2);
                    AssertEqualsT(t1, t2);
                }

                else if (hn1 is IMethodInfo m1)
                {
                    var m2 = hn2 as IMethodInfo;

                    Assert.NotNull(m2);
                    AssertEqualsM(m1, m2);
                }

                else
                {
                    Assert.Fail();
                }
            }
示例#7
0
        static async Task Main(string[] args)
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddHttpClient(
                "StarWarsClient",
                c => c.BaseAddress = new Uri("http://localhost:5000/graphql"));
            serviceCollection.AddWebSocketClient(
                "StarWarsClient",
                c => c.Uri = new Uri("ws://localhost:5000/graphql"));
            serviceCollection.AddStarWarsClient();

            IServiceProvider services = serviceCollection.BuildServiceProvider();
            var client = services.GetRequiredService <IStarWarsClient>();
            var result = await client.GetHeroAsync(Episode.NewHope);

            IHasName has = result.Data.Hero;

            result.EnsureNoErrors();
            Console.WriteLine(result.Data.Hero.Name);

            var stream = await client.OnReviewAsync(Episode.NewHope);

            Console.WriteLine("listening...");
            await foreach (var review in stream)
            {
                Console.WriteLine(review.Data.OnReview.Stars);
            }
        }
示例#8
0
        private static void PrintResult(IHasName result)
        {
            Console.ForegroundColor = ConsoleColor.Blue;
            var resultType = result.GetType();

            Console.WriteLine("Тип результату: " + resultType + "\nІм'я: " + result.Name);
        }
示例#9
0
        public void Entered(IHasName element)
        {
            if (_menus.Count < 1 || _menus.Peek() != element)
            {
                _menus.Push(element);
            }

            UpdateConsoleTitle();
        }
示例#10
0
        private static void SetSurname(IHasName child, string name)
        {
            var parName = child.GetType().GetProperty("Surname");

            if (parName != null && parName.CanWrite)
            {
                parName.SetValue(child, name);
            }
        }
示例#11
0
        public static bool FullNameMatches(this IHasName cls, string pattern, bool useRegularExpressions = false)
        {
            if (useRegularExpressions)
            {
                return(pattern != null && Regex.IsMatch(cls.FullName, pattern));
            }

            return(cls.FullNameContains(pattern));
        }
示例#12
0
 private static bool IsOfTypeWithName(
     IHasName objectType,
     object result)
 {
     if (result == null)
     {
         return(true);
     }
     return(objectType.Name.Equals(result.GetType().Name));
 }
示例#13
0
 private IHasName GetChild(Type childType, string name)
 {
     if (childType != null && name != null)
     {
         System.Reflection.ConstructorInfo ci = childType.GetConstructor(new Type[] { typeof(string) });
         IHasName child = ci.Invoke(new object[] { name }) as IHasName;
         return(child);
     }
     return(null);
 }
示例#14
0
        public void StudentPrettyGirlTest()
        {
            God        god     = new God(false);
            Student    student = new Student("Антон");
            PrettyGirl girl    = new PrettyGirl("Анна");
            IHasName   result  = god.MakeCouple(student, girl);

            Girl resultGirl = result as PrettyGirl;

            CheckGeneralGirlRequirements(resultGirl, girl.Name, student.Name + "овна");
        }
示例#15
0
        public void BotanGirlTest()
        {
            God      god     = new God(false);
            Botan    student = new Botan("Антон");
            Girl     girl    = new Girl("Анна");
            IHasName result  = god.MakeCouple(student, girl);

            Girl resultGirl = result as SmartGirl;

            CheckGeneralGirlRequirements(resultGirl, girl.Name, student.Name + "овна");
        }
示例#16
0
        private void SetPatronymicIfExists(IHasName target, Human first, Human second)
        {
            var patronymicProperty = target.GetType().GetProperties(System.Reflection.BindingFlags.NonPublic |
                                                                    System.Reflection.BindingFlags.NonPublic |
                                                                    System.Reflection.BindingFlags.Instance).FirstOrDefault(x => x.Name == PatronymicPropertyName);

            if (patronymicProperty != null)
            {
                var s = NamesHelper.GeneratePatronimyc((first.Gender == Gender.Male ? first : second).Name, Gender.Female);
                patronymicProperty.SetValue(target, s);
            }
        }
 public TypeInitializationContext(ISchemaContext schemaContext,
                                  Action <SchemaError> reportError, IHasName type,
                                  bool isQueryType)
 {
     _schemaContext = schemaContext
                      ?? throw new ArgumentNullException(nameof(schemaContext));
     _reportError = reportError
                    ?? throw new ArgumentNullException(nameof(reportError));
     Type = type
            ?? throw new ArgumentNullException(nameof(type));
     IsQueryType = isQueryType;
     IsDirective = type is DirectiveType;
 }
示例#18
0
        //PUBLIC METHODS
        /// <summary>
        /// Gets human readable event name
        /// </summary>
        public static string FormatName(IHasName obj)
        {
            //get enum name of object
            var name = obj.GetName();

            //convert enum name to string
            var nameWithoutSpaces = name.ToString();

            //add spaces in between camel case letters
            var nameWithSpace = SplitCamelCase(nameWithoutSpaces);

            return(nameWithSpace);
        }
示例#19
0
        private IHasName CreateCoupleResult(string typeName, string humanName, string fatherName)
        {
            Type     type    = Type.GetType(hasNameNamespace + typeName);
            IHasName hasName = (IHasName)Activator.CreateInstance(type, new object[1] {
                humanName
            });

            PropertyInfo info = type.GetProperty("Patronymic");

            if (info != null)
            {
                info.SetValue(hasName, NamesHelper.PatronymicFromName(((Human)hasName).Sex, fatherName));
            }

            return(hasName);
        }
示例#20
0
        private IReadOnlyList <IHasName> ParseRootHeroFriendsNodes(
            JsonElement parent,
            string field)
        {
            if (!parent.TryGetProperty(field, out JsonElement obj))
            {
                return(null);
            }

            string type = obj.GetProperty(TypeName).GetString();

            if (string.Equals(type, "Droid", StringComparison.Ordinal))
            {
                int objLength = obj.GetArrayLength();
                var list      = new IHasName[objLength];

                for (int objIndex = 0; objIndex < objLength; objIndex++)
                {
                    JsonElement element = obj[objIndex];
                    var         entity  = new Droid();
                    entity.Name    = (string)DeserializeString(element, "name");
                    list[objIndex] = entity;
                }

                return(list);
            }

            if (string.Equals(type, "Human", StringComparison.Ordinal))
            {
                int objLength = obj.GetArrayLength();
                var list      = new IHasName[objLength];

                for (int objIndex = 0; objIndex < objLength; objIndex++)
                {
                    JsonElement element = obj[objIndex];
                    var         entity  = new Human();
                    entity.Name    = (string)DeserializeString(element, "name");
                    list[objIndex] = entity;
                }

                return(list);
            }

            throw new UnknownSchemaTypeException(type);
        }
示例#21
0
        public static IHasName Couple(Human x, Human y)
        {
            Console.WriteLine($"Type #1: {x.GetType().Name}, Type #2: {y.GetType().Name}.");

            if (x.Sex == y.Sex)
            {
                throw new SexException("Equals = true.\n");
            }

            CoupleAttribute xCouple = x.GetCoupleAttribute().SingleOrDefault(temp => temp.Pair == y.GetType().Name);
            CoupleAttribute yCouple = y.GetCoupleAttribute().SingleOrDefault(temp => temp.Pair == x.GetType().Name);

            bool xAcces = xCouple?.Probability >= random.NextDouble();
            bool yAcces = yCouple?.Probability >= random.NextDouble();

            if (xAcces && yAcces)
            {
                try
                {
                    IHasName res = (IHasName)Activator.CreateInstance(Type.GetType(x.GetType().Namespace + "." + xCouple.ChildType));

                    var stringMethod = y.GetType().GetMethods(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public).FirstOrDefault(temp => temp.ReturnType == typeof(string));

                    string name = (string)stringMethod?.Invoke(y, null);

                    var nameProp    = res.GetType().GetProperty("Name");
                    var surnameProp = res.GetType().GetProperty("Surname");
                    var sexProp     = res.GetType().GetProperty("Sex");

                    nameProp.SetValue(res, name);

                    if (surnameProp != null)
                    {
                        string surName = x.Sex == Sex.Men ? x.Name : y.Name;

                        surName += (Sex)sexProp.GetValue(res) == Sex.Men ? "ович" : "овна";
                        surnameProp.SetValue(res, surName);
                    }

                    return(res);
                }catch (Exception e) { Console.WriteLine(e.Message); }
            }

            return(null);
        }
示例#22
0
        public void BotanSmartGirlTest()
        {
            God       god     = new God(false);
            Botan     student = new Botan("Антон");
            SmartGirl girl    = new SmartGirl("Анна");
            IHasName  result  = god.MakeCouple(student, girl);

            Book book = result as Book;

            if (book != null)
            {
                Assert.AreEqual(book.Name, girl.Name);
            }
            else
            {
                Assert.Fail("Incorrect resul type");
            }
        }
示例#23
0
        private static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;
            Console.WriteLine(Resources.About);
            if (DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
            {
                Console.WriteLine(Resources.SundayGreeting);
                return;
            }

            Console.WriteLine(Resources.WorkDayGreeting);
            Console.WriteLine(Resources.HowToUse);

            var        entitiesGenerator = new EntitiesGenerator();
            ConsoleKey pressedKey;

            do
            {
                Human parent        = entitiesGenerator.CreateRandomHuman();
                Human anotherParent = entitiesGenerator.CreateRandomHuman();
                parent.ToConsole();
                anotherParent.ToConsole();
                try
                {
                    IHasName child = entitiesGenerator.Couple(parent, anotherParent);
                    if (child == null)
                    {
                        Console.WriteLine(Resources.FailedCoupleCreation);
                    }
                    else
                    {
                        child.ToConsole();
                    }
                }
                catch (SameSexException exception)
                {
                    Console.WriteLine(exception.Message);
                }
                Console.WriteLine();
                pressedKey = ReadControlKey();
            } while (!IsInterruptKey(pressedKey));
        }
示例#24
0
        public void LoadWithDirective()
        {
            var type  = typeof(IHasName);
            var types = Assembly.GetExecutingAssembly().GetTypes()
                        .Where(t => type.IsAssignableFrom(t));

            foreach (var concreteType in types)
            {
                var props      = concreteType.GetProperties();
                var attributes = concreteType.GetCustomAttributes(typeof(PropertyRequirement));

                foreach (var attribute in attributes)
                {
                    var att = attribute as PropertyRequirement;

                    if (att.IsCodeRequired)
                    {
                        HasName = Activator.CreateInstance(concreteType) as IHasName;
                    }
                }
            }
        }
示例#25
0
        static void Main(string[] args)
        {
            ConsoleKeyInfo con = new ConsoleKeyInfo();
            Human          h1, h2;

            do
            {
                try
                {
                    h1 = Human.CreateHuman();
                    h2 = Human.CreateHuman();

                    IHasName res = Human.Couple(h1, h2);

                    if (res != null)
                    {
                        string surname     = "";
                        var    surnameProp = res.GetType().GetProperty("Surname");

                        if (surnameProp != null)
                        {
                            surname = (string)surnameProp.GetValue(res);
                        }

                        Console.WriteLine($"{res.GetType().Name}. {res.Name}. {surname}\n");
                    }
                    else
                    {
                        Console.WriteLine("Bad!\n");
                    }
                }catch (SexException e)
                {
                    Console.WriteLine(e.Message);
                }

                con = Console.ReadKey();
            } while (con.Key != ConsoleKey.Q && con.Key != ConsoleKey.F10);
        }
示例#26
0
 public static bool NameStartsWith(this IHasName cls, string pattern)
 {
     return(cls.Name.ToLower().StartsWith(pattern.ToLower()));
 }
 private static ApiObject FindObject(IHasName apiObject, IDictionary<string, ApiObject> objects, string key)
 {
     var foundKey = objects.Keys.FirstOrDefault(k => string.Equals(k, key));
     var obj = foundKey != null ? objects[foundKey] : objects.FirstOrDefault(o => o.Value.Name == apiObject.Name).Value;
     return obj;
 }
示例#28
0
 public static string GetName(IHasName hasName) => hasName.Name;
示例#29
0
 public int GetOrdinal(IHasName name)
 {
     return _table.Columns.GetIndex(name.Name);
 }
示例#30
0
 public bool GetBoolean(IHasName name)
 {
     return Convert.ToBoolean(_values[GetOrdinal(name.Name)]);
 }
示例#31
0
 public string GetString(IHasName name)
 {
     return Convert.ToString(_values[GetOrdinal(name.Name)]);
 }
示例#32
0
 public int GetInt32(IHasName name)
 {
     return Convert.ToInt32(_values[GetOrdinal(name.Name)]);
 }
示例#33
0
 public long GetInt64(IHasName name)
 {
     return Convert.ToInt64(_values[GetOrdinal(name.Name)]);
 }
示例#34
0
 public short GetInt16(IHasName name)
 {
     return Convert.ToInt16(_values[GetOrdinal(name.Name)]);
 }
示例#35
0
 public byte GetByte(IHasName name)
 {
     return Convert.ToByte(_values[GetOrdinal(name.Name)]);
 }
示例#36
0
 public char GetChar(IHasName name)
 {
     return Convert.ToChar(_values[GetOrdinal(name.Name)]);
 }
示例#37
0
 public BaseIdViewModel(ProfileViewModel profile, IHasName model)
 {
     Profile = profile;
     Id      = model.Id;
     Name    = model.Name;
 }
示例#38
0
 public object GetValue(IHasName name)
 {
     return _values[GetOrdinal(name.Name)];
 }
示例#39
0
 public static bool FullNameContains(this IHasName cls, string pattern)
 {
     return(pattern != null && cls.FullName.ToLower().Contains(pattern.ToLower()));
 }
示例#40
0
 /// <summary>
 /// 获取或设置指定列的数据。
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public object this[IHasName name]
 {
     get { return this[this.GetOrdinal(name.Name)]; }
     set { this[this.GetOrdinal(name.Name)] = value; }
 }
示例#41
0
 public Guid GetGuid(IHasName name)
 {
     return (Guid)_values[GetOrdinal(name.Name)];
 }
示例#42
0
 public DateTime GetDateTime(IHasName name)
 {
     return Convert.ToDateTime(_values[GetOrdinal(name.Name)]);
 }
示例#43
0
        public static IEnumerable <TEvent> FilterEntity <TEvent>(this IEnumerable <TEvent> history, IHasName entity)
            where TEvent : class, IEvent
        {
            var results = history.Where(x => ReferenceEquals(x.Entity, entity));

            return(results);
        }
示例#44
0
 public double GetDouble(IHasName name)
 {
     return Convert.ToDouble(_values[GetOrdinal(name.Name)]);
 }
示例#45
0
 public decimal GetDecimal(IHasName name)
 {
     return Convert.ToDecimal(_values[GetOrdinal(name.Name)]);
 }
示例#46
0
 public float GetFloat(IHasName name)
 {
     return Convert.ToSingle(_values[GetOrdinal(name.Name)]);
 }