/// <summary> /// Evaluates whether the condition is true for the specified object. /// </summary> /// <param name="uv">The Ultraviolet context.</param> /// <param name="dobj">The object against which to evaluate the trigger condition.</param> /// <returns><see langword="true"/> if the condition is true for the specified object; otherwise, <see langword="false"/>.</returns> internal Boolean Evaluate(UltravioletContext uv, DependencyObject dobj) { Contract.Require(uv, nameof(uv)); Contract.Require(dobj, nameof(dobj)); var dprop = DependencyProperty.FindByStylingName(uv, dobj, propertyName.Owner, propertyName.Name); if (dprop == null) { return(false); } var refvalCacheType = (propertyValueCachhe == null) ? null : propertyValueCachhe.GetType(); if (refvalCacheType == null || (refvalCacheType != dprop.PropertyType && refvalCacheType != dprop.UnderlyingType)) { propertyValueCachhe = ObjectResolver.FromString( propertyValue.Value, dprop.PropertyType, propertyValue.Culture); } var comparison = TriggerComparisonCache.Get(dprop.PropertyType, op); if (comparison == null) { throw new InvalidOperationException(PresentationStrings.InvalidTriggerComparison.Format(propertyName, op, dprop.PropertyType)); } return(comparison(dobj, dprop, propertyValueCachhe)); }
/// <summary> /// Gets the value which is set by this action. /// </summary> /// <typeparam name="T">The type of value to retrieve.</typeparam> /// <returns>The value which is set by this action.</returns> public T GetValue <T>() { if (valueCache == null || valueCache.GetType() != typeof(T)) { valueCache = ObjectResolver.FromString(propertyValue.Value, typeof(T), propertyValue.Culture); } return((T)valueCache); }
/// <summary> /// Gets a <see cref="System.ComponentModel.TypeConverter.StandardValuesCollection"/> containing the object references defined by the specified data object registry. /// </summary> /// <returns>The <see cref="System.ComponentModel.TypeConverter.StandardValuesCollection"/> which was created.</returns> private static StandardValuesCollection GetStandardValuesForRegistry() { var registry = DataObjectRegistries.Get <T>(); var keys = registry.Select(x => String.Format("@{0}:{1}", registry.ReferenceResolutionName, x.Key)); var references = (from k in keys select(ResolvedDataObjectReference) ObjectResolver.FromString(k, typeof(ResolvedDataObjectReference))).ToList(); references.Insert(0, ResolvedDataObjectReference.Invalid); return(new StandardValuesCollection(references)); }
/// <inheritdoc/> public override Object Instantiate(UltravioletContext uv, UvmlInstantiationContext context) { if (String.Equals(Literal, "{{null}}", StringComparison.Ordinal)) { return(Type.IsValueType ? Activator.CreateInstance(Type) : null); } if (typeof(IInputElement).IsAssignableFrom(Type)) { return(new UvmlElementReference(Literal)); } return(ObjectResolver.FromString(Literal, Type, Culture)); }
/// <inheritdoc/> public override TextTableLayout Process(ContentManager manager, IContentProcessorMetadata metadata, XDocument input) { var layoutDesc = new TextTableLayoutDescription(); layoutDesc.Width = (Int32?)input.Root.Attribute("Width"); layoutDesc.Height = (Int32?)input.Root.Attribute("Height"); var rowElements = input.Root.Elements("Row"); if (rowElements.Any()) { var rowDescCollection = new List <TextTableLayoutRowDescription>(); layoutDesc.Rows = rowDescCollection; foreach (var rowElement in rowElements) { var rowDesc = new TextTableLayoutRowDescription(); rowDescCollection.Add(rowDesc); var cellElements = rowElement.Elements("Cell"); if (cellElements.Any()) { var cellDescCollection = new List <TextTableLayoutCellDescription>(); rowDesc.Cells = cellDescCollection; foreach (var cellElement in cellElements) { var cellDesc = new TextTableLayoutCellDescription(); cellDescCollection.Add(cellDesc); cellDesc.TextFlags = (TextFlags)ObjectResolver.FromString( (String)cellElement.Attribute("TextFlags") ?? String.Empty, typeof(TextFlags)); cellDesc.Text = cellElement.Value; cellDesc.Format = (String)cellElement.Attribute("Format"); cellDesc.Binding = (String)cellElement.Attribute("Binding"); cellDesc.Width = (Int32?)cellElement.Attribute("Width"); cellDesc.Height = (Int32?)cellElement.Attribute("Height"); } } } } return(new TextTableLayout(layoutDesc)); }
/// <summary> /// Converts a string to a value to be applied to a styled dependency property. /// </summary> /// <param name="style">The style to resolve to a value.</param> /// <param name="type">The type of object to create.</param> /// <param name="provider">An object that supplies culture-specific formatting information.</param> /// <returns>The object that was created.</returns> private static Object ResolveStyledValue(UvssRule style, Type type, IFormatProvider provider) { if (style.CachedResolvedValue != null && style.CachedResolvedValue.GetType() == type) { return(style.CachedResolvedValue); } var value = style.Value.Trim(); if (value == "null") { return(type.IsValueType ? Activator.CreateInstance(type) : null); } var resolvedValue = ObjectResolver.FromString(value, type, provider, true); style.CachedResolvedValue = resolvedValue; return(resolvedValue); }
public static SourcedCursor Parse(String str, IFormatProvider provider) { var source = AssetSource.Global; if (str.EndsWith(" local")) { source = AssetSource.Local; str = str.Substring(0, str.Length - " local".Length); } else if (str.EndsWith(" global")) { source = AssetSource.Global; str = str.Substring(0, str.Length - " global".Length); } var asset = (SourcedCursorResource)ObjectResolver.FromString(str.Trim(), typeof(SourcedCursorResource), provider); return(new SourcedCursor(asset, source)); }
/// <summary> /// Gets the value of the specified argument. /// </summary> /// <param name="name">The name of the argument for which to retrieve a value.</param> /// <param name="value">The value of the specified argument.</param> /// <returns><see langword="true"/> if the specified argument exists and has a value; otherwise, <see langword="false"/>.</returns> public Boolean TryGetArgument <T>(String name, out T value) { Contract.RequireNotEmpty(name, nameof(name)); String strval; if (!arguments.TryGetValue(name.ToLowerInvariant(), out strval)) { value = default(T); return(false); } if (strval == null) { value = default(T); return(false); } value = (T)ObjectResolver.FromString(strval, typeof(T)); return(true); }
/// <summary> /// Converts the string representation of a <see cref="SourcedResource{T}"/> to an object instance. /// A return value indicates whether the conversion succeeded. /// </summary> /// <param name="s">The string to convert.</param> /// <param name="style">A set of <see cref="NumberStyles"/> values indicating which elements are present in <paramref name="s"/>.</param> /// <param name="provider">A format provider that provides culture-specific formatting information.</param> /// <param name="v">The converted value.</param> /// <returns><see langword="true"/> if the conversion succeeded; otherwise, <see langword="false"/>.</returns> public static Boolean TryParse(String s, NumberStyles style, IFormatProvider provider, out SourcedResource <T> v) { var source = AssetSource.Global; if (s.EndsWith(" local")) { source = AssetSource.Local; s = s.Substring(0, s.Length - " local".Length); } else if (s.EndsWith(" global")) { source = AssetSource.Global; s = s.Substring(0, s.Length - " global".Length); } var asset = (AssetID)ObjectResolver.FromString(s.Trim(), typeof(AssetID), provider); v = new SourcedResource <T>(asset, source); return(true); }
/// <summary> /// Creates a new <see cref="AnimationKeyframeBase"/> instance from the specified keyframe definition. /// </summary> /// <param name="keyframeDefinition">The keyframe definition to instantiate.</param> /// <param name="keyframeValueType">The type of value being animated by the keyframe.</param> /// <returns>The <see cref="AnimationKeyframeBase"/> instance that was created.</returns> private AnimationKeyframeBase InstantiateStoryboardAnimationKeyframe(UvssStoryboardKeyframe keyframeDefinition, Type keyframeValueType) { var time = TimeSpan.FromMilliseconds(keyframeDefinition.Time); var easing = default(EasingFunction); if (!String.IsNullOrEmpty(keyframeDefinition.Easing)) { standardEasingFunctions.TryGetValue(keyframeDefinition.Easing, out easing); } var valueDef = keyframeDefinition.Value; var value = valueDef.IsEmpty ? null : ObjectResolver.FromString(valueDef.Value, keyframeValueType, valueDef.Culture, true); var keyframeType = typeof(AnimationKeyframe <>).MakeGenericType(keyframeValueType); var keyframeInstance = (value == null) ? (AnimationKeyframeBase)Activator.CreateInstance(keyframeType, time, easing) : (AnimationKeyframeBase)Activator.CreateInstance(keyframeType, time, value, easing); return(keyframeInstance); }
/// <summary> /// Attempts to convert the tag's value to the specified type. /// </summary> /// <typeparam name="T">The type to which to convert the tag's value.</typeparam> /// <returns>The converted value of the tag.</returns> public T As <T>() { return((T)ObjectResolver.FromString(Value, typeof(T))); }
/// <summary> /// Creates an instance of DefaultValueAttribute from the specified XML element. /// </summary> /// <param name="element">The XML element from which to create the attribute.</param> /// <param name="type">The type of the default value.</param> /// <returns>The attribute that was created.</returns> private static Attribute CreateDefaultValueAttribute(XElement element, Type type) { var value = ObjectResolver.FromString(element.Value, type); return(new DefaultValueAttribute(value)); }