本文整理汇总了C#中Compiler.AllowInternal方法的典型用法代码示例。如果您正苦于以下问题:C# Compiler.AllowInternal方法的具体用法?C# Compiler.AllowInternal怎么用?C# Compiler.AllowInternal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Compiler
的用法示例。
在下文中一共展示了Compiler.AllowInternal方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitRead
protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
bool writeValue;
SanityCheck(ctx.Model, property, Tail, out writeValue, ctx.NonPublic, ctx.AllowInternal(property));
if (ExpectedType.IsValueType && valueFrom == null)
{
throw new InvalidOperationException("Attempt to mutate struct on the head of the stack; changes would be lost");
}
using (Compiler.Local loc = ctx.GetLocalWithValue(ExpectedType, valueFrom))
{
if (Tail.RequiresOldValue)
{
ctx.LoadAddress(loc, ExpectedType); // stack is: old-addr
ctx.LoadValue(property); // stack is: old-value
}
Type propertyType = property.PropertyType;
ctx.ReadNullCheckedTail(propertyType, Tail, null); // stack is [new-value]
if (writeValue)
{
using (Compiler.Local newVal = new Compiler.Local(ctx, property.PropertyType))
{
ctx.StoreValue(newVal); // stack is empty
Compiler.CodeLabel allDone = new Compiler.CodeLabel(); // <=== default structs
if (!propertyType.IsValueType)
{ // if the tail returns a null, intepret that as *no assign*
allDone = ctx.DefineLabel();
ctx.LoadValue(newVal); // stack is: new-value
ctx.BranchIfFalse(@allDone, true); // stack is empty
}
// assign the value
ctx.LoadAddress(loc, ExpectedType); // parent-addr
ctx.LoadValue(newVal); // parent-obj|new-value
if (shadowSetter == null)
{
ctx.StoreValue(property); // empty
}
else
{
ctx.EmitCall(shadowSetter); // empty
}
if (!propertyType.IsValueType)
{
ctx.MarkLabel(allDone);
}
}
}
else
{ // don't want return value; drop it if anything there
// stack is [new-value]
if (Tail.ReturnsValue) { ctx.DiscardValue(); }
}
}
}
示例2: EmitRead
protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
bool writeValue;
SanityCheck(ctx.Model, property, Tail, out writeValue, ctx.NonPublic, ctx.AllowInternal(property));
if (ExpectedType.IsValueType && valueFrom == null)
{
throw new InvalidOperationException("Attempt to mutate struct on the head of the stack; changes would be lost");
}
ctx.LoadAddress(valueFrom, ExpectedType); // stack is: old-addr
if (writeValue && Tail.RequiresOldValue)
{ // need to read and write
ctx.CopyValue();
}
// stack is: [old-addr]|old-addr
if (Tail.RequiresOldValue)
{
ctx.LoadValue(property); // stack is: [old-addr]|old-value
}
Type propertyType = property.PropertyType;
ctx.ReadNullCheckedTail(propertyType, Tail, null); // stack is [old-addr]|[new-value]
if (writeValue)
{
// stack is old-addr|new-value
Compiler.CodeLabel @skip = new Compiler.CodeLabel(), allDone = new Compiler.CodeLabel(); // <=== default structs
if (!propertyType.IsValueType)
{ // if the tail returns a null, intepret that as *no assign*
ctx.CopyValue(); // old-addr|new-value|new-value
@skip = ctx.DefineLabel();
allDone = ctx.DefineLabel();
ctx.BranchIfFalse(@skip, true); // old-addr|new-value
}
if (shadowSetter == null)
{
ctx.StoreValue(property);
}
else
{
ctx.EmitCall(shadowSetter);
}
if (!propertyType.IsValueType)
{
ctx.Branch(allDone, true);
ctx.MarkLabel(@skip); // old-addr|new-value
ctx.DiscardValue();
ctx.DiscardValue();
ctx.MarkLabel(allDone);
}
}
else
{ // don't want return value; drop it if anything there
// stack is [new-value]
if (Tail.ReturnsValue) { ctx.DiscardValue(); }
}
}