Exemple #1
0
        private FuzzyMethod(FuzzyType target, IMethodInfo runtimeMethod)
        {
            _method = runtimeMethod;

            var genericArgs = new List<FuzzyType>();
            foreach (var genericArg in _method.GetMethodGenericArguments())
                genericArgs.Add(FuzzyType.FromRuntimeType(genericArg));
            GenericArguments = genericArgs.AsReadOnly();

            Target = target;
            ReturnValue = FuzzyType.FromRuntimeType(_method.ReturnType);
            Args = _method.GetParameters()
                .Select(param => FuzzyType.FromRuntimeType(param.ParameterType))
                .ToArray();

            // establishing links between typedef generic args and method's generic args
            // read more comments at FuzzyType.GetFieldOrProperty
            // see also comments to ReflectionHelper.GetGenericArgsMapping

            foreach (var pair in _method.GetGenericArgsMapping())
            {
                var typeDefArg = SelectGenericArg(pair.Value);
                var publicTypePointArgs = SelectGenericArg(pair.Key);
                publicTypePointArgs.IsIdenticalTo(typeDefArg);
            }

            // SomeMoreStuffInferred handlers for children just escalate the event
            // no need to process it since everything necessary is already done by links
            //
            // upd. currently noone cares about this event from this very class, 
            // but imo it's still important to comply to FuzzyMetadata contract

            Target.SomeMoreStuffInferred += (o, e) => FireSomeMoreStuffInferred();
            ReturnValue.SomeMoreStuffInferred += (o, e) => FireSomeMoreStuffInferred();
            Args.ForEach(arg => arg.SomeMoreStuffInferred += (o, e) => FireSomeMoreStuffInferred());

            // Register typepoints for debug -> 0 downtime in release, but immensely useful in debug mode
            var methodBinding = target.DebuggableParents.OfType<FuzzyMethodBinding>().SingleOrDefault();
            if (methodBinding != null)
            {
                this.RegDebuggableParent(methodBinding).SetDesc("alt");
                ReturnValue.RegDebuggableParent(this).SetDesc("ret");
                Args.ForEach((arg, i) => arg.RegDebuggableParent(this).SetDesc("arg" + i));
            }
        }