示例#1
0
        private void InstrumentType(TypeDefinition type)
        {
            var methods = type.GetMethods();

            foreach (var method in methods)
            {
                MethodDefinition actualMethod = method;
                if (InstrumentationHelper.IsLocalMethod(method.Name))
                {
                    actualMethod = methods.FirstOrDefault(m => m.Name == method.Name.Split('>')[0].Substring(1)) ?? method;
                }

                if (!actualMethod.CustomAttributes.Any(IsExcludeAttribute))
                {
                    InstrumentMethod(method);
                }
            }

            var ctors = type.GetConstructors();

            foreach (var ctor in ctors)
            {
                if (!ctor.CustomAttributes.Any(IsExcludeAttribute))
                {
                    InstrumentMethod(ctor);
                }
            }
        }
示例#2
0
        private void InstrumentType(TypeDefinition type)
        {
            var methods = type.GetMethods();

            foreach (var method in methods)
            {
                MethodDefinition actualMethod = method;
                IEnumerable <CustomAttribute> customAttributes = method.CustomAttributes;
                if (InstrumentationHelper.IsLocalMethod(method.Name))
                {
                    actualMethod = methods.FirstOrDefault(m => m.Name == method.Name.Split('>')[0].Substring(1)) ?? method;
                }

                if (actualMethod.IsGetter || actualMethod.IsSetter)
                {
                    PropertyDefinition prop = type.Properties.FirstOrDefault(p => p.GetMethod.FullName.Equals(actualMethod.FullName));
                    if (prop?.HasCustomAttributes == true)
                    {
                        customAttributes = customAttributes.Union(prop.CustomAttributes);
                    }
                }

                if (!customAttributes.Any(IsExcludeAttribute))
                {
                    InstrumentMethod(method);
                }
            }

            var ctors = type.GetConstructors();

            foreach (var ctor in ctors)
            {
                if (!ctor.CustomAttributes.Any(IsExcludeAttribute))
                {
                    InstrumentMethod(ctor);
                }
            }
        }