Пример #1
0
        public SemanticMethodMask_I FindMethodByDefinition(
            RuntimicSystemModel model,
            BoundTypeDefinitionWithMethodsMask_I boundTypeWithMethods,
            MethodDefinition methodDefinition)
        {
            if (!boundTypeWithMethods.Methods.ByName.TryGetValue(methodDefinition.Name, out List <SemanticMethodMask_I> list))
            {
                throw new Exception($"Could not find the method named {methodDefinition.Name}.");
            }

            for (int i = 0; i < list.Count; i++)
            {
                var method = list[i];

                if (method.MethodReference.MetadataToken.TokenType == methodDefinition.MetadataToken.TokenType &&
                    method.MethodReference.MetadataToken.RID == methodDefinition.MetadataToken.RID)
                {
                    return(method);
                }

                if (Cecil.Metadata.Members.Methods.AreSame(model, methodDefinition, method.MethodReference, false))
                {
                    return(method);
                }
            }

            throw new Exception("Could not find the method.");
        }
Пример #2
0
        private void AddMethodToBound(BoundTypeDefinitionWithMethodsMask_I convertedTypeWithMethods, BoundMethod methodEntry)
        {
            if (!convertedTypeWithMethods.Methods.ByName.TryGetValue(methodEntry.Name, out List <SemanticMethodMask_I> methodList))
            {
                methodList = new List <SemanticMethodMask_I>();

                convertedTypeWithMethods.Methods.ByName.Add(methodEntry.Name, methodList);
            }

            methodList.Add(methodEntry);
        }
Пример #3
0
        public SemanticMethodMask_I FindMethodByDefinition(RuntimicSystemModel model, BoundTypeDefinitionWithMethodsMask_I boundTypeWithMethods, MethodDefinition methodDefinition)
        {
            if (!boundTypeWithMethods.Methods.ByName.TryGetValue(methodDefinition.Name, out List <SemanticMethodMask_I> list))
            {
                throw new System.Exception("Could not find the method.");
            }

            for (int i = 0; i < list.Count; i++)
            {
                var method = list[i];

                if (method.MethodReference == methodDefinition)
                {
                    return(method);
                }
            }

            throw new System.Exception("Could not find the method.");
        }
Пример #4
0
        public MethodInfo GetMethodOrThrow_Internal(ILConversion conversion, ConvertedTypeDefinitionMask_I callingType,
                                                    BoundTypeDefinitionWithMethodsMask_I boundTypeWithMethods, MethodReference methodReference)
        {
            if (boundTypeWithMethods.IsArrayType())
            {
                return(Methods.Building.MakeArrayMethod(conversion, callingType, boundTypeWithMethods, methodReference));
            }



            if (!boundTypeWithMethods.Methods.ByName.TryGetValue(methodReference.Name, out List <SemanticMethodMask_I> list))
            {
                throw new Exception($"Could not find the method {methodReference.FullName}.");
            }

            if (list.Count == 0)
            {
                throw new Exception("Could not find the method.");
            }



            for (int i = 0; i < list.Count; i++)
            {
                var currentSemanticMethod = list[i];

                if (!(currentSemanticMethod is BoundMethodDefinitionMask_I boundMethod))
                {
                    throw new Exception($"The converted type {boundTypeWithMethods.FullName} has a non-bound method present and it cannot be used to get a method info.");
                }

                var method = boundMethod.UnderlyingMethod;

                if (!VerifyReturnType(conversion, currentSemanticMethod.MethodReference, methodReference))
                {
                    continue;
                }

                if (!VerifyGenericArguments(currentSemanticMethod.MethodReference, methodReference))
                {
                    continue;
                }

                if (!Cecil.Methods.AreSame(conversion.RuntimicSystem, currentSemanticMethod.MethodReference.Parameters, methodReference.Parameters, methodReference))
                {
                    continue;
                }

                return(method);

                ////var currentSemanticMethod = list[i];

                //if (Cecil.Metadata.Members.Methods.AreSame(currentSemanticMethod.MethodReference, methodReference))
                //{
                //	if (!(currentSemanticMethod is BoundMethodDefinitionMask_I boundMethod1))
                //	{
                //		throw new Exception($"The converted type {boundTypeWithMethods.FullName} has a non-bound method present and it cannot be used to get a method info.");
                //	}

                //	var method1 = boundMethod1.UnderlyingMethod;

                //	return method1;
                //}
            }

            //for (int i = 0; i < list.Count; i++)
            //{


            // if (i == 6)
            // {

            // }

            // var currentSemanticMethod = list[i];


            // if (Cecil.Metadata.Members.Methods.AreSame(currentSemanticMethod.MethodReference, methodReference))
            // {
            //  if (!(currentSemanticMethod is BoundMethodDefinitionMask_I boundMethod1))
            //  {
            //   throw new Exception($"The converted type {boundTypeWithMethods.FullName} has a non-bound method present and it cannot be used to get a method info.");
            //  }

            //  var method1 = boundMethod1.UnderlyingMethod;

            //  return method1;
            // }

            //}

            throw new Exception("Could not find the method.");
        }