コード例 #1
0
        private void WeaveProperties(
            TypeDefinition clazz,
            IReadOnlyList <CrossCutterN.Aspect.Metadata.ICustomAttribute> classCustomAttributes,
            MethodWeaver methodWeaver,
            IClassWeavingStatisticsBuilder statistics)
        {
            foreach (var property in clazz.Properties)
            {
                var propertyInfo = property.Convert(classCustomAttributes);
                var plan         = planner.MakePlan(propertyInfo);
                if (!plan.IsEmpty())
                {
                    var propertyStatistics = StatisticsFactory.InitializePropertyWeavingRecord(property.Name, property.FullName);
                    var getterPlan         = plan.GetterPlan;
                    var getter             = property.GetMethod;
                    if (!getterPlan.IsEmpty() && getter != null)
                    {
                        methodWeaver.Weave(getter, getterPlan, property.Name, propertyStatistics.GetterContainer);
                    }

                    var setterPlan = plan.SetterPlan;
                    var setter     = property.SetMethod;
                    if (!setterPlan.IsEmpty() && setter != null)
                    {
                        methodWeaver.Weave(setter, setterPlan, property.Name, propertyStatistics.SetterContainer);
                    }

                    var propertyStatisticsFinished = propertyStatistics.Build();
                    if (propertyStatisticsFinished != null)
                    {
                        statistics.AddPropertyWeavingStatistics(propertyStatisticsFinished);
                    }
                }
            }
        }
コード例 #2
0
        private void WeaveMethods(
            TypeDefinition clazz,
            IReadOnlyList <CrossCutterN.Aspect.Metadata.ICustomAttribute> classCustomAttributes,
            MethodWeaver methodWeaver,
            IClassWeavingStatisticsBuilder statistics)
        {
            foreach (var method in clazz.Methods)
            {
                // methods without bodies can't be injected
                // property getter and setter will be handled in property phase
                if (!method.HasBody || IsPropertyMethod(method))
                {
                    continue;
                }

                var methodInfo = method.Convert(classCustomAttributes);
                var plan       = planner.MakePlan(methodInfo);
                if (!plan.IsEmpty())
                {
                    var methodStatistics = StatisticsFactory.InitializeMethodWeavingRecord(method.Name, method.FullName);
                    methodWeaver.Weave(method, plan, null, methodStatistics);
                    var methodStatisticsFinished = methodStatistics.Build();
                    if (methodStatisticsFinished != null)
                    {
                        statistics.AddMethodWeavingStatistics(methodStatisticsFinished);
                    }
                }
            }
        }