Ejemplo n.º 1
0
        void SetSafestActionForETWMethod(AnnotationStore annotations, MethodDefinition method, MethodAction desiredAction)
        {
            if (desiredAction == MethodAction.ConvertToThrow)
            {
                // If the desired action is a throw but the method has a void return let's just clear the body.
                // If the method does not have a void return, let's still insert a throw just in case.  stubbing the body could result in
                // an unexpected value being returned from the method which may lead to a more confusing error down the road
                if (method.ReturnType.MetadataType == MetadataType.Void)
                {
                    annotations.SetAction(method, MethodAction.ConvertToStub);
                    return;
                }

                if (!MethodBodyScanner.IsWorthConvertingToThrow(method.Body))
                {
                    return;
                }
            }

            annotations.SetAction(method, desiredAction);
        }
Ejemplo n.º 2
0
        void ExcludeEventSource(TypeDefinition type)
        {
            var annotations = Context.Annotations;

            foreach (var method in type.Methods)
            {
                if (annotations.GetAction(method) != MethodAction.Nothing)
                {
                    continue;
                }

                if (method.IsStatic)
                {
                    continue;
                }

                if (method.HasCustomAttributes)
                {
                    method.CustomAttributes.Clear();
                }

                if (method.IsDefaultConstructor())
                {
                    annotations.SetAction(method, MethodAction.ConvertToStub);
                    continue;
                }

                if (method.Name == "IsEnabled" || BCL.IsIDisposableImplementation(method) || method.IsFinalizer())
                {
                    annotations.SetAction(method, MethodAction.ConvertToStub);
                    continue;
                }

                if (MethodBodyScanner.IsWorthConvertingToThrow(method.Body))
                {
                    annotations.SetAction(method, MethodAction.ConvertToThrow);
                }
            }
        }
Ejemplo n.º 3
0
        void ExcludeMonoCollation(TypeDefinition type)
        {
            var annotations = Context.Annotations;


            switch (type.Name)
            {
            case "SimpleCollator":
                if (type.Namespace == "Mono.Globalization.Unicode")
                {
                    foreach (var method in type.Methods)
                    {
                        if (MethodBodyScanner.IsWorthConvertingToThrow(method.Body))
                        {
                            annotations.SetAction(method, MethodAction.ConvertToThrow);
                        }
                    }
                }

                break;

            case "CompareInfo":
                if (type.Namespace == "System.Globalization")
                {
                    foreach (var method in type.Methods)
                    {
                        if (method.Name == "get_UseManagedCollation")
                        {
                            annotations.SetAction(method, MethodAction.ConvertToStub);
                            break;
                        }
                    }
                }

                break;
            }
        }
Ejemplo n.º 4
0
        void ExcludeEventSourceImplementation(TypeDefinition type)
        {
            var annotations = Context.Annotations;

            foreach (var method in type.Methods)
            {
                if (annotations.GetAction(method) != MethodAction.Nothing)
                {
                    continue;
                }

                if (method.IsStatic)
                {
                    continue;
                }

                bool skip = false;
                if (method.HasCustomAttributes)
                {
                    if (!method.IsPrivate)
                    {
                        foreach (var attr in method.CustomAttributes)
                        {
                            //
                            // [NonEvent] attribute is commonly used to mark code which calls
                            // IsEnabled we could check for that as well to be more aggressive
                            // but for now I haven't seen such code in wild
                            //
                            if (BCL.EventTracingForWindows.IsNonEventAtribute(attr.AttributeType))
                            {
                                skip = true;
                                break;
                            }
                        }
                    }

                    method.CustomAttributes.Clear();
                }

                if (method.IsFinalizer())
                {
                    annotations.SetAction(method, MethodAction.ConvertToStub);
                    continue;
                }

                if (method.IsConstructor)
                {
                    //
                    // Skip when it cannot be easily stubbed
                    //
                    if (type.BaseType.HasDefaultConstructor())
                    {
                        annotations.SetAction(method, MethodAction.ConvertToStub);
                    }

                    continue;
                }

                if (!skip && MethodBodyScanner.IsWorthConvertingToThrow(method.Body))
                {
                    annotations.SetAction(method, MethodAction.ConvertToThrow);
                }
            }
        }