Esempio n. 1
0
 private static void CheckMethodGenerics(Method call, ClassDefinition node)
 {
     if (node.GenericParameters.Count > 0)
     {
         var tf = new GenericTypeFinder();
         call.Body.Accept(tf);
         var results = tf.Results.ToArray();
         if (results.Length > 0)
         {
             var replacer = new GeneratorTypeReplacer();
             foreach (var gtype in results)
             {
                 var replacement = node.GenericParameters.FirstOrDefault(gp => gp.Name == gtype.Name);
                 if (replacement != null)
                 {
                     replacer.Replace(gtype, (IType)replacement.Entity);
                 }
             }
             if (replacer.Any)
             {
                 call.Body.Accept(new GenericTypeMapper(replacer));
             }
         }
     }
 }
Esempio n. 2
0
        private void MapGenerics(ClassDefinition cd)
        {
            var finder = new GenericTypeFinder();

            foreach (var member in cd.Members)
            {
                member.Accept(finder);
            }

            _mapper = _mapper ?? new GeneratorTypeReplacer();
            var genParams = cd.GenericParameters;

            foreach (var genType in finder.Results)
            {
                var replacement = genParams.FirstOrDefault(p => p.Name.Equals(genType.Name));
                if (replacement != null && genType != replacement.Entity)
                {
                    _mapper.Replace(genType, (IType)replacement.Entity);
                }
            }
        }