Example #1
0
    public override void Execute()
    {
        if (Environment.GetEnvironmentVariable("NOBSERVABLE_DEBUG_ATTACH") == "1")
        {
            LogError($"Attach debugger to {Process.GetCurrentProcess().Id}");
            while (!Debugger.IsAttached)
            {
                Thread.Sleep(1000);
            }
        }

        var context = new WeavingContext(TypeSystem, this, ModuleDefinition);

        foreach (var t in AllTypes(ModuleDefinition.Types))
        {
            var observeAll = t.CustomAttributes.Any(ca => ca.AttributeType.AreEqual(context.ObservableAttributeReference));
            foreach (var p in t.Properties)
            {
                var getter = p.GetMethod;
                var setter = p.SetMethod;
                if (getter == null || setter == null)
                {
                    continue;
                }
                if (getter.IsStatic || setter.IsStatic)
                {
                    continue;
                }
                if (observeAll ||
                    p.CustomAttributes.Any(ca => ca.AttributeType.AreEqual(context.ObservableAttributeReference)))
                {
                    IlInjector.InstrumentProperty(context, p);
                }
            }

            if (context.BlazorHelperAsm != null && IsBlazorComponent(t))
            {
                if (t.Interfaces.Any(iface => iface.InterfaceType.FullName == "NObservable.Blazor.IObserverComponent"))
                {
                    IlInjector.InstrumentBlazorComponent(context, t);
                }
            }
        }
    }
Example #2
0
    public override void Execute()
    {
        if (Environment.GetEnvironmentVariable("NOBSERVABLE_DEBUG_ATTACH") == "1")
        {
            LogError($"Attach debugger to {Process.GetCurrentProcess().Id}");
            while (!Debugger.IsAttached)
            {
                Thread.Sleep(1000);
            }
        }

        var context = new WeavingContext(TypeSystem, ModuleDefinition);

        foreach (var t in AllTypes(ModuleDefinition.Types))
        {
            var            observeAll = t.CustomAttributes.Any(ca => ca.AttributeType.AreEqual(context.ObservableAttributeReference));
            FieldReference field      = null;

            if (t.Name.StartsWith("BasicEngineTest"))
            {
                var set = t.GetMethods().First(m => m.Name == "Wtf");
                Console.WriteLine();
            }
            foreach (var p in t.Properties)
            {
                var getter = p.GetMethod;
                var setter = p.SetMethod;
                if (getter == null || setter == null)
                {
                    continue;
                }
                if (getter.IsStatic || setter.IsStatic)
                {
                    continue;
                }
                if (observeAll ||
                    p.CustomAttributes.Any(ca => ca.AttributeType.AreEqual(context.ObservableAttributeReference)))
                {
                    IlInjector.InstrumentProperty(context, p);
                }
            }
        }
    }