Ejemplo n.º 1
0
        public BoundMethod BuildMethod(RuntimicSystemModel model, BoundTypeDefinition_I input, MethodInfo method, MethodReference methodReference)
        {
            BoundMethod boundMethod;

            if (method.GetGenericArguments().Length > 0)
            {
                boundMethod = new BoundGenericInstanceMethod
                {
                    DeclaringType    = input,
                    MethodAttributes = method.Attributes,
                    Name             = method.Name,
                    UnderlyingMethod = method,
                    MethodReference  = methodReference,
                };
            }
            else
            {
                boundMethod = new BoundNonGenericInstanceMethod
                {
                    DeclaringType    = input,
                    MethodAttributes = method.Attributes,
                    Name             = method.Name,
                    UnderlyingMethod = method,
                    MethodReference  = methodReference,
                };
            }

            return(boundMethod);
        }
Ejemplo n.º 2
0
        public BoundMethod BuildMethod(InfrastructureRuntimicModelMask_I model, BoundTypeDefinition_I input, MethodInfo method)
        {
            BoundMethod boundMethod;

            if (method.GetGenericArguments().Length > 0)
            {
                boundMethod = new BoundGenericInstanceMethod
                {
                    DeclaringType    = input,
                    MethodAttributes = method.Attributes,
                    Name             = method.Name,
                    UnderlyingMethod = method
                };
            }
            else
            {
                boundMethod = new BoundNonGenericInstanceMethod
                {
                    DeclaringType    = input,
                    MethodAttributes = method.Attributes,
                    Name             = method.Name,
                    UnderlyingMethod = method
                };
            }

            return(boundMethod);
        }
Ejemplo n.º 3
0
        public void BuildFields(RuntimicSystemModel semanticModel, BoundTypeDefinition_I input)
        {
            // Done on purpose to find errors
            var typeDefinition = (TypeDefinition)input.SourceTypeReference;

            if (!typeDefinition.HasFields)
            {
                return;
            }

            if (!(input is BoundTypeDefinitionWithFields_I typeWithFields))
            {
                throw new Exception("Trying to build a field on a type that does not support fields.");
            }

            System.Type type = input.UnderlyingType;

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

                var fieldInfo = type.GetField(field.Name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public
//					| BindingFlags.NonPublic
                                              );

                if (fieldInfo != null)
                {
                    BuildField(semanticModel, typeWithFields, field, fieldInfo);
                }
            }
        }
Ejemplo n.º 4
0
        public void BuildMethods(InfrastructureRuntimicModelMask_I model, BoundTypeDefinition_I input)
        {
            if (!(input is BoundTypeDefinitionWithMethodsMask_I boundTypeWithMethods))
            {
                return;
            }

            if (input.FullName == "Root.Testing.Resources.Models.E01D.Runtimic.Execution.Emitting.Conversion.Inputs.Types.GenericClassWithMembersThatTakeInGenericClassParameters`1<T>")
            {
            }

            // Done on purpose to find errors
            var methods = input.UnderlyingType.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);

            List <BoundMethod> boundMethods = new List <BoundMethod>(methods.Length);

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

                var boundMethod = BuildMethod(model, input, method);

                if (!boundTypeWithMethods.Methods.ByName.TryGetValue(boundMethod.Name, out List <SemanticMethodMask_I> methodList))
                {
                    methodList = new List <SemanticMethodMask_I>();

                    boundTypeWithMethods.Methods.ByName.Add(boundMethod.Name, methodList);
                }

                methodList.Add(boundMethod);

                boundMethods.Add(boundMethod);

                // NULL CHECK: Possibly null if a generic instance
                input.Module?.MethodsByMetadataToken.Add(method.MetadataToken, boundMethod);
            }

            // Get the type definition that corresponds to the type reference.  This will store all the methods that are available.
            var declaringTypeDefinition = Cecil.Metadata.Members.Types.Getting.GetDefinition(model, input.SourceTypeReference);

            // Ensure all the methods are added to prevent this problem:
            #region

            #endregion
            for (int i = 0; i < boundMethods.Count; i++)
            {
                var boundMethod = boundMethods[i];

                // Search the declaring type definition for the method definition that matches the method info.
                boundMethod.MethodReference = Cecil.Metadata.Members.Methods.Getting.FromMethodInfos.References.GetMethodReference(model, declaringTypeDefinition.Methods, boundMethod.UnderlyingMethod);
            }
        }
Ejemplo n.º 5
0
        public void BuildConstructors(RuntimicSystemModel model, BoundTypeDefinition_I input)
        {
            if (!(input is BoundTypeDefinitionWithConstructorsMask_I boundTypeWithConstructors))
            {
                return;
            }



            // Done on purpose to find errors
            var constructors = input.UnderlyingType.GetConstructors(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);

            List <BoundConstructorDefinition> boundConstructors = new List <BoundConstructorDefinition>(constructors.Length);

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

                var boundConstructor = new BoundConstructorDefinition
                {
                    DeclaringType         = input,
                    ConstructorAttributes = constructor.Attributes,
                    Name = constructor.Name,
                    UnderlyingConstructor = constructor,
                    IsStaticConstructor   = constructor.Name == ConstructorInfo.TypeConstructorName
                };

                boundTypeWithConstructors.Constructors.All.Add(boundConstructor);

                boundConstructors.Add(boundConstructor);

                input?.Module?.ConstructorsByMetadataToken.Add(constructor.MetadataToken, boundConstructor);
            }

            // Get the type definition that corresponds to the type reference.  This will store all the constructors that are available.
            var declaringTypeDefinition = Cecil.Metadata.Members.Types.Getting.GetDefinition(model, input.SourceTypeReference);

            // Ensure all the constructors are added to prevent this problem:
            #region

            #endregion
            for (int i = 0; i < boundConstructors.Count; i++)
            {
                var boundConstructor = boundConstructors[i];

                // Search the declaring type definition for the constructor definition that matches the constructor info.
                boundConstructor.MethodReference = Cecil.Metadata.Members.Methods.Getting.GetMethodReference(model, declaringTypeDefinition.Methods, boundConstructor.UnderlyingConstructor.DeclaringType, boundConstructor.UnderlyingConstructor.MetadataToken);
            }
        }
Ejemplo n.º 6
0
        public void BuildConstructors(InfrastructureRuntimicModelMask_I model, BoundTypeDefinition_I input)
        {
            if (!(input is BoundTypeDefinitionWithConstructorsMask_I boundTypeWithConstructors))
            {
                return;
            }

            if (input.FullName == "Root.Testing.Resources.Models.E01D.Runtimic.Execution.Emitting.Conversion.Inputs.Types.GenericClassWithMembersThatTakeInGenericClassParameters`1<T>")
            {
            }

            // Done on purpose to find errors
            var constructors = input.UnderlyingType.GetConstructors(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);

            List <BoundConstructorDefinition> boundConstructors = new List <BoundConstructorDefinition>(constructors.Length);

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

                var boundConstructor = BuildConstructor(model, input, constructor);

                boundTypeWithConstructors.Constructors.All.Add(boundConstructor);

                boundConstructors.Add(boundConstructor);

                input.Module.ConstructorsByMetadataToken.Add(constructor.MetadataToken, boundConstructor);
            }

            // Get the type definition that corresponds to the type reference.  This will store all the constructors that are available.
            var declaringTypeDefinition = Cecil.Metadata.Members.Types.Getting.GetDefinition(model, input.SourceTypeReference);

            // Ensure all the constructors are added to prevent this problem:
            #region

            #endregion
            for (int i = 0; i < boundConstructors.Count; i++)
            {
                var boundConstructor = boundConstructors[i];

                // Search the declaring type definition for the constructor definition that matches the constructor info.
                boundConstructor.MethodReference = Cecil.Metadata.Members.Constructors.Getting.FromConstructorInfos.References.GetMethodReference(model, declaringTypeDefinition, boundConstructor.UnderlyingConstructor);
            }
        }
Ejemplo n.º 7
0
 public BoundConstructorDefinition BuildConstructor(InfrastructureRuntimicModelMask_I model, BoundTypeDefinition_I input, ConstructorInfo constructor)
 {
     return(new BoundConstructorDefinition
     {
         DeclaringType = input,
         ConstructorAttributes = constructor.Attributes,
         Name = constructor.Name,
         UnderlyingConstructor = constructor
     });
 }