void DefineAnonymousStorey (EmitContext ec)
{
//
// Creates anonymous method storey
//
if (ec.CurrentAnonymousMethod != null && ec.CurrentAnonymousMethod.Storey != null) {
//
// Creates parent storey reference when hoisted this is accessible
//
if (am_storey.OriginalSourceBlock.Explicit.HasCapturedThis) {
ExplicitBlock parent = am_storey.OriginalSourceBlock.Explicit.Parent.Explicit;
//
// Hoisted this exists in top-level parent storey only
//
while (parent.am_storey == null || parent.am_storey.Parent is AnonymousMethodStorey)
parent = parent.Parent.Explicit;
am_storey.AddParentStoreyReference (ec, parent.am_storey);
}
am_storey.SetNestedStoryParent (ec.CurrentAnonymousMethod.Storey);
// TODO MemberCache: Review
am_storey.Mutator = ec.CurrentAnonymousMethod.Storey.Mutator;
}
am_storey.CreateType ();
if (am_storey.Mutator == null && ec.CurrentTypeParameters != null)
am_storey.Mutator = new TypeParameterMutator (ec.CurrentTypeParameters, am_storey.CurrentTypeParameters);
am_storey.DefineType ();
am_storey.ResolveTypeParameters ();
var ref_blocks = am_storey.ReferencesFromChildrenBlock;
if (ref_blocks != null) {
foreach (ExplicitBlock ref_block in ref_blocks) {
for (ExplicitBlock b = ref_block.Explicit; b.am_storey != am_storey; b = b.Parent.Explicit) {
if (b.am_storey != null) {
b.am_storey.AddParentStoreyReference (ec, am_storey);
// Stop propagation inside same top block
if (b.ParametersBlock.am_storey == ParametersBlock.am_storey)
break;
b = b.ParametersBlock;
}
b.HasCapturedVariable = true;
}
}
}
am_storey.Define ();
am_storey.Parent.PartialContainer.AddCompilerGeneratedClass (am_storey);
}