12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #if FEAT_COMPILER
- using System;
- using System.Reflection.Emit;
- namespace ProtoBuf.Compiler
- {
- internal sealed class Local : IDisposable
- {
-
- private LocalBuilder value;
- private readonly Type type;
- private CompilerContext ctx;
- private Local(LocalBuilder value, Type type)
- {
- this.value = value;
- this.type = type;
- }
- internal Local(CompilerContext ctx, Type type)
- {
- this.ctx = ctx;
- if (ctx != null) { value = ctx.GetFromPool(type); }
- this.type = type;
- }
- internal LocalBuilder Value => value ?? throw new ObjectDisposedException(GetType().Name);
- public Type Type => type;
- public Local AsCopy()
- {
- if (ctx == null) return this;
- return new Local(value, this.type);
- }
-
- public void Dispose()
- {
- if (ctx != null)
- {
-
-
- ctx.ReleaseToPool(value);
- value = null;
- ctx = null;
- }
- }
- internal bool IsSame(Local other)
- {
- if((object)this == (object)other) return true;
- object ourVal = value;
- return other != null && ourVal == (object)(other.value);
- }
- }
- }
- #endif
|