Example #1
0
        public void EnsureTypeParametersIfAny(RuntimicSystemModel model, BoundTypeDefinition converted)
        {
            TypeReference inputType = converted.SourceTypeReference;

            if (!inputType.HasGenericParameters)
            {
                return;
            }

            var parameters = inputType.GenericParameters;

            var generic = (BoundGenericTypeDefinition_I)converted;

            Type[] typeArguments = converted.UnderlyingType.GetGenericArguments();

            for (var i = 0; i < parameters.Count; i++)
            {
                var parameter = parameters[i];

                var typeParameter = new BoundGenericParameterTypeDefinition()
                {
                    Attributes          = Cecil.Metadata.Members.GenericParameters.GetTypeParameterAttributes(parameter),
                    Name                = parameter.Name,
                    FullName            = parameter.FullName,
                    Position            = parameter.Position,
                    TypeParameterKind   = Cecil.Metadata.Members.GenericParameters.GetTypeParameterKind(parameter.Type),
                    Definition          = parameter,
                    SourceTypeReference = parameter
                };

                typeParameter.UnderlyingType = FindMatchingType(typeArguments, typeParameter.SourceTypeReference);

                //var typeParameter = CreateTypeParameter(model, typeArguments, inputType, parameters[i]);

                Members.TypeParameters.Add(model, generic.TypeParameters, typeParameter);
            }

            // DO THIS SEPERATELY, as the constraints could be self referencing, and it needs the parameters to be added to this type to find them.
            // THUS THE CREATE AND  ADD OPERATIONS NEED TO BE DONE FIRST.  This is the same reason why the add is called on ensuring before anything else.
            for (var i = 0; i < parameters.Count; i++)
            {
                var typeParameter = (BoundGenericParameterTypeDefinition)generic.TypeParameters.All[i];

                BuildConstraints(model, typeParameter);
            }

            //for (var i = 0; i < parameters.Count; i++)
            //{
            //	var typeParameter = (BoundGenericParameterTypeDefinition)generic.TypeParameters.All[i];

            //	//if (typeParameter.InterfaceTypeConstraints != null && typeParameter.InterfaceTypeConstraints.Count > 0)
            //	//{
            //	//	GetInterfaceTypeConstraints(model, typeParameter.InterfaceTypeConstraints);
            //	//}

            //	//GetBaseTypeConstraint(model, typeParameter.BaseTypeConstraint);

            //}
        }
Example #2
0
        private void BuildConstraints(RuntimicSystemModel model, BoundGenericParameterTypeDefinition typeParameter)
        {
            var typeParamterType = typeParameter.Definition;

            var constraints = typeParamterType.Constraints;

            var semanticConstraints = new BoundGenericParameterTypeDefinitionConstraintMask_I[constraints.Count];

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

                BoundTypeParameterConstraint semanticConstraint;

                bool isClassConstraint = IsClassConstraint(model, constraint);

                if (isClassConstraint)
                {
                    var x = new BoundClassTypeParameterConstraint()
                    {
                        Attributes = typeParameter.Attributes,
                        Class      = Execution.Metadata.Members.Types.Ensuring.EnsureBound(model, constraint)
                    };

                    typeParameter.BaseTypeConstraint = x;

                    semanticConstraint = x;
                }
                else
                {
                    var x = new BoundInterfaceTypeParameterConstraint()
                    {
                        Attributes = typeParameter.Attributes,
                        Interface  = Execution.Metadata.Members.Types.Ensuring.EnsureBound(model, constraint)
                    };

                    semanticConstraint = x;

                    typeParameter.InterfaceTypeConstraints.Add(x);
                }

                semanticConstraints[i] = semanticConstraint;
            }
        }
Example #3
0
        public BoundGenericParameterTypeDefinition CreateTypeParameter(InfrastructureRuntimicModelMask_I conversion, Type[] typeArguments, TypeReference inputType, GenericParameter typeParamterType)
        {
            var typeParameter = new BoundGenericParameterTypeDefinition
            {
                Attributes          = Cecil.Metadata.Members.GenericParameters.GetTypeParameterAttributes(typeParamterType),
                Name                = typeParamterType.Name,
                FullName            = typeParamterType.FullName,
                Position            = typeParamterType.Position,
                TypeParameterKind   = GetTypeParameterKind(typeParamterType.Type),
                Definition          = typeParamterType,
                SourceTypeReference = inputType
            };

            typeParameter.UnderlyingType = FindMatchingType(typeArguments, typeParamterType);



            return(typeParameter);
        }