public AtomGetterMethodWeaver(AtomWeaverV2 weaver, PropertyDefinition property, FieldReference atomField, AtomOptions options) { _atomField = atomField; _options = options; _property = property; _atomDebugName = weaver._generateDebugNames ? $"{property.DeclaringType.FullName}::{property.Name}" : null; _resultVariable = new VariableDefinition(property.PropertyType); _nullCheckEndInstruction = Instruction.Create(OpCodes.Nop); _directEvalEndInstruction = Instruction.Create(OpCodes.Nop); _loadResultInstruction = Instruction.Create(OpCodes.Ldloc, _resultVariable); var propertyType = property.PropertyType; _atomCreateMethod = Helpers.MakeGenericMethod(weaver._atomCreateMethod, propertyType); _atomPullCtorMethod = Helpers.MakeHostInstanceGeneric(weaver._atomPullCtorMethod, propertyType); _tryEnterMethod = Helpers.MakeHostInstanceGeneric(weaver._atomDirectEvalMethod, propertyType); _atomGetMethod = Helpers.MakeHostInstanceGeneric(weaver._atomGetValueMethod, propertyType); var body = property.GetMethod.Body; body.InitLocals = true; body.Variables.Add(_resultVariable); }
internal AtomBase(Lifetime lifetime, string debugName, AtomOptions options) { this.debugName = debugName; this.options = options; lifetime.Register(this); }
public bool Weave(PropertyDefinition property) { var atomAttribute = Helpers.GetCustomAttribute <AtomAttribute>(property); if (atomAttribute == null) { return(false); } if (!property.DeclaringType.IsClass || property.DeclaringType.IsValueType) { _diagnosticMessages.Add(UserError.AtomAttributeCanBeUsedOnlyOnClassMembers(property)); return(false); } if (!property.DeclaringType.IsInterfaceImplemented(_lifetimeScopeInterfaceType)) { _diagnosticMessages.Add(UserError.AtomAttributeCanBeUsedOnlyOnLifetimeScope(property)); return(false); } if (property.GetMethod == null) { _diagnosticMessages.Add(UserError.CannotUseAtomAttributeOnSetOnlyProperty(property)); return(false); } if (property.GetMethod.IsStatic) { _diagnosticMessages.Add(UserError.CannotUseAtomAttributeOnStaticProperty(property)); return(false); } if (property.GetMethod.IsAbstract) { _diagnosticMessages.Add(UserError.CannotUseAtomAttributeOnAbstractProperty(property)); return(false); } var atomOptions = new AtomOptions { KeepAlive = atomAttribute.GetArgumentValueOrDefault(KeepAliveParameterName, false), }; property.CustomAttributes.Remove(atomAttribute); FixAutoPropertyBackingField(property); var atomField = CreateAtomField(property); property.DeclaringType.Fields.Add(atomField); new AtomGetterMethodWeaver(this, property, atomField, atomOptions).Weave(); if (property.SetMethod != null) { new AtomSetterMethodWeaver(this, property, atomField).Weave(); } return(true); }
public static bool Has(this AtomOptions keys, in AtomOptions flag)