/// <summary>
        /// Builds an Instruction using the information stored in the InstructionBlueprint.
        /// </summary>
        /// <param name="target">The object that the returned Instruction will execute on</param>
        /// <param name="currentTime">The current time to use as an offset for the Instruction's Time of execution</param>
        /// <throws exception="ArgumentException">If target's type is not this InstructionBlueprint's TargetType</throws>
        /// <throws exception="NullReferenceException">If this InstructionBlueprint was fully initialized before this call to BuildInstruction.</throws>
        /// <returns>An Instruction created from this InstructionBlueprint's information</returns>
        #endregion
        public GenericInstruction BuildInstruction(object target, double currentTime)
        {
            GenericInstruction toReturn;


            //Make sure the target is a compatible type
#if WINDOWS_8
            if (!TargetType.GetTypeInfo().IsAssignableFrom(target.GetType().GetTypeInfo()))
#else
            if (!TargetType.IsInstanceOfType(target))
#endif
            {
                throw new ArgumentException("This InstructionBlueprint's TargetType is " + TargetType + " and doesn't match the argument's type, " +
                                            target.GetType());
            }
            else if (String.IsNullOrEmpty(MemberName) || MemberType == null)
            {
                throw new NullReferenceException("The InstructionBlueprint " + " has not been fully initialized and therefore cannot be made into an Instruction.");
            }
            else
            {
                mFourObjectArray[0] = target;
                mFourObjectArray[1] = MemberName;
                mFourObjectArray[2] = MemberValue;
                mFourObjectArray[3] = Time + currentTime;

                toReturn = mCurrentConstructor.Invoke(mFourObjectArray) as GenericInstruction;
            }
            return(toReturn);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Create a new bridge to a property for a bindable object.
 /// </summary>
 /// <param name="targetPropertyName">The name of the property that is going to be bound to with.</param>
 /// <param name="getter">Gets the value of the property.</param>
 /// <param name="setter">Sets the value of the property.</param>
 /// <param name="defaultValue">The default value of the property.</param>
 public BindableProperty(string targetPropertyName, Func <TOwner, TProperty> getter, Action <TOwner, TProperty> setter, TProperty defaultValue = default(TProperty))
 {
     TargetType     = typeof(TProperty);
     TargetProperty = TargetType.GetTypeInfo().GetDeclaredProperty(targetPropertyName);
     Getter         = getter;
     Setter         = setter;
     DefaultValue   = defaultValue;
 }
Exemplo n.º 3
0
        public object Deserialize(JSValue deserializedJson, object resultContainer = null)
        {
            if (deserializedJson == null)
            {
                throw new ArgumentNullException(nameof(deserializedJson));
            }

            if (deserializedJson._valueType < JSValueType.Object)
            {
                return(deserializedJson.Value);
            }
#if NETSTANDARD1_3
            var result = resultContainer ?? TargetType.GetTypeInfo().DeclaredConstructors.Where(x => x.IsPublic).First(x => x.GetParameters().Length == 0).Invoke(new object[0]);
#else
            var result = resultContainer ?? TargetType.GetConstructor(Type.EmptyTypes).Invoke(new object[0]);
#endif
            var tempSrcObject = deserializedJson._oValue as JSObject;
            foreach (var property in tempSrcObject._fields)
            {
                var prop = getProperty(property.Key);
                if (prop != null)
                {
                    object value        = property.Value;
                    var    deserializer = GetSerializer(value, Context.CurrentGlobalContext);
                    if (deserializer != null)
                    {
                        value = deserializer.Deserialize(property.Value);
                    }
                    else
                    {
                        value = Convert.ChangeType(property.Value.Value, prop.PropertyType);
                    }

                    prop.SetValue(result, value, null);
                    continue;
                }

                var field = getField(property.Key);
                if (field != null)
                {
                    object value        = property.Value;
                    var    deserializer = GetSerializer(value, Context.CurrentGlobalContext);
                    if (deserializer != null)
                    {
                        value = deserializer.Deserialize(property.Value);
                    }
                    else
                    {
                        value = Convert.ChangeType(property.Value.Value, field.FieldType);
                    }

                    field.SetValue(result, Convert.ChangeType(property.Value, field.FieldType));
                    continue;
                }
            }

            return(result);
        }
Exemplo n.º 4
0
        public virtual bool CanSerialize(object value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            return(TargetType.GetTypeInfo().IsAssignableFrom(value.GetType().GetTypeInfo()));
        }
Exemplo n.º 5
0
        public void Apply(DependencyObject d)
        {
            if (!TargetType.GetTypeInfo().IsAssignableFrom(d.GetType().GetTypeInfo()))
            {
                throw new InvalidOperationException($"This style cannot be applied to {d.GetType()}, Target type is {TargetType}.");
            }

            Seal();
            d.ValueStorage[StyleDependencyValueStorage.Key] = new StyleDependencyValueStorage(this, d);
        }
Exemplo n.º 6
0
        /// <inheritdoc/>
        protected override SelectorMatch Evaluate(IStyleable control, bool subscribe)
        {
            if (TargetType != null)
            {
                var controlType = control.StyleKey ?? control.GetType();

                if (IsConcreteType)
                {
                    if (controlType != TargetType)
                    {
                        return(SelectorMatch.False);
                    }
                }
                else
                {
                    if (!TargetType.GetTypeInfo().IsAssignableFrom(controlType.GetTypeInfo()))
                    {
                        return(SelectorMatch.False);
                    }
                }
            }

            if (Name != null && control.Name != Name)
            {
                return(SelectorMatch.False);
            }

            if (_classes.IsValueCreated && _classes.Value.Count > 0)
            {
                if (subscribe)
                {
                    var observable = Observable.FromEventPattern <
                        NotifyCollectionChangedEventHandler,
                        NotifyCollectionChangedEventArgs>(
                        x => control.Classes.CollectionChanged += x,
                        x => control.Classes.CollectionChanged -= x)
                                     .StartWith((EventPattern <NotifyCollectionChangedEventArgs>)null)
                                     .Select(_ => Matches(control.Classes))
                                     .DistinctUntilChanged();
                    return(new SelectorMatch(observable));
                }
                else
                {
                    return(new SelectorMatch(Matches(control.Classes)));
                }
            }
            else
            {
                return(SelectorMatch.True);
            }
        }
        /// <inheritdoc/>
        protected override SelectorMatch Evaluate(IStyleable control, bool subscribe)
        {
            if (TargetType != null)
            {
                var controlType = control.StyleKey ?? control.GetType();

                if (IsConcreteType)
                {
                    if (controlType != TargetType)
                    {
                        return(SelectorMatch.NeverThisType);
                    }
                }
                else
                {
                    if (!TargetType.GetTypeInfo().IsAssignableFrom(controlType.GetTypeInfo()))
                    {
                        return(SelectorMatch.NeverThisType);
                    }
                }
            }

            if (Name != null)
            {
                return(control.Name == Name ?
                       SelectorMatch.AlwaysThisInstance :
                       SelectorMatch.NeverThisInstance);
            }

            if (_classes.IsValueCreated && _classes.Value.Count > 0)
            {
                if (subscribe)
                {
                    var observable = new ClassObserver(control.Classes, _classes.Value);
                    return(new SelectorMatch(observable));
                }
                else
                {
                    return(Matches(control.Classes) ?
                           SelectorMatch.AlwaysThisInstance :
                           SelectorMatch.NeverThisInstance);
                }
            }
            else
            {
                return(SelectorMatch.AlwaysThisType);
            }
        }