Beispiel #1
0
        public void BuildMethodsForGenericInstance(RuntimicSystemModel model, BoundGenericTypeDefinition_I input)
        {
            if (!(input is BoundTypeDefinitionWithMethodsMask_I convertedTypeWithMethods))
            {
                return;
            }

            if (input.UnderlyingType.IsGenericTypeDefinition)
            {
                throw new System.Exception("You cannot get a method that is part of a generic type definition.  Using this method info will cause a method invocation exception. ");
            }

            var blueprintMethods = Methods.Getting.GetMethods(input.Blueprint);

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

                var blueprintUnderlyingMethodInfo = blueprintMethod.UnderlyingMethod;

                // This MUST use typebuilder.GetMethod and not
                // input.Blueprint.UnderlyingType, as different MethodInfo objects are returned.
                var genericInstanceMethodInfo = TypeBuilder.GetMethod(input.UnderlyingType, blueprintUnderlyingMethodInfo);

                var methodDefinition = (MethodDefinition)blueprintMethod.MethodReference;

                var methodReference = Cecil.Methods.Building.MethodDefinitions.
                                      MakeGenericInstanceTypeMethodReference(model, (GenericInstanceType)input.SourceTypeReference, methodDefinition);

                var methodEntry = BuildMethod(model, input, genericInstanceMethodInfo, methodReference);

                AddMethodToBound(convertedTypeWithMethods, methodEntry);
            }
        }
Beispiel #2
0
        // go through each field, and check if the field definition has a reference to a gneric parameter, and replace it.
        public void BuildFields(RuntimicSystemModel semanticModel, BoundGenericTypeDefinition_I converted)
        {
            if (!(converted is BoundTypeDefinitionWithFields_I typeWithFields))
            {
                return;
            }

            var allFields = converted.UnderlyingType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);

            for (int i = 0; i < allFields.Length; i++)
            {
                var field = allFields[i];

                BuildField(semanticModel, typeWithFields, field);
            }
        }
Beispiel #3
0
        public void BuildFields_WithGenericTypeParameters(RuntimicSystemModel semanticModel, BoundGenericTypeDefinition_I input, BoundGenericTypeDefinitionMask_I blueprint)
        {
            if (!(input is BoundTypeDefinitionWithFieldsMask_I typeWithFields))
            {
                return;
            }

            if (!(blueprint is BoundTypeDefinitionWithFieldsMask_I bound))
            {
                return;
            }

            var list = bound.Fields.ByName.Values.ToList();

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

                typeWithFields.Fields.ByName.Add(field.Name, field);
            }
        }