public ConstructorInfo GetConstructor(IEnumerable<Type> argTypes)
        {
            var comparer = new TypeComparer();

            return _type.GetConstructors(BINDING_FLAGS)
                         .Where(c => comparer.Equals(c.GetParameters()
                                                      .Select(p => p.ParameterType), argTypes))
                         .Union(_type.GetConstructors(BINDING_FLAGS)
                                      .Where(c => comparer.Assignable(c.GetParameters()
                                                                       .Select(p => p.ParameterType), argTypes)))
                         .FirstOrDefault();
        }
        public PropertyInfo GetIndexer(IEnumerable<Type> argTypes)
        {
            var matches = _type.GetProperties(BINDING_FLAGS)
                              .Where(p => p.Name.Equals("Item"));

            var comparer = new TypeComparer();

            return matches.Where(m => comparer.Equals(m.GetIndexParameters()
                                                       .Select(p => p.ParameterType), argTypes))
                          .Union(matches.Where(m => comparer.Assignable(m.GetIndexParameters()
                                                                         .Select(p => p.ParameterType), argTypes)))
                          .FirstOrDefault();
        }
        public MethodInfo GetMethod(string methodName, IEnumerable<Type> argTypes)
        {
            var matches = _type.GetMethods(BINDING_FLAGS)
                                .Where(m => m.Name.Equals(methodName))
                                .ToArray();

            var comparer = new TypeComparer();

            return matches.Count() == 1
                   && !argTypes.Any()
                   ? matches.First()
                   : matches.Where(m => comparer.Equals(m.GetParameters()
                                                         .Select(p => p.ParameterType), argTypes))
                            .Union(matches.Where(m => comparer.Assignable(m.GetParameters()
                                                                           .Select(p => p.ParameterType), argTypes)))
                            .FirstOrDefault();
        }
Beispiel #4
0
        /// <summary>
        /// Evaluates the expression, if possible.
        /// </summary>
        /// <returns> The result of evaluating the expression, or <c>null</c> if the expression can
        /// not be evaluated. </returns>
        public override object Evaluate()
        {
            // Evaluate the operands.
            var left = this.Left.Evaluate();

            if (left == null)
            {
                return(null);
            }
            var right = this.Right.Evaluate();

            if (right == null)
            {
                return(null);
            }

            // Apply the binary operator logic.
            switch (this.OperatorType)
            {
            case OperatorType.Add:
            {
                var leftPrimitive  = TypeConverter.ToPrimitive(left, PrimitiveTypeHint.None);
                var rightPrimitive = TypeConverter.ToPrimitive(right, PrimitiveTypeHint.None);
                if (TypeUtilities.IsString(leftPrimitive) == true || TypeUtilities.IsString(rightPrimitive) == true)
                {
                    return(TypeConverter.ToString(leftPrimitive) + TypeConverter.ToString(rightPrimitive));
                }
                return(TypeConverter.ToNumber(leftPrimitive) + TypeConverter.ToNumber(rightPrimitive));
            }

            // Arithmetic operations.
            case OperatorType.Subtract:
                return(TypeConverter.ToNumber(left) - TypeConverter.ToNumber(right));

            case OperatorType.Multiply:
                return(TypeConverter.ToNumber(left) * TypeConverter.ToNumber(right));

            case OperatorType.Divide:
                return(TypeConverter.ToNumber(left) / TypeConverter.ToNumber(right));

            case OperatorType.Modulo:
                return(TypeConverter.ToNumber(left) % TypeConverter.ToNumber(right));

            case OperatorType.Exponentiation:
                return(Library.MathObject.Pow(TypeConverter.ToNumber(left), TypeConverter.ToNumber(right)));

            // Bitwise operations.
            case OperatorType.BitwiseAnd:
                return(TypeConverter.ToInt32(left) & TypeConverter.ToInt32(right));

            case OperatorType.BitwiseOr:
                return(TypeConverter.ToInt32(left) | TypeConverter.ToInt32(right));

            case OperatorType.BitwiseXor:
                return(TypeConverter.ToInt32(left) ^ TypeConverter.ToInt32(right));

            case OperatorType.LeftShift:
                return(TypeConverter.ToInt32(left) << (int)(TypeConverter.ToUint32(right) & 0x1F));

            case OperatorType.SignedRightShift:
                return(TypeConverter.ToInt32(left) >> (int)(TypeConverter.ToUint32(right) & 0x1F));

            case OperatorType.UnsignedRightShift:
                return((uint)TypeConverter.ToInt32(left) >> (int)(TypeConverter.ToUint32(right) & 0x1F));

            // Relational operations.
            case OperatorType.LessThan:
            case OperatorType.LessThanOrEqual:
            case OperatorType.GreaterThan:
            case OperatorType.GreaterThanOrEqual:
                return(PrimitiveType.Bool);

            // Equality operations.
            case OperatorType.Equal:
                return(TypeComparer.Equals(left, right) == true);

            case OperatorType.StrictlyEqual:
                return(TypeComparer.StrictEquals(left, right) == true);

            case OperatorType.NotEqual:
                return(TypeComparer.Equals(left, right) == false);

            case OperatorType.StrictlyNotEqual:
                return(TypeComparer.StrictEquals(left, right) == false);

            // Logical operations.
            case OperatorType.LogicalAnd:
                if (TypeConverter.ToBoolean(left) == false)
                {
                    return(left);
                }
                return(right);

            case OperatorType.LogicalOr:
                if (TypeConverter.ToBoolean(left) == true)
                {
                    return(left);
                }
                return(right);

            // Misc
            case OperatorType.InstanceOf:
            case OperatorType.In:
                return(null);

            default:
                throw new NotImplementedException(string.Format("Unsupported operator {0}", this.OperatorType));
            }
        }
        public void IceAgainstIceShouldBeNotVeryEffective()
        {
            TypeEffect typeEffect = TypeComparer.GetMoveEffectivenessBasedOnPokemonType(iceType, Type.ICE);

            Assert.Equal(TypeEffect.NOT_VERY_EFFECTIVE, typeEffect);
        }
        public void DarkAgainstFairyShouldBeNotVeryEffective()
        {
            TypeEffect typeEffect = TypeComparer.GetMoveEffectivenessBasedOnPokemonType(darkType, Type.FAIRY);

            Assert.Equal(TypeEffect.NOT_VERY_EFFECTIVE, typeEffect);
        }
Beispiel #7
0
        public void FlyingAgainstSteelShouldBeNotVeryEffective()
        {
            TypeEffect typeEffect = TypeComparer.GetMoveEffectivenessBasedOnPokemonType(flyingType, Type.STEEL);

            Assert.Equal(TypeEffect.NOT_VERY_EFFECTIVE, typeEffect);
        }
Beispiel #8
0
        private void AddMissingAliases(TypeDeclaration typeDeclaration)
        {
            var type       = Resolver.ResolveNode(typeDeclaration).Type;
            var interfaces = type.DirectBaseTypes.Where(t => t.Kind == TypeKind.Interface).ToArray();
            var members    = type.GetMembers(null, GetMemberOptions.IgnoreInheritedMembers).ToArray();
            var baseTypes  = type.GetNonInterfaceBaseTypes().ToArray().Reverse();

            if (interfaces.Length > 0)
            {
                foreach (var baseInterface in interfaces)
                {
                    var interfaceMembers = baseInterface.GetMembers().Where(m => m.DeclaringTypeDefinition.Kind == TypeKind.Interface);
                    foreach (var interfaceMember in interfaceMembers)
                    {
                        var isDirectlyImplemented = members.Any(m => m.ImplementedInterfaceMembers.Contains(interfaceMember));
                        if (!isDirectlyImplemented)
                        {
                            foreach (var baseType in baseTypes)
                            {
                                //var derivedMember = InheritanceHelper.GetDerivedMember(interfaceMember, baseType.GetDefinition());
                                IMember derivedMember = null;
                                IEnumerable <IMember> baseMembers;
                                if (interfaceMember.SymbolKind == SymbolKind.Accessor)
                                {
                                    baseMembers = baseType.GetAccessors(null, GetMemberOptions.IgnoreInheritedMembers).Where(m => m.Name == interfaceMember.Name && TypeComparer.Equals(m.ReturnType, interfaceMember.ReturnType));
                                }
                                else
                                {
                                    baseMembers = baseType.GetMembers(null, GetMemberOptions.IgnoreInheritedMembers).Where(m => m.Name == interfaceMember.Name && TypeComparer.Equals(m.ReturnType, interfaceMember.ReturnType));
                                }

                                foreach (IMember baseMember in baseMembers)
                                {
                                    if (baseMember.IsPrivate)
                                    {
                                        continue;
                                    }
                                    if (SignatureComparer.Ordinal.Equals(interfaceMember, baseMember))
                                    {
                                        derivedMember = baseMember.Specialize(interfaceMember.Substitution);
                                        break;
                                    }
                                }

                                if (derivedMember != null && !derivedMember.ImplementedInterfaceMembers.Contains(interfaceMember) && !CurrentType.InstanceConfig.Alias.Any(a => typeDeclaration.Equals(a.Entity) && interfaceMember.Equals(a.InterfaceMember) && derivedMember.Equals(a.DerivedMember)))
                                {
                                    CurrentType.InstanceConfig.Alias.Add(new TypeConfigItem {
                                        Entity = typeDeclaration, InterfaceMember = interfaceMember, DerivedMember = derivedMember
                                    });
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #9
0
 public static bool Is(object value1, object value2)
 {
     return(TypeComparer.SameValue(value1, value2));
 }
        public void FireAgainstDragonShouldBeSuperEffective()
        {
            TypeEffect typeEffect = TypeComparer.GetMoveEffectivenessBasedOnPokemonType(FireType, Type.DRAGON);

            Assert.Equal(TypeEffect.NOT_VERY_EFFECTIVE, typeEffect);
        }
        public void WaterAgainstDragonShouldBeNotVeryEffective()
        {
            TypeEffect typeEffect = TypeComparer.GetMoveEffectivenessBasedOnPokemonType(WaterType, Enums.Type.DRAGON);

            Assert.Equal(TypeEffect.NOT_VERY_EFFECTIVE, typeEffect);
        }
        public void FireAgainstFireShouldBeNotVeryEffective()
        {
            TypeEffect typeEffect = TypeComparer.GetMoveEffectivenessBasedOnPokemonType(FireType, FireType);

            Assert.Equal(TypeEffect.NOT_VERY_EFFECTIVE, typeEffect);
        }
        public void FireAgainstIceShouldBeSuperEffective()
        {
            TypeEffect typeEffect = TypeComparer.GetMoveEffectivenessBasedOnPokemonType(FireType, Type.ICE);

            Assert.Equal(TypeEffect.SUPER_EFFECTIVE, typeEffect);
        }
Beispiel #14
0
 public ContractsFactory()
 {
     _contracts    = new Dictionary <object, object> (500);
     _typeComparer = new TypeComparer();
 }
Beispiel #15
0
 public static void RunMySort(string[] str, TypeComparer typeComparer)
 {
     Console.WriteLine("Запуск сортировки.");
     MySort(str, typeComparer);
     EndSort?.Invoke(str, EventArgs.Empty);
 }
        public void IceAgainstGroundShouldBeSuperEffective()
        {
            TypeEffect typeEffect = TypeComparer.GetMoveEffectivenessBasedOnPokemonType(iceType, Type.GROUND);

            Assert.Equal(TypeEffect.SUPER_EFFECTIVE, typeEffect);
        }
Beispiel #17
0
 public IDebuggerField GetField(SR.FieldInfo field)
 {
     return debugger.Dispatcher.UI(() => {
         var comparer = new TypeComparer();
         foreach (var f in GetFields(field.Name, true)) {
             if (comparer.Equals(f.FieldSig.GetFieldType(), field.FieldType))
                 return f;
         }
         return null;
     });
 }
        void BuildMap()
        {
            // Build an array of object indices and sort it

            RefComparer objectComparer = new RefComparer();

            objectComparer.objects = objects;

            objectIndices = new int [numObjects];
            for (int n = 0; n < numObjects; n++)
            {
                objectIndices [n] = n;
            }
            Array.Sort <int> (objectIndices, objectComparer);
            // Sorted array of codes needed for the binary search
            objectCodes = new uint [numObjects];
            for (int n = 0; n < numObjects; n++)
            {
                objectCodes [n] = objects [objectIndices[n]].Code;
            }

            // Build an array of type indices and sort it

            TypeComparer typeComparer = new TypeComparer();

            typeComparer.types = types;

            typeIndices = new int [numTypes];
            for (int n = 0; n < numTypes; n++)
            {
                typeIndices [n] = n;
            }
            Array.Sort <int> (typeIndices, typeComparer);
            // Sorted array of codes needed for the binary search
            uint[] typeCodes = new uint [numTypes];
            for (int n = 0; n < numTypes; n++)
            {
                typeCodes [n] = types [typeIndices[n]].Code;
            }

            // Assign the type index to each object

            for (int n = 0; n < numObjects; n++)
            {
                int i = Array.BinarySearch <uint> (typeCodes, objectTypeCodes [n]);
                if (i >= 0)
                {
                    objects [n].Type = typeIndices [i];
                    types [objects [n].Type].ObjectCount++;
                    types [objects [n].Type].TotalSize += objects [n].Size;
                }
            }

            // Build the array of referenceCodes, but using indexes
            references = new int [numReferences];

            for (int n = 0; n < numReferences; n++)
            {
                int i = Array.BinarySearch(objectCodes, referenceCodes[n]);
                if (i >= 0)
                {
                    references[n] = objectIndices [i];
                    objects [objectIndices [i]].InverseRefsCount++;
                }
                else
                {
                    references[n] = -1;
                }
            }

            // Calculate the array index of inverse referenceCodes for each object

            int[] invPositions = new int [numObjects];                  // Temporary array to hold reference positions
            int   rp           = 0;

            for (int n = 0; n < numObjects; n++)
            {
                objects [n].InverseRefsIndex = rp;
                invPositions [n]             = rp;
                rp += objects [n].InverseRefsCount;
            }

            // Build the array of inverse referenceCodes
            // Also calculate the index of each field name

            inverseRefs     = new int [numReferences];
            fieldReferences = new int [numReferences];

            for (int ob = 0; ob < numObjects; ob++)
            {
                int fi = types [objects [ob].Type].FieldsIndex;
                int nf = fi + types [objects [ob].Type].FieldsCount;
                int sr = objects [ob].RefsIndex;
                int er = sr + objects [ob].RefsCount;
                for (; sr < er; sr++)
                {
                    int i = references [sr];
                    if (i != -1)
                    {
                        inverseRefs [invPositions [i]] = ob;
                        invPositions [i]++;
                    }
                    // If the reference is bound to a field, locate the field
                    uint fr = fieldReferenceCodes [sr];
                    if (fr != 0)
                    {
                        for (int k = fi; k < nf; k++)
                        {
                            if (fieldCodes [k] == fr)
                            {
                                fieldReferences [sr] = k;
                                break;
                            }
                        }
                    }
                }
            }
        }
Beispiel #19
0
 public IDebuggerMethod GetMethod(SR.MethodBase method)
 {
     return debugger.Dispatcher.UI(() => {
         var comparer = new TypeComparer();
         foreach (var m in GetMethods(method.Name, true)) {
             if (comparer.MethodSigEquals(m.MethodSig, method))
                 return m;
         }
         return null;
     });
 }
        public void FightingAgainstBugShouldBeNotVeryEffective()
        {
            TypeEffect typeEffect = TypeComparer.GetMoveEffectivenessBasedOnPokemonType(fightingType, Type.BUG);

            Assert.Equal(TypeEffect.NOT_VERY_EFFECTIVE, typeEffect);
        }
        public void NormalAgainstRockShouldBeNotVeryEffective()
        {
            TypeEffect typeEffect = TypeComparer.GetMoveEffectivenessBasedOnPokemonType(normalType, Type.ROCK);

            Assert.Equal(TypeEffect.NOT_VERY_EFFECTIVE, typeEffect);
        }
        public void FightingAgainstSteelShouldBeSuperEffective()
        {
            TypeEffect typeEffect = TypeComparer.GetMoveEffectivenessBasedOnPokemonType(fightingType, Type.STEEL);

            Assert.Equal(TypeEffect.SUPER_EFFECTIVE, typeEffect);
        }
Beispiel #23
0
 public static bool IsCovariantTo(this Type type, Type inspected)
 {
     return(TypeComparer.Compare(type, inspected));
 }
Beispiel #24
0
        internal void Build(string name, HeapShotData data)
        {
            this.name = name;

            // Build an array of type indices and sort it

            types = data.TypesList.ToArray();
            TypeComparer typeComparer = new TypeComparer();

            typeComparer.types = types;

            typeIndices = new int [types.Length];
            for (int n = 0; n < types.Length; n++)
            {
                typeIndices [n] = n;
            }
            Array.Sort <int> (typeIndices, typeComparer);
            // Sorted array of codes needed for the binary search
            long[] typeCodes = new long [types.Length];
            for (int n = 0; n < types.Length; n++)
            {
                typeCodes [n] = types [typeIndices[n]].Code;
            }

            // Build an array of object indices and sort it

            RefComparer objectComparer = new RefComparer();

            objectComparer.objects = data.ObjectsList;

            int[] objectIndices = new int [data.ObjectsList.Count];
            for (int n = 0; n < data.ObjectsList.Count; n++)
            {
                objectIndices [n] = n;
            }
            Array.Sort <int> (objectIndices, objectComparer);
            // Sorted array of codes needed for the reordering and binary search
            objectCodes = new long [data.ObjectsList.Count];
            for (int n = 0; n < data.ObjectsList.Count; n++)
            {
                objectCodes [n] = data.ObjectsList [objectIndices[n]].Code;
            }

            // Merge duplicates

            long[]       mergedObjectCodes         = new long [data.RealObjectCount];
            ObjectInfo[] mergedObjects             = new ObjectInfo [data.RealObjectCount];
            long[]       mergedReferenceCodes      = new long [data.ReferenceCodes.Count];
            ulong[]      mergedFieldReferenceCodes = new ulong [data.FieldReferenceCodes.Count];
            long         last            = long.MinValue;
            int          mergedObjectPos = -1;
            int          mergedRefPos    = 0;

            for (int n = 0; n < objectCodes.Length; n++)
            {
                ObjectInfo ob = data.ObjectsList [objectIndices[n]];
                if (n == 0 || objectCodes [n] != last)
                {
                    last = objectCodes [n];
                    mergedObjectPos++;
                    mergedObjects [mergedObjectPos]           = ob;
                    mergedObjects [mergedObjectPos].RefsIndex = mergedRefPos;
                    mergedObjects [mergedObjectPos].RefsCount = 0;                     // Refs are being added below
                    mergedObjectCodes [mergedObjectPos]       = mergedObjects [mergedObjectPos].Code;

                    // Find the type index
                    int i = Array.BinarySearch <long> (typeCodes, data.ObjectTypeCodes [objectIndices[n]]);
                    if (i >= 0)
                    {
                        i = typeIndices [i];
                        mergedObjects [mergedObjectPos].Type = i;
                        types [i].ObjectCount++;
                        types [i].TotalSize += mergedObjects [mergedObjectPos].Size;
                    }
                    else
                    {
                        mergedObjects [mergedObjectPos].Type = 0;
                        long type_not_found = data.ObjectTypeCodes [objectIndices [n]];
                        if (!types_not_found.Contains(type_not_found))
                        {
                            types_not_found.Add(type_not_found);
                            Console.WriteLine("Type not found: " + type_not_found);
                        }
                    }
                }
                int baseRefIndex = ob.RefsIndex;
                int refsCount    = ob.RefsCount;
                for (int r = baseRefIndex; r < baseRefIndex + refsCount; r++, mergedRefPos++)
                {
                    mergedReferenceCodes [mergedRefPos]      = data.ReferenceCodes [r];
                    mergedFieldReferenceCodes [mergedRefPos] = data.FieldReferenceCodes [r];
                }
                mergedObjects [mergedObjectPos].RefsCount += refsCount;
                totalMemory += mergedObjects [mergedObjectPos].Size;
            }

            objects     = mergedObjects;
            objectCodes = mergedObjectCodes;
            int missingRefs = 0;

            // Build the array of referenceCodes, but using indexes
            // Also calculate the number of inverse references for each object
            references = new int [mergedReferenceCodes.Length];

            for (int n = 0; n < mergedReferenceCodes.Length; n++)
            {
                int i = Array.BinarySearch(objectCodes, mergedReferenceCodes[n]);
                if (i >= 0)
                {
                    references[n] = i;
                    objects [i].InverseRefsCount++;
                }
                else
                {
                    //Console.WriteLine ("Referenced object not found: " + mergedReferenceCodes[n]);
                    references[n] = 0;
                    missingRefs++;
                }
            }

            Console.WriteLine("pp Missing references: " + missingRefs + " of " + mergedReferenceCodes.Length);

            // Calculate the array index of inverse referenceCodes for each object

            int[] invPositions = new int [objects.Length];              // Temporary array to hold reference positions
            int   rp           = 0;

            for (int n = 0; n < objects.Length; n++)
            {
                objects [n].InverseRefsIndex = rp;
                invPositions [n]             = rp;
                rp += objects [n].InverseRefsCount;
            }

            // Build the array of inverse referenceCodes
            // Also calculate the index of each field name

            inverseRefs     = new int [mergedReferenceCodes.Length];
            fieldReferences = new int [mergedReferenceCodes.Length];

            for (int ob = 0; ob < objects.Length; ob++)
            {
                long t  = objects [ob].Type;
                int  fi = types [t].FieldsIndex;
                int  nf = fi + types [t].FieldsCount;
                int  sr = objects [ob].RefsIndex;
                int  er = sr + objects [ob].RefsCount;
                for (; sr < er; sr++)
                {
                    int i = references [sr];
                    if (i != -1)
                    {
                        inverseRefs [invPositions [i]] = ob;
                        invPositions [i]++;
                    }
                    // If the reference is bound to a field, locate the field
                    ulong fr = mergedFieldReferenceCodes [sr];
                    if (fr != 0)
                    {
                        for (int k = fi; k < nf; k++)
                        {
                            if (data.FieldCodes [k] == fr)
                            {
                                fieldReferences [sr] = k;
                                break;
                            }
                        }
                    }
                }
            }
        }
        public void DarkAgainstGhostShouldBeSuperEffective()
        {
            TypeEffect typeEffect = TypeComparer.GetMoveEffectivenessBasedOnPokemonType(darkType, Type.GHOST);

            Assert.Equal(TypeEffect.SUPER_EFFECTIVE, typeEffect);
        }
Beispiel #26
0
        static bool KeyPressed(ConsoleKeyInfo keyPress, Creature player, WorldObject[][] map)
        {
            WorldObject objInfront;

            switch (keyPress.Key)
            {
            case ConsoleKey.LeftArrow:
                objInfront = map[vision - 1][vision];
                if (objInfront is null)
                {
                    player.Move(-1, 0);
                }
                else
                {
                    if (TypeComparer.IsSameOrVariant(typeof(CreatureCombatBehavior), objInfront.GetType()).SuccessValue)
                    {
                        Creature       creature = (Creature)objInfront;
                        DamageResponse attack   = player.Hit();
                        IResponse      response = creature.ReceiveHit(attack);
                        if (!response.SuccessValue)
                        {
                            player.ItemManager.AddItems(creature.Loot());
                        }

                        else
                        {
                            response = player.ReceiveHit(creature.Hit());
                            if (!response.SuccessValue)
                            {
                                Console.Clear();
                                Console.WriteLine("YOU DIED");
                            }
                        }
                    }
                }
                break;

            case ConsoleKey.RightArrow:
                objInfront = map[vision + 1][vision];
                if (objInfront is null)
                {
                    player.Move(1, 0);
                }
                else
                {
                    if (TypeComparer.IsSameOrVariant(typeof(CreatureCombatBehavior), objInfront.GetType()).SuccessValue)
                    {
                        Creature       creature = (Creature)objInfront;
                        DamageResponse attack   = player.Hit();
                        IResponse      response = creature.ReceiveHit(attack);
                        if (!response.SuccessValue)
                        {
                            player.ItemManager.AddItems(creature.Loot());
                        }

                        else
                        {
                            response = player.ReceiveHit(creature.Hit());
                            if (!response.SuccessValue)
                            {
                                Console.Clear();
                                Console.WriteLine("YOU DIED");
                            }
                        }
                    }
                }
                break;

            case ConsoleKey.UpArrow:
                objInfront = map[vision][vision + 1];
                if (objInfront is null)
                {
                    player.Move(0, 0 + 1);
                }
                else
                {
                    if (TypeComparer.IsSameOrVariant(typeof(CreatureCombatBehavior), objInfront.GetType()).SuccessValue)
                    {
                        Creature       creature = (Creature)objInfront;
                        DamageResponse attack   = player.Hit();
                        IResponse      response = creature.ReceiveHit(attack);
                        if (!response.SuccessValue)
                        {
                            player.ItemManager.AddItems(creature.Loot());
                        }

                        else
                        {
                            response = player.ReceiveHit(creature.Hit());
                            if (!response.SuccessValue)
                            {
                                Console.Clear();
                                Console.WriteLine("YOU DIED");
                            }
                        }
                    }
                }
                break;

            case ConsoleKey.DownArrow:
                objInfront = map[vision][vision - 1];
                if (objInfront is null)
                {
                    player.Move(0, -1);
                }
                else
                {
                    if (TypeComparer.IsSameOrVariant(typeof(CreatureCombatBehavior), objInfront.GetType()).SuccessValue)
                    {
                        Creature       creature = (Creature)objInfront;
                        DamageResponse attack   = player.Hit();
                        IResponse      response = creature.ReceiveHit(attack);
                        if (!response.SuccessValue)
                        {
                            player.ItemManager.AddItems(creature.Loot());
                        }

                        else
                        {
                            response = player.ReceiveHit(creature.Hit());
                            if (!response.SuccessValue)
                            {
                                Console.Clear();
                                Console.WriteLine("YOU DIED");
                            }
                        }
                    }
                }
                break;

            default:
                return(false);
            }

            return(true);
        }
Beispiel #27
0
        public void FlyingAgainstFightingShouldBeSuperEffective()
        {
            TypeEffect typeEffect = TypeComparer.GetMoveEffectivenessBasedOnPokemonType(flyingType, Type.FIGHTING);

            Assert.Equal(TypeEffect.SUPER_EFFECTIVE, typeEffect);
        }
Beispiel #28
0
        public void SteelAgainstBugShouldBeSuperEffective()
        {
            TypeEffect typeEffect = TypeComparer.GetMoveEffectivenessBasedOnPokemonType(steelType, Type.BUG);

            Assert.Equal(TypeEffect.SUPER_EFFECTIVE, typeEffect);
        }
Beispiel #29
0
 public new bool Equals(object x, object y)
 {
     return(TypeComparer.SameValueZero(x, y));
 }
Beispiel #30
0
 public IDebuggerMethod GetConstructor(params object[] argTypes)
 {
     return debugger.Dispatcher.UI(() => {
         var comparer = new TypeComparer();
         foreach (var m in GetConstructors()) {
             if (comparer.ArgListsEquals(m.MethodSig.Params, argTypes))
                 return m;
         }
         return null;
     });
 }
Beispiel #31
0
        public void SteelAgainstElectricShouldBeNotVeryEffective()
        {
            TypeEffect typeEffect = TypeComparer.GetMoveEffectivenessBasedOnPokemonType(steelType, Type.ELECTRIC);

            Assert.Equal(TypeEffect.NOT_VERY_EFFECTIVE, typeEffect);
        }
Beispiel #32
0
        public void Equals()
        {
            var engine = new ScriptEngine();

            // Undefined.
            Assert.AreEqual(true, TypeComparer.Equals(Undefined.Value, Undefined.Value));
            Assert.AreEqual(true, TypeComparer.Equals(Undefined.Value, Null.Value));
            Assert.AreEqual(false, TypeComparer.Equals(Undefined.Value, false));
            Assert.AreEqual(false, TypeComparer.Equals(Undefined.Value, true));
            Assert.AreEqual(false, TypeComparer.Equals(Undefined.Value, 0));
            Assert.AreEqual(false, TypeComparer.Equals(Undefined.Value, 0.0));
            Assert.AreEqual(false, TypeComparer.Equals(Undefined.Value, 5.5));
            Assert.AreEqual(false, TypeComparer.Equals(Undefined.Value, double.NaN));
            Assert.AreEqual(false, TypeComparer.Equals(Undefined.Value, ""));
            Assert.AreEqual(false, TypeComparer.Equals(Undefined.Value, " "));
            Assert.AreEqual(false, TypeComparer.Equals(Undefined.Value, "5.5"));
            Assert.AreEqual(false, TypeComparer.Equals(Undefined.Value, "foo"));
            Assert.AreEqual(false, TypeComparer.Equals(Undefined.Value, engine.Object.Construct()));

            // Null.
            Assert.AreEqual(true, TypeComparer.Equals(Null.Value, Undefined.Value));
            Assert.AreEqual(true, TypeComparer.Equals(Null.Value, Null.Value));
            Assert.AreEqual(false, TypeComparer.Equals(Null.Value, false));
            Assert.AreEqual(false, TypeComparer.Equals(Null.Value, true));
            Assert.AreEqual(false, TypeComparer.Equals(Null.Value, 0));
            Assert.AreEqual(false, TypeComparer.Equals(Null.Value, 0.0));
            Assert.AreEqual(false, TypeComparer.Equals(Null.Value, 5.5));
            Assert.AreEqual(false, TypeComparer.Equals(Null.Value, double.NaN));
            Assert.AreEqual(false, TypeComparer.Equals(Null.Value, ""));
            Assert.AreEqual(false, TypeComparer.Equals(Null.Value, " "));
            Assert.AreEqual(false, TypeComparer.Equals(Null.Value, "5.5"));
            Assert.AreEqual(false, TypeComparer.Equals(Null.Value, "foo"));
            Assert.AreEqual(false, TypeComparer.Equals(Null.Value, engine.Object.Construct()));

            // Boolean.
            Assert.AreEqual(false, TypeComparer.Equals(false, Undefined.Value));
            Assert.AreEqual(false, TypeComparer.Equals(false, Null.Value));
            Assert.AreEqual(true, TypeComparer.Equals(false, false));
            Assert.AreEqual(false, TypeComparer.Equals(false, true));
            Assert.AreEqual(true, TypeComparer.Equals(false, 0));
            Assert.AreEqual(true, TypeComparer.Equals(false, 0.0));
            Assert.AreEqual(false, TypeComparer.Equals(false, 5.5));
            Assert.AreEqual(false, TypeComparer.Equals(false, double.NaN));
            Assert.AreEqual(true, TypeComparer.Equals(false, ""));
            Assert.AreEqual(true, TypeComparer.Equals(false, " "));
            Assert.AreEqual(true, TypeComparer.Equals(false, "0"));
            Assert.AreEqual(false, TypeComparer.Equals(false, "1"));
            Assert.AreEqual(false, TypeComparer.Equals(false, "5.5"));
            Assert.AreEqual(false, TypeComparer.Equals(false, "false"));
            Assert.AreEqual(false, TypeComparer.Equals(false, "true"));
            Assert.AreEqual(false, TypeComparer.Equals(false, "foo"));
            Assert.AreEqual(false, TypeComparer.Equals(false, engine.Object.Construct()));
            Assert.AreEqual(true, TypeComparer.Equals(false, engine.Boolean.Construct(false)));
            Assert.AreEqual(false, TypeComparer.Equals(false, engine.Boolean.Construct(true)));
            Assert.AreEqual(true, TypeComparer.Equals(false, engine.Number.Construct(0)));
            Assert.AreEqual(false, TypeComparer.Equals(false, engine.Number.Construct(1)));
            Assert.AreEqual(false, TypeComparer.Equals(true, "0"));
            Assert.AreEqual(true, TypeComparer.Equals(true, "1"));

            // Number.
            Assert.AreEqual(false, TypeComparer.Equals(5.5, Undefined.Value));
            Assert.AreEqual(false, TypeComparer.Equals(5.5, Null.Value));
            Assert.AreEqual(false, TypeComparer.Equals(5.5, false));
            Assert.AreEqual(false, TypeComparer.Equals(5.5, true));
            Assert.AreEqual(false, TypeComparer.Equals(5.5, 0));
            Assert.AreEqual(false, TypeComparer.Equals(5.5, 0.0));
            Assert.AreEqual(true, TypeComparer.Equals(5.5, 5.5));
            Assert.AreEqual(false, TypeComparer.Equals(5.5, double.NaN));
            Assert.AreEqual(false, TypeComparer.Equals(5.5, ""));
            Assert.AreEqual(false, TypeComparer.Equals(5.5, " "));
            Assert.AreEqual(true, TypeComparer.Equals(5.5, "5.5"));
            Assert.AreEqual(false, TypeComparer.Equals(5.5, "foo"));
            Assert.AreEqual(false, TypeComparer.Equals(5.5, engine.Object.Construct()));
            Assert.AreEqual(true, TypeComparer.Equals(5.5, engine.Number.Construct(5.5)));
            Assert.AreEqual(true, TypeComparer.Equals(0, 0.0));
            Assert.AreEqual(true, TypeComparer.Equals(5, 5.0));
            Assert.AreEqual(false, TypeComparer.Equals(double.NaN, double.NaN));
            Assert.AreEqual(false, TypeComparer.Equals(double.NaN, engine.Number.Construct(double.NaN)));

            // String.
            Assert.AreEqual(false, TypeComparer.Equals("5.5", Undefined.Value));
            Assert.AreEqual(false, TypeComparer.Equals("5.5", Null.Value));
            Assert.AreEqual(false, TypeComparer.Equals("5.5", false));
            Assert.AreEqual(false, TypeComparer.Equals("5.5", true));
            Assert.AreEqual(false, TypeComparer.Equals("5.5", 0));
            Assert.AreEqual(false, TypeComparer.Equals("5.5", 0.0));
            Assert.AreEqual(true, TypeComparer.Equals("5.5", 5.5));
            Assert.AreEqual(false, TypeComparer.Equals("5.5", double.NaN));
            Assert.AreEqual(false, TypeComparer.Equals("5.5", ""));
            Assert.AreEqual(false, TypeComparer.Equals("5.5", " "));
            Assert.AreEqual(true, TypeComparer.Equals("5.5", "5.5"));
            Assert.AreEqual(false, TypeComparer.Equals("5.5", "foo"));
            Assert.AreEqual(false, TypeComparer.Equals("5.5", engine.Object.Construct()));
            Assert.AreEqual(true, TypeComparer.Equals("5.5", engine.Number.Construct(5.5)));
            Assert.AreEqual(true, TypeComparer.Equals("5.5", engine.String.Construct("5.5")));
            Assert.AreEqual(true, TypeComparer.Equals("0", engine.Boolean.Construct(false)));
            Assert.AreEqual(true, TypeComparer.Equals("1", engine.Boolean.Construct(true)));
            Assert.AreEqual(true, TypeComparer.Equals("", engine.String.Construct()));
            Assert.AreEqual(true, TypeComparer.Equals("", engine.String.Construct("")));

            // Object.
            var temp = engine.Object.Construct();

            Assert.AreEqual(true, TypeComparer.Equals(temp, temp));
            Assert.AreEqual(true, TypeComparer.Equals(engine.Boolean.Construct(false), "0"));
            Assert.AreEqual(false, TypeComparer.Equals(engine.Boolean.Construct(false), "1"));
            Assert.AreEqual(false, TypeComparer.Equals(engine.Boolean.Construct(true), "0"));
            Assert.AreEqual(true, TypeComparer.Equals(engine.Boolean.Construct(true), "1"));
            Assert.AreEqual(false, TypeComparer.Equals(engine.Boolean.Construct(false), "false"));
            Assert.AreEqual(false, TypeComparer.Equals(engine.Boolean.Construct(false), "true"));
            Assert.AreEqual(false, TypeComparer.Equals(engine.Boolean.Construct(true), "false"));
            Assert.AreEqual(false, TypeComparer.Equals(engine.Boolean.Construct(true), "true"));
            Assert.AreEqual(false, TypeComparer.Equals(engine.Object.Construct(), engine.Object.Construct()));
            Assert.AreEqual(false, TypeComparer.Equals(engine.Number.Construct(5.5), engine.Number.Construct(5.5)));
            Assert.AreEqual(true, TypeComparer.Equals(engine.Number.Construct(5.5), 5.5));
            Assert.AreEqual(false, TypeComparer.Equals(engine.String.Construct("5.5"), engine.String.Construct("5.5")));
            Assert.AreEqual(true, TypeComparer.Equals(engine.String.Construct("5.5"), 5.5));
            Assert.AreEqual(true, TypeComparer.Equals(engine.String.Construct(""), ""));
        }
        /// <summary>
        ///     Attempts to construct an instance of <see cref="InjectionDefinition" /> by linking the injection method with the
        ///     injection target (the method to be injected).
        ///     The way how the method is injected is specified by the injection flags. If the injection method does not match the
        ///     criteria set by the injection flags, an exception will be thrown.
        /// </summary>
        /// <param name="injectTarget">The method that will be injected.</param>
        /// <param name="injectMethod">The method which to inject.</param>
        /// <param name="flags">Injection flags that specify what values to pass to the injection method and how to inject it.</param>
        /// <param name="localVarIDs">
        ///     An array of indicies of local variables to pass to the injection method. Used only if
        ///     <see cref="InjectFlags.PassLocals" /> is specified, otherwise ignored.
        /// </param>
        /// <param name="memberReferences">
        ///     An array of class fields from the type the target lies in to pass to the injection
        ///     method. Used only if <see cref="InjectFlags.PassFields" /> is specified, otherwise ignored.
        /// </param>
        public InjectionDefinition(MethodDefinition injectTarget,
                                   MethodDefinition injectMethod,
                                   InjectFlags flags,
                                   int[] localVarIDs = null,
                                   params FieldDefinition[] memberReferences)
        {
            Assert(
            injectMethod.IsStatic,
            $"{nameof(injectMethod)} must be static in order to be used as the injection.");
            Assert(injectMethod.IsPublic, $"{nameof(injectMethod)} must be public.");
            Assert(
            injectMethod.HasBody,
            $"{nameof(injectMethod)} must have a definition in order to be used as the injecton.");

            InjectValues hFlags = flags.ToValues();

            bool isVoid = injectTarget.ReturnType.FullName == "System.Void";

            Assert(
            !hFlags.PassLocals || localVarIDs != null,
            $"Supposed to pass local references, but {nameof(localVarIDs)} is empty");
            Assert(
            !hFlags.PassFields || memberReferences != null,
            $"Supposed to pass member fields, but {nameof(memberReferences)} is empty!");

            int prefixCount = Convert.ToInt32(hFlags.PassTag) + Convert.ToInt32(hFlags.PassInvokingInstance)
                              + Convert.ToInt32(hFlags.ModifyReturn && !isVoid);
            int localsCount = hFlags.PassLocals ? localVarIDs.Length : 0;
            int memberRefCount = (hFlags.PassFields ? memberReferences.Length : 0);
            int paramCount = (hFlags.PassParameters ? injectTarget.Parameters.Count : 0);
            int parameters = injectMethod.Parameters.Count - prefixCount - localsCount - memberRefCount;
            // int parameters = injectMethod.Parameters.Count - prefixCount - localsCount - memberRefCount;
            // PassParameters => 0 < parameters <= injectTarget.Patameters.Count
            // !PassParameters => parameters = 0
            Assert(
            (hFlags.PassParameters && 0 < parameters && parameters <= injectTarget.Parameters.Count
             || !hFlags.PassParameters && parameters == 0),
            //injectMethod.Parameters.Count == prefixCount + localsCount + memberRefCount + paramCount,
            $@"The injection method has a wrong number of parameters! Check that the provided target method, local variables, member references and injection flags add up to the right number of parameters.
Needed parameters: Prefix: {
            prefixCount}, Locals: {localsCount}, Members: {memberRefCount}, Parameters: {
            (hFlags.PassParameters ? "between 1 and " + paramCount : "0")}, TOTAL: {
            (hFlags.PassParameters ? $"between {prefixCount + localsCount + memberRefCount + 1} and " : "")}{
            prefixCount + localsCount + memberRefCount + paramCount}.
Injection has {injectMethod.Parameters.Count
            } parameters.");

            TypeComparer comparer = new TypeComparer();

            if (hFlags.PassTag)
            {
                Assert(
                injectMethod.Parameters[0].ParameterType.FullName == "System.Int32",
                "Supposed to pass a tag, but the provided tag must be of type System.Int32 (int).");
            }

            if (hFlags.PassInvokingInstance)
            {
                Assert(
                !injectTarget.IsStatic,
                "Supposed to pass invoking instance, but the target method is static and thus is not bound to any instances.");
                Assert(
                comparer.Equals(
                injectMethod.Parameters[Convert.ToInt32(hFlags.PassTag)].ParameterType,
                injectTarget.DeclaringType),
                "Supposed to pass invoking instance, but the type of the instance does not match with the type declared in the injection method.");
            }

            if (hFlags.ModifyReturn)
            {
                Assert(
                injectMethod.ReturnType.FullName == "System.Boolean",
                "The injection method must return a boolean in order to alter the return value.");
                Assert(
                isVoid
                || comparer.Equals(
                injectMethod.Parameters[Convert.ToInt32(hFlags.PassTag) + Convert.ToInt32(hFlags.PassInvokingInstance)]
                   .ParameterType,
                new ByReferenceType(injectTarget.ReturnType)),
                "Supposed to modify the return value, but the provided return type does not match with the return type of the target method! Also make sure the type is passed by reference (out/ref).");
            }

            if (hFlags.PassLocals)
            {
                Assert(injectTarget.Body.HasVariables, "The target method does not have any locals.");
                Assert(
                localVarIDs.Length != 0,
                "Supposed to pass method locals, but the IDs of the locals were not specified.");
                Assert(
                localVarIDs.All(i => 0 <= i && i < injectTarget.Body.Variables.Count),
                "Supposed to receive local references, but the provided local variable index/indices do not exist in the target method!");
                Assert(
                injectMethod.Parameters.Slice(prefixCount, localsCount)
                            .Select((p, i) => new {param = p, index = localVarIDs[i]})
                            .All(
                            t =>
                            t.param.ParameterType.IsByReference
                            && comparer.Equals(
                            t.param.ParameterType,
                            new ByReferenceType(injectTarget.Body.Variables[t.index].VariableType))),
                "Supposed to receive local references, but the types between injection method and target method mismatch. Also make sure they are passed by reference (ref/out).");
            }

            if (hFlags.PassFields)
            {
                Assert(!injectTarget.IsStatic, "Cannot pass member references if the injection method is static!");
                Assert(
                memberReferences.Length != 0,
                "Supposed to pass member references, but no members were specified.");
                Assert(
                memberReferences.All(
                m =>
                m.DeclaringType.FullName == injectTarget.DeclaringType.FullName
                && m.DeclaringType.BaseType.FullName == injectTarget.DeclaringType.BaseType.FullName),
                $"The provided member fields do not belong to {injectTarget.DeclaringType}");

                IEnumerable<TypeReference> paramRefs =
                injectMethod.Parameters.Slice(prefixCount + localsCount, memberRefCount).Select(p => p.ParameterType);
                IEnumerable<TypeReference> typeReferences = paramRefs as TypeReference[] ?? paramRefs.ToArray();

                Assert(
                typeReferences.All(p => p.IsByReference),
                "Supposed to pass class members, but the provided parameters in the injection method are not of a reference type (ref)!");
                Assert(
                typeReferences.SequenceEqual(
                memberReferences.Select(f => (TypeReference) new ByReferenceType(f.FieldType)),
                comparer),
                "Supposed to pass class members, but the existing members are of a different type than the ones specified in the injection method.");
            }

            if (hFlags.PassParameters)
            {
                Assert(
                injectMethod.HasGenericParameters == injectTarget.Parameters.Any(p => p.ParameterType.IsGenericParameter),
                "The injection and target methods have mismatching specification of generic parameters!");

                Assert(
                !injectMethod.HasGenericParameters
                || injectMethod.GenericParameters.Count <= injectTarget.GenericParameters.Count + injectTarget.DeclaringType.GenericParameters.Count,
                "The injection and target methods have a mismatching number of generic parameters! The injection method must have less or the same number of generic parameters as the target!");

                Assert(
                !hFlags.PassParametersByRef
                || injectMethod.Parameters.Skip(prefixCount + localsCount + memberRefCount)
                               .All(p => p.ParameterType.IsByReference),
                "Supposed to pass target method parameters by reference, but the provided parameters in the injection method are not of a reference type (ref).");

                Assert(
                injectMethod.Parameters.Skip(prefixCount + localsCount + memberRefCount)
                            .Select(p => p.ParameterType)
                            .SequenceEqual(
                            injectTarget.Parameters.Take(parameters)
                                        .Select(
                                        p =>
                                        (hFlags.PassParametersByRef
                                         ? new ByReferenceType(p.ParameterType) : p.ParameterType)),
                            comparer),
                "Supposed to pass target method parameters by reference, but the types specified in injection and target methods do not match.");
            }

            InjectMethod = injectMethod;
            InjectTarget = injectTarget;
            Flags = flags;
            MemberReferences = memberReferences;
            LocalVarIDs = localVarIDs;
            _PrefixCount = prefixCount;
            _MemeberRefCount = memberRefCount;
            _ParameterCount = parameters;
        }
        public void RockAgainstFightingShouldBeNotVeryEffective()
        {
            TypeEffect typeEffect = TypeComparer.GetMoveEffectivenessBasedOnPokemonType(rockType, Type.FIGHTING);

            Assert.Equal(TypeEffect.NOT_VERY_EFFECTIVE, typeEffect);
        }
Beispiel #35
0
 public IDebuggerEvent GetEvent(SR.EventInfo evt)
 {
     return debugger.Dispatcher.UI(() => {
         var comparer = new TypeComparer();
         foreach (var e in GetEvents(evt.Name, true)) {
             var eventType = e.EventType;
             // EventType currently always returns null
             if (eventType == null)
                 return e;
             if (comparer.Equals(eventType, evt.EventHandlerType))
                 return e;
         }
         return null;
     });
 }
        public void RockAgainstFlyingShouldBeSuperEffective()
        {
            TypeEffect typeEffect = TypeComparer.GetMoveEffectivenessBasedOnPokemonType(rockType, Type.FLYING);

            Assert.Equal(TypeEffect.SUPER_EFFECTIVE, typeEffect);
        }
Beispiel #37
0
 public IDebuggerMethod GetMethod(string name, bool checkBaseClasses, params object[] argTypes)
 {
     return debugger.Dispatcher.UI(() => {
         var comparer = new TypeComparer();
         foreach (var m in GetMethods(name, checkBaseClasses)) {
             if (comparer.ArgListsEquals(m.MethodSig.Params, argTypes))
                 return m;
         }
         return null;
     });
 }
        public void RockAgainstGroundShouldBeNotVeryEffective()
        {
            TypeEffect typeEffect = TypeComparer.GetMoveEffectivenessBasedOnPokemonType(rockType, Type.GROUND);

            Assert.Equal(TypeEffect.NOT_VERY_EFFECTIVE, typeEffect);
        }
Beispiel #39
0
 public IDebuggerProperty GetProperty(SR.PropertyInfo prop)
 {
     return debugger.Dispatcher.UI(() => {
         var comparer = new TypeComparer();
         foreach (var p in GetProperties(prop.Name, true)) {
             if (comparer.PropertySignatureEquals(p, prop))
                 return p;
         }
         return null;
     });
 }
        public void WaterAgainstRockShouldBeSuperEffective()
        {
            TypeEffect typeEffect = TypeComparer.GetMoveEffectivenessBasedOnPokemonType(WaterType, Enums.Type.ROCK);

            Assert.Equal(TypeEffect.SUPER_EFFECTIVE, typeEffect);
        }