public object ConvertFrom(IValueContext context, CultureInfo culture, object value) { return new MemberSelector { MemberName = (string)value, }; }
public static void SetValue( object instance, MutableMember member, object value, IValueContext context) { var perspexProperty = FindPerspexProperty(instance, member); if (value is IBinding) { SetBinding(instance, member, perspexProperty, (IBinding)value); } else if (perspexProperty != null) { ((PerspexObject)instance).SetValue(perspexProperty, value); } else if (instance is Setter && member.Name == "Value") { // TODO: Make this more generic somehow. var setter = (Setter)instance; var targetType = setter.Property.PropertyType; var xamlType = member.TypeRepository.GetByType(targetType); var convertedValue = default(object); if (CommonValueConversion.TryConvert(value, xamlType, context, out convertedValue)) { SetClrProperty(instance, member, convertedValue); } } else { SetClrProperty(instance, member, value); } }
public bool TryConvert(object value, XamlType xamlType, IValueContext valueContext, out object result) { var targetType = xamlType.UnderlyingType; result = null; if (targetType.IsNullable()) { var typeInfo = Nullable.GetUnderlyingType(targetType); if (typeInfo != null && typeInfo.GetTypeInfo().IsEnum) { if (EnumExtensions.TryParse(typeInfo, value.ToString(), out result)) { return(true); } } } if (targetType.GetTypeInfo().IsEnum) { if (EnumExtensions.TryParse(targetType, value.ToString(), out result)) { return(true); } } return(false); }
public object ConvertFrom(IValueContext context, CultureInfo culture, object value) { return(new MemberSelector { MemberName = (string)value, }); }
public static void SetValue( object instance, MutableMember member, object value, IValueContext context) { var perspexProperty = FindPerspexProperty(instance, member); if (value is IBinding) { SetBinding(instance, member, perspexProperty, context, (IBinding)value); } else if (perspexProperty != null) { ((PerspexObject)instance).SetValue(perspexProperty, value); } else if (instance is Setter && member.Name == "Value") { // TODO: Make this more generic somehow. var setter = (Setter)instance; var targetType = setter.Property.PropertyType; var xamlType = member.TypeRepository.GetByType(targetType); var convertedValue = default(object); if (CommonValueConversion.TryConvert(value, xamlType, context, out convertedValue)) { SetClrProperty(instance, member, convertedValue); } } else { SetClrProperty(instance, member, value); } }
public IEnumerable<string> GetValues(IValueContext currentContext) { return GetValue(currentContext).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select( each => each.Trim()); }
private Uri GetBaseUri(IValueContext context) { object result; context.ParsingDictionary.TryGetValue("Uri", out result); return(result as Uri); }
private void setResults(ICanSetBackingValues targetObject, IValueContext context) { if (Count > 0) { foreach (var op in this) { switch (op.Operation) { case Operation.AddToCollection: if (op.Value is Scalar) { targetObject.AddValue(op.Value.GetValue(context)); } else { foreach (var i in op.Value.GetValues(context)) { targetObject.AddValue(i); } } break; case Operation.Assignment: case Operation.CollectionAssignment: targetObject.Reset(); foreach (var i in op.Value.GetValues(context)) { targetObject.AddValue(i); } break; } } } }
public ObjectAssembler(StackingLinkedList <Level> state, IRuntimeTypeSource typeSource, IInstanceLifeCycleListener listener, IValueContext context) { StateCommuter = new StateCommuter(state, typeSource, listener, context); LifecycleListener = listener; }
public ObjectAssembler(StackingLinkedList<Level> state, IRuntimeTypeSource typeSource, IInstanceLifeCycleListener listener, IValueContext context) { StateCommuter = new StateCommuter(state, typeSource, listener, context); LifecycleListener = listener; }
public object ConvertTo( IValueContext context, CultureInfo culture, object value, Type destinationType) { throw new NotImplementedException(); }
/// <inheritdoc/> public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType) { if (value is IHighlightingDefinition definition && destinationType == typeof(string)) { return(definition.Name); } return(null); }
public string GetValue(IValueContext currentContext) { if (Context == null) { return(_content); } return((currentContext ?? Context).ResolveMacrosInContext(_content, null, false)); }
/// <inheritdoc/> public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType) { if (value is TextLocation loc && destinationType == typeof(string)) { return(loc.Line.ToString(culture) + ";" + loc.Column.ToString(culture)); } throw new InvalidOperationException(); }
internal IEnumerable <string> GetValues(IValueContext currentContext) { if (_value == null) { _value = new Result(); setResults(_value, currentContext); } return(_value); }
public bool CanConvertTo(IValueContext context, Type destinationType) { if (destinationType == typeof(string) || destinationType == typeof(int)) { return(true); } return(false); }
public IEnumerable <string> GetValues(IValueContext currentContext) { if (Count == 0) { return(new [] { string.Empty }); } return(this.Select(each => (currentContext ?? Context).ResolveMacrosInContext(each.GetValue(currentContext ?? Context), null, false))); }
public object ConvertFrom(IValueContext context, CultureInfo culture, object value) { if (value is string) { return value; } return null; }
public bool CanConvertTo(IValueContext context, Type destinationType) { if (destinationType == typeof(string) || destinationType == typeof(int)) { return true; } return false; }
public object ConvertFrom(IValueContext context, CultureInfo culture, object value) { if (value is string) { return(value); } return(null); }
public IEnumerable <string> GetValues(IValueContext currentContext) { // need to take all the parameters, and resolve each of them into a collection // then matrix out a final collection by looping thru each of the values and // processing the template. // then, should return the collection of generated values var t = Template.Select(each => (string)each.Data.ToString()).Aggregate((c, e) => c + e); return(Permutations.Select(each => (currentContext ?? Context).ResolveMacrosInContext(t, each, false))); }
/// <inheritdoc/> public object ConvertFrom(IValueContext context, CultureInfo culture, object value) { var s = value as string; var parts = s?.Split(';', ','); if (parts?.Length == 2) { return(new TextLocation(int.Parse(parts[0], culture), int.Parse(parts[1], culture))); } throw new InvalidOperationException(); }
public virtual void SetValue(object instance, object value, IValueContext valueContext) { if (ValueSetter.IsStatic) { ValueSetter.Invoke(null, new[] { instance, value }); } else { member.Setter.Invoke(instance, new[] { value }); } }
public object ConvertFrom(IValueContext context, CultureInfo culture, object value) { string strValue = (string)value; string[] pointStrs = strValue.Split(new[] { ' ', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); var result = new List<Point>(pointStrs.Length); foreach (var pointStr in pointStrs) { result.Add(Point.Parse(pointStr, culture)); } return result; }
public CompareEval(IValueContext Context, DbValue val1, DbValue val2) : base(Context) { this.val1 = val1; this.val2 = val2; List <DbValue> argsbuf = new List <DbValue>(2); argsbuf.Add(val1); argsbuf.Add(val2); args = new DbFunctionArguments(argsbuf); }
private IEnumerable <string> LookupPropertyForMacro(string valuename, IValueContext context) { var v = GetProperty(ResolveAlias(valuename), false); if (v == null || v._map is ElementMap) { return(null); } return(v.Values); }
public StateCommuter(StackingLinkedList <Level> stack, IRuntimeTypeSource typeSource, IInstanceLifeCycleListener lifecycleListener, IValueContext valueContext) { Guard.ThrowIfNull(stack, nameof(stack)); Guard.ThrowIfNull(typeSource, nameof(typeSource)); Stack = stack; this.lifecycleListener = lifecycleListener; this.valueContext = valueContext; }
public string GetValue(IValueContext currentContext) { switch (Count) { case 0: return(string.Empty); case 1: return(this[0].GetValue(currentContext ?? Context)); } return(this.Aggregate("", (current, each) => current + ", " + each.GetValue(currentContext ?? Context)).Trim(',', ' ')); }
public StateCommuter(StackingLinkedList<Level> stack, IRuntimeTypeSource typeSource, IInstanceLifeCycleListener lifecycleListener, IValueContext valueContext) { Guard.ThrowIfNull(stack, nameof(stack)); Guard.ThrowIfNull(typeSource, nameof(typeSource)); Stack = stack; this.lifecycleListener = lifecycleListener; this.valueContext = valueContext; }
public object ConvertFrom(IValueContext context, CultureInfo culture, object value) { var valueStr = (string)value; if (!valueStr.Contains(":")) { // shorthand seconds format (ie. "0.25") var secs = double.Parse(valueStr, CultureInfo.InvariantCulture); return TimeSpan.FromSeconds(secs); } return TimeSpan.Parse(valueStr); }
public static bool TryConvert(object value, XamlType targetType, IValueContext valueContext, out object result) { result = null; foreach (var step in ValueConverters) { if (step.TryConvert(value, targetType, valueContext, out result)) { return true; } } return false; }
public ObjectAssembler(IRuntimeTypeSource typeSource, IValueContext valueContext, Settings settings = null) : this(new StackingLinkedList<Level>(), typeSource, GetLifecycleListener(settings), valueContext) { this.valueContext = valueContext; Guard.ThrowIfNull(typeSource, nameof(typeSource)); TypeSource = typeSource; StateCommuter.RaiseLevel(); rootInstance = settings?.RootInstance; var rootInstanceType = rootInstance?.GetType(); rootInstanceXamlType = rootInstanceType != null ? TypeSource.GetByType(rootInstanceType) : null; }
public object ConvertFrom(IValueContext context, CultureInfo culture, object value) { string strValue = (string)value; string[] pointStrs = strValue.Split(new[] { ' ', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); var result = new List <Point>(pointStrs.Length); foreach (var pointStr in pointStrs) { result.Add(Point.Parse(pointStr, culture)); } return(result); }
public static bool TryConvert(object value, XamlType targetType, IValueContext valueContext, out object result) { result = null; foreach (var step in ValueConverters) { if (step.TryConvert(value, targetType, valueContext, out result)) { return(true); } } return(false); }
public object ConvertFrom(IValueContext context, CultureInfo culture, object value) { var valueStr = (string)value; if (!valueStr.Contains(":")) { // shorthand seconds format (ie. "0.25") var secs = double.Parse(valueStr, CultureInfo.InvariantCulture); return(TimeSpan.FromSeconds(secs)); } return(TimeSpan.Parse(valueStr)); }
public object ConvertFrom(IValueContext context, CultureInfo culture, object value) { FontWeight result; if (Enum.TryParse(value as string, out result)) { return result; } else { throw new ArgumentException("unable to convert parameter to FontWeight"); } }
public object ConvertFrom(IValueContext context, CultureInfo culture, object value) { FontWeight result; if (Enum.TryParse(value as string, out result)) { return(result); } else { throw new ArgumentException("unable to convert parameter to FontWeight"); } }
public object ConvertFrom(IValueContext context, CultureInfo culture, object value) { var path = value as string; if (path != null) { return CreateIconFromPath(context, path); } var bitmap = value as IBitmap; if (bitmap != null) { return new WindowIcon(bitmap); } throw new NotSupportedException(); }
public string GetValue(IValueContext currentContext) { var v = GetValues(currentContext).ToArray(); switch (v.Length) { case 0: return(string.Empty); case 1: return(this[0].GetValue(currentContext)); } return(v.Aggregate("", (current, each) => current + ", " + each).Trim(',', ' ')); }
public ObjectAssembler(IRuntimeTypeSource typeSource, IValueContext valueContext, Settings settings = null) : this(new StackingLinkedList <Level>(), typeSource, GetLifecycleListener(settings), valueContext) { this.valueContext = valueContext; Guard.ThrowIfNull(typeSource, nameof(typeSource)); TypeSource = typeSource; StateCommuter.RaiseLevel(); rootInstance = settings?.RootInstance; var rootInstanceType = rootInstance?.GetType(); rootInstanceXamlType = rootInstanceType != null?TypeSource.GetByType(rootInstanceType) : null; }
public object ConvertFrom(IValueContext context, CultureInfo culture, object value) { var uri = new Uri((string)value, UriKind.RelativeOrAbsolute); var scheme = uri.IsAbsoluteUri ? uri.Scheme : "file"; switch (scheme) { case "file": return new Bitmap((string)value); default: var assets = PerspexLocator.Current.GetService<IAssetLoader>(); return new Bitmap(assets.Open(uri)); } }
private static void SetBinding( object instance, MutableMember member, PerspexProperty property, IValueContext context, IBinding binding) { if (!(AssignBinding(instance, member, binding) || ApplyBinding(instance, property, context, binding))) { throw new InvalidOperationException( $"Cannot assign to '{member.Name}' on '{instance.GetType()}"); } }
private static void SetBinding( object instance, MutableMember member, AvaloniaProperty property, IValueContext context, IBinding binding) { if (!(AssignBinding(instance, member, binding) || ApplyBinding(instance, property, context, binding))) { throw new InvalidOperationException( $"Cannot assign to '{member.Name}' on '{instance.GetType()}"); } }
private static bool ApplyBinding( object instance, AvaloniaProperty property, IValueContext context, IBinding binding) { if (property == null) { return(false); } var control = instance as IControl; if (control != null) { if (property != Control.DataContextProperty) { DelayedBinding.Add(control, property, binding); } else { control.Bind(property, binding); } } else { // The target is not a control, so we need to find an anchor that will let us look // up named controls and style resources. First look for the closest IControl in // the TopDownValueContext. object anchor = context.TopDownValueContext.StoredInstances .Select(x => x.Instance) .OfType <IControl>() .LastOrDefault(); // If a control was not found, then try to find the highest-level style as the XAML // file could be a XAML file containing only styles. if (anchor == null) { anchor = context.TopDownValueContext.StoredInstances .Select(x => x.Instance) .OfType <IStyle>() .FirstOrDefault(); } ((IAvaloniaObject)instance).Bind(property, binding, anchor); } return(true); }
private WindowIcon CreateIconFromPath(IValueContext context, string path) { var uri = new Uri(path, UriKind.RelativeOrAbsolute); var baseUri = GetBaseUri(context); var scheme = uri.IsAbsoluteUri ? uri.Scheme : "file"; switch (scheme) { case "file": return new WindowIcon(path); default: var assets = AvaloniaLocator.Current.GetService<IAssetLoader>(); return new WindowIcon(assets.Open(uri, baseUri)); } }
public object ConvertFrom(IValueContext context, CultureInfo culture, object value) { var uri = new Uri((string)value, UriKind.RelativeOrAbsolute); var scheme = uri.IsAbsoluteUri ? uri.Scheme : "file"; switch (scheme) { case "file": return(new Bitmap((string)value)); default: var assets = PerspexLocator.Current.GetService <IAssetLoader>(); return(new Bitmap(assets.Open(uri))); } }
public object ConvertFrom(IValueContext context, CultureInfo culture, object value) { if (culture == null) { throw new ArgumentNullException("culture"); } if (value == null) { throw new ArgumentNullException("value"); } DateTimeFormatInfo dateTimeFormatInfo = (DateTimeFormatInfo)culture.GetFormat(typeof(DateTimeFormatInfo)); DateTime d = DateTime.ParseExact(value.ToString(), dateTimeFormatInfo.ShortDatePattern, culture); return d; }
public Scalar(ObjectNode context, IEnumerable<Token> singleExpression, string sourceFile) { var item = singleExpression.ToList(); // trim off whitespace while (item.Count > 0 && item[0].IsWhitespaceOrComment) { item.RemoveAt(0); } _sourceLocations = new[] { new SourceLocation(item.FirstOrDefault(), sourceFile) }; while (item.Count > 0 && item[item.Count - 1].IsWhitespaceOrComment) { item.RemoveAt(item.Count - 1); } // may have to expand out certian types of tokens here. _content = item.Aggregate("", (current, each) => current + each.Data); Context = context; }
public object ConvertFrom(IValueContext context, CultureInfo culture, object value) { var s = (string)value; string typeName; string propertyName; Type type; ParseProperty(s, out typeName, out propertyName); if (typeName == null) { var styleType = context.TypeRepository.GetByType(typeof(Style)); var style = (Style)context.TopDownValueContext.GetLastInstance(styleType); type = style.Selector.TargetType; if (type == null) { throw new ParseException( "Could not determine the target type. Please fully qualify the property name."); } } else { type = context.TypeRepository.GetByQualifiedName(typeName)?.UnderlyingType; if (type == null) { throw new ParseException($"Could not find type '{typeName}'."); } } // First look for non-attached property on the type and then look for an attached property. var property = PerspexPropertyRegistry.Instance.FindRegistered(type, s) ?? PerspexPropertyRegistry.Instance.GetAttached(type) .FirstOrDefault(x => x.Name == propertyName); if (property == null) { throw new ParseException( $"Could not find PerspexProperty '{type.Name}.{propertyName}'."); } return property; }
public bool TryConvert(object value, XamlType targetType, IValueContext valueContext, out object result) { result = null; var typeConverter = targetType.TypeConverter; if (typeConverter != null) { if (typeConverter.CanConvertFrom(valueContext, value.GetType())) { { result = typeConverter.ConvertFrom(valueContext, CultureInfo.InvariantCulture, value); return true; } } } return false; }
public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == null) { throw new ArgumentNullException("destinationType"); } if (culture == null) { throw new ArgumentNullException("culture"); } DateTime? d = value as DateTime?; if (!d.HasValue || destinationType != typeof(string)) { throw new NotSupportedException(); } DateTimeFormatInfo dateTimeFormatInfo = (DateTimeFormatInfo)culture.GetFormat(typeof(DateTimeFormatInfo)); return d.Value.ToString(dateTimeFormatInfo.ShortDatePattern, culture); }
public override void SetValue(object instance, object value, IValueContext valueContext) { if (member.Name == "Value" && instance is Setter) { var setter = (Setter) instance; var targetType = setter.Property.PropertyType; var xamlType = member.TypeRepository.GetByType(targetType); object compatibleValue; CommonValueConversion.TryConvert(value, xamlType, valueContext, out compatibleValue); base.SetValue(instance, compatibleValue, valueContext); } else { if (!TrySetDependencyProperty(instance, value)) { base.SetValue(instance, value, valueContext); } } }
public object ConvertFrom(IValueContext context, CultureInfo culture, object value) { var str = value as string; if (value is int) { return Convert.ToInt32(value, CultureInfo.InvariantCulture); } if (value is long) { return Convert.ToInt32(value, CultureInfo.InvariantCulture); } else if (str != null) { long v; if (long.TryParse(str, NumberStyles.Integer, CultureInfo.InvariantCulture, out v)) { return (int)v; } } throw new InvalidOperationException(); }
public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType) { if (value == null) { return null; } if (destinationType == typeof(int)) { var str = value as string; if (str != null) { int n; if (int.TryParse(str, NumberStyles.Integer, CultureInfo.InvariantCulture, out n)) { return n; } return null; } } if (destinationType == typeof(double)) { var str = value as string; if (str != null) { double n; if (double.TryParse(str, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out n)) { return n; } return null; } } return value.ToString(); }
public object ConvertFrom(IValueContext context, CultureInfo culture, object value) { return new ColumnDefinitions((string)value); }
public bool CanConvertTo(IValueContext context, Type destinationType) { return false; }
public bool CanConvertFrom(IValueContext context, Type sourceType) { return sourceType == typeof(string); }
private Uri GetBaseUri(IValueContext context) { object result; context.ParsingDictionary.TryGetValue("Uri", out result); return result as Uri; }