Reputation: 315
I want to inline a method with a switch
block.
If I use the return
in switch
statements, will it break the ParentMethod
execution?
void ParentMethod()
{
InliningMethod(myEnum.SomeValue);
//do some after inline for test case
Console.WriteLine("Will this have been writed?");
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void InliningMethod(MyEnum value)
{
switch(myEnum)
{
case MyEnum.SomeValue:
return; //will it have been moved in ParentMethod?
default: break;
}
//do some
}
Upvotes: 0
Views: 192
Reputation: 1
Inline method is just a style to write method in less code, it doesn't change execution principle. So, "return statement" inside inline method will not break parent method.
Upvotes: 0
Reputation: 77304
Inlining does not mean the code just gets copied over. The compiler will get it right, the return
only exits the method it's in, whether the compiler later inlines it or not.
Upvotes: 2