Famaritana raha fomba fiantsoana fomba iray ao amin'ny fiangonana hafa misy fanambarana vaovao ary mifamadika amin'izany

Te-hanoratra fitsipika tsy hahomby aho raha misy fizarana zavatra atao ao anatin'ny fomba rehetra antsoina amin'ny fomba voamarika amin'ny toetra manokana.

Niasa aho hatramin'izao, amin'ny alàlan'ny famerenana ny fomba rehetra miantso ny fombako hanamarinana amin'ny fampiasana CallGraph.CallersFor () , hahitana raha misy amin'ireo fomba amam-panahy ireo no manana ny toetrany.

Mety ho an'ny manamarina ny fomba amam-panao ao anatin'ny fiangonana mitovy amin'ny fomba tokony hojerena, na izany aza ny famakiana an-tserasera, hita fa indray mandeha CallGraph.CallersFor () dia nijery ireo fivoriambe rehetra, saingy tsy izany ankehitriny.

Fanontaniana: Misy fomba ve hahazoana lisitry ny fomba fiantsoana fomba iray nomena, ao anatin'izany ireo ao amin'ny fivoriambe hafa?

Valiny hafa: Raha tsy azo atao ny voalaza etsy ambony, ahoana no hataoko rehefa mandeha fomba izay iantsoana fomba iray, anisan'izany ireo ao amin'ny fivoriambe hafa.


Ohatra:

-----In Assembly A

public class ClassA
{
    public MethodA()
    {
        MethodB();
    }

    public MethodB()
    {
        object o = new object(); // Allocation i want to break the rule
        // Currently my rule walks up the call tree,
        // checking for a calling method with the NoAllocationsAllowed attribute.
        // Problem is, because of the different assemblies,
        // it can't go from ClassA.MethodA to ClassB.MethodB.
    }
}


----In Assembly B

public var ClassAInstance = new ClassA();

public class ClassB
{
    [NoAllocationsAllowed] // Attribute that kicks off the rule-checking.
    public MethodA()
    {
        MethodB();
    }

    public MethodB()
    {
        ClassAInstance.MethodA();
    }
}

Tsy dia mi aho nd amin'izay itateran'ny lalàna ny lesoka, amin'izao fotoana izao dia efa ampy ny lesoka.

8
задан Cœur 9 June 2018 в 16:17
поделиться