Statement UpdateValue(Property prop, Expression value) { var setArgs = new[] { _selfExpression, value }; if (prop.IsAttachedProperty()) { var setMethod = prop.GetSetMethodName(); return(new CallStaticMethod(setMethod, setArgs)); } if (_ctx.IsDeclaredInUx(prop)) { var nameString = new StringLiteral(prop.GetMemberName().Name); var nameSelector = new Instantiate(TypeName.Parse("Uno.UX.Selector"), nameString); var origin = new StringLiteral(null); // dummy origin return(new CallStaticMethod( StaticMemberName.Parse("Uno.UX.SimulatedProperties.Set"), _selfExpression, nameString, value, origin) + new CallStaticMethod( StaticMemberName.Parse("Uno.UX.PropertyObject.EmulatePropertyChanged"), _selfExpression, nameSelector, origin)); } return(new WriteProperty(_selfExpression, prop.GetMemberName(), value)); }
static Expression GetExpression(this GlobalReferenceValue grv, Context ctx) { if (grv.ResolvedValue != null) { return(grv.ResolvedValue.GetExpression(ctx)); } var globalName = new Variable(grv.ToLiteral()); if (ctx.Names.Contains(globalName)) { return(new ReadVariable(globalName)); } return(new ReadStaticField(StaticMemberName.Parse(grv.ToLiteral()))); }
public static Expression GetExpression(this Node node, Context ctx) { var resourceNode = node as ResourceRefNode; if (resourceNode != null) { var globalName = new Variable(resourceNode.StaticRefId); if (ctx.Names.Contains(globalName)) { return(new ReadVariable(globalName)); } return(new ReadStaticField(StaticMemberName.Parse(resourceNode.StaticRefId))); } return(new ReadVariable(ctx.Names[node])); }
static Expression GetPropertyExpression(Context ctx, Property property, Optional <Expression> maybeObj) { var propertyName = property.GetMemberName(); var propertyType = property.Facet.DataType.GetTypeName(); var vars = ctx.Names; var propObj = vars.GetUniqueName(); vars = vars.Reserve(propObj); var value = vars.GetUniqueName(); vars = vars.Reserve(value); var origin = vars.GetUniqueName(); vars = vars.Reserve(origin); if (ctx.IsDeclaredInUx(property)) { var setter = new Lambda( signature: Signature.Action(propObj, value, origin), localVariables: new BindVariable[0], statements: new Statement[] { new CallStaticMethod( StaticMemberName.Parse("Uno.UX.SimulatedProperties.Set"), new ReadVariable(propObj), new StringLiteral(propertyName.Name), new ReadVariable(value), new ReadVariable(origin)) }); var getter = new Lambda( signature: new Signature(List.Create(new Parameter(TypeName.Parse("object"), propObj)), propertyType), localVariables: new BindVariable[0], statements: new Statement[] { new Return( new CallStaticMethod( StaticMemberName.Parse("Uno.UX.SimulatedProperties.Get"), new ReadVariable(propObj), new StringLiteral(propertyName.Name))), }); var mp = (IMutableProperty)property.Facet; return(new Instantiate( UxPropertyType.Parameterize(propertyType), setter, getter, maybeObj.Or((Expression) new StringLiteral(null)), // the only null we've got is string new StringLiteral(propertyName.Name), new BooleanLiteral(mp.OriginSetterName != null) )); } else { var obj = maybeObj.Or((Expression) new ReadVariable(propObj)); var setter = new Lambda( signature: Signature.Action(propObj, value, origin), localVariables: new BindVariable[0], statements: new[] { property.SetValueStatement(ctx, obj, new ReadVariable(value), new ReadVariable(origin)) }); var getter = new Lambda( signature: new Signature(List.Create(new Parameter(TypeName.Parse("object"), propObj)), propertyType), localVariables: new BindVariable[0], statements: new[] { new Return(property.GetValueStatement(ctx, obj)) }); var mp = (IMutableProperty)property.Facet; return(new Instantiate( UxPropertyType.Parameterize(propertyType), setter, getter, maybeObj.Or((Expression) new StringLiteral(null)), // the only null we've got is string new StringLiteral(propertyName.Name), new BooleanLiteral(mp.OriginSetterName != null) )); } }