protected override void MarkMethodBody(MethodBody body) { if (!OptimizerContext.IsEnabled(body.Method)) { base.MarkMethodBody(body); return; } var debug = OptimizerContext.GetDebugLevel(body.Method); if (debug > 0) { OptimizerContext.LogMessage(MessageImportance.Normal, $"MARK BODY: {body.Method}"); OptimizerContext.Debug(); } var scanner = BasicBlockScanner.Scan(OptimizerContext, body.Method); if (scanner == null) { OptimizerContext.LogDebug($"BB SCAN FAILED: {body.Method}"); base.MarkMethodBody(body); return; } if (scanner == null || !scanner.FoundConditionals) { base.MarkMethodBody(body); return; } if (debug > 0) { OptimizerContext.LogDebug($"MARK BODY - CONDITIONAL: {body.Method}"); } scanner.RewriteConditionals(); base.MarkMethodBody(body); }
void ProcessProperty(PropertyDefinition property) { if (property.SetMethod != null) { return; } if (property.GetMethod == null || !property.GetMethod.HasBody) { return; } if (property.PropertyType.MetadataType != MetadataType.Boolean) { return; } var scanner = BasicBlockScanner.Scan(Context, property.GetMethod); if (scanner == null || !scanner.FoundConditionals) { return; } Context.LogMessage(MessageImportance.Normal, $"Found conditional property: {property}"); scanner.RewriteConditionals(); if (!CecilHelper.IsConstantLoad(scanner.Body, out var value)) { Context.LogMessage(MessageImportance.High, $"Property `{property}` uses conditionals, but does not return a constant."); return; } Context.MarkAsConstantMethod(property.GetMethod, value ? ConstantValue.True : ConstantValue.False); Context.Debug(); }