Exemplo n.º 1
0
            public AnalysisNet.Types.IGenericParameterReference GetGenericParameter(Cecil.GenericParameter cecilParameter)
            {
                Cecil.IGenericParameterProvider owner = cecilParameter.Owner;
                if (genericParamsMap.TryGetValue(owner, out GenericParameterMap map))
                {
                    return(map[cecilParameter.Position]);
                }

                // populates map
                if (cecilParameter.Type == Cecil.GenericParameterType.Method)
                {
                    typeExtractor.ExtractMethod(owner as Cecil.MethodReference);
                }
                else
                {
                    // check my assumption
                    if ((owner is Cecil.GenericInstanceType))
                    {
                        throw new Exception();
                    }

                    typeExtractor.ExtractType(owner as Cecil.TypeReference);
                }

                map = genericParamsMap[owner];
                return(map[cecilParameter.Position]);
            }
Exemplo n.º 2
0
        private void MapGenericParameters(Cecil.IGenericParameterProvider cecilContainer, AnalysisNet.Types.IGenericReference analysisNetContainer)
        {
            GenericParameterMap map = new GenericParameterMap();

            for (int i = 0; i < cecilContainer.GenericParameters.Count; i++)
            {
                map[i] = cecilContainer.GenericParameters.ElementAt(i);
            }

            genericParamsMap[analysisNetContainer] = map;
        }
Exemplo n.º 3
0
 private AnalysisNet.Types.IGenericReference ExtractOwner(Cecil.IGenericParameterProvider provider)
 {
     if (provider is Cecil.TypeReference typeRef)
     {
         return(ExtractType(typeRef) as AnalysisNet.Types.IBasicType);
     }
     else
     {
         return(ExtractMethod(provider as Cecil.MethodReference));
     }
 }
Exemplo n.º 4
0
            public void MapGenericParameters(Cecil.IGenericParameterProvider cecilContainer, AnalysisNet.Types.IGenericReference analysisNetContainer)
            {
                GenericParameterMap map = new GenericParameterMap();

                for (int i = 0; i < cecilContainer.GenericParameters.Count; i++)
                {
                    Cecil.GenericParameter cecilParam = cecilContainer.GenericParameters.ElementAt(i);
                    AnalysisNet.Types.GenericParameterReference analysisNetParam = new AnalysisNet.Types.GenericParameterReference(GetKind(cecilParam), (ushort)cecilParam.Position)
                    {
                        GenericContainer = analysisNetContainer
                    };
                    map[i] = analysisNetParam;
                }

                genericParamsMap[cecilContainer] = map;

                //throw new NotImplementedException();
            }
Exemplo n.º 5
0
 protected void AddConstraintsToGenericParameters(AnalysisNet.Types.IGenericDefinition genericDefinition, Cecil.IGenericParameterProvider genericParameterProvider)
 {
     foreach (AnalysisNet.Types.GenericParameter analysisNetParameter in genericDefinition.GenericParameters)
     {
         IEnumerable <Cecil.GenericParameterConstraint> constraints = analysisNetParameter.Constraints.Select(c => new Cecil.GenericParameterConstraint(ReferenceGenerator.TypeReference(c)));
         genericParameterProvider.GenericParameters.ElementAt(analysisNetParameter.Index).Constraints.AddRange(constraints);
     }
 }