Exemple #1
0
            public AvaloniaAttachedInstanceProperty(XamlAstNamePropertyReference prop,
                                                    TransformerConfiguration config,
                                                    IXamlType declaringType,
                                                    IXamlType type,
                                                    IXamlType avaloniaPropertyType,
                                                    IXamlType avaloniaObject,
                                                    IXamlField field) : base(prop, prop.Name,
                                                                             declaringType, null)


            {
                _config               = config;
                _declaringType        = declaringType;
                _avaloniaPropertyType = avaloniaPropertyType;

                // XamlIl doesn't support generic methods yet
                if (_avaloniaPropertyType.GenericArguments?.Count > 0)
                {
                    _avaloniaPropertyType = _avaloniaPropertyType.BaseType;
                }

                _avaloniaObject = avaloniaObject;
                _field          = field;
                PropertyType    = type;
                Setters.Add(new SetterMethod(this));
                Getter = new GetterMethod(this);
            }
Exemple #2
0
        public XamlAstClrProperty(IXamlLineInfo lineInfo, IXamlProperty property,
                                  TransformerConfiguration cfg) : base(lineInfo)
        {
            Name   = property.Name;
            Getter = property.Getter;
            if (property.Setter != null)
            {
                Setters.Add(new XamlDirectCallPropertySetter(property.Setter));
            }
            CustomAttributes = property.CustomAttributes.ToList();
            DeclaringType    = (property.Getter ?? property.Setter)?.DeclaringType;
            var typeConverterAttributes = cfg.GetCustomAttribute(property, cfg.TypeMappings.TypeConverterAttributes);

            if (typeConverterAttributes != null)
            {
                foreach (var attr in typeConverterAttributes)
                {
                    var typeConverter =
                        XamlTransformHelpers.TryGetTypeConverterFromCustomAttribute(cfg, attr);
                    if (typeConverter != null)
                    {
                        TypeConverters[property.PropertyType] = typeConverter;
                        break;
                    }
                }
            }
        }
Exemple #3
0
        public FlowActivityDefinition <TReq, TRes> SetValue <TVal>(Expression <Func <TReq, TVal> > propertyExpression, TVal value)
        {
            var requestSetInputProperty = ReflectionUtils.GetProperty(propertyExpression);

            Setters.Add(new Tuple <PropertyInfo, object>(requestSetInputProperty, value));
            AddFlowValueBinding <TReq, TRes>(requestSetInputProperty);
            return(this);
        }
Exemple #4
0
 public void add(DependencyProperty property, object value)
 {
     Setters.Add(new Setter()
     {
         Property = property,
         Value    = value
     });
 }
 /// <summary>
 /// Used to provider a custom setting actions. This setters will be invoked just after the new
 /// value is set on the property. They setters will be executed in the same order they are defined
 /// </summary>
 /// <param name="setters">A list of setters</param>
 /// <returns>this</returns>
 public ViewModelPropertyDescriptor <TOwner, TResult> Set(params Action <TResult>[] setters)
 {
     foreach (var setter in setters)
     {
         Setters.Add(setter);
     }
     return(this);
 }
    public override void InitStats()
    {
        base.InitStats();


        Getters.Add("Killstreak", delegate() { return(Killstreak); });

        Setters.Add("Killstreak", delegate(object val) { Killstreak = (int)val; });
    }
            public SetterValueProperty(IXamlIlLineInfo line, IXamlIlType setterType, IXamlIlType targetType,
                                       AvaloniaXamlIlWellKnownTypes types)
                : base(line, "Value", setterType, null)
            {
                Getter = setterType.Methods.First(m => m.Name == "get_Value");
                var method = setterType.Methods.First(m => m.Name == "set_Value");

                Setters.Add(new XamlIlDirectCallPropertySetter(method, types.IBinding));
                Setters.Add(new XamlIlDirectCallPropertySetter(method, types.UnsetValueType));
                Setters.Add(new XamlIlDirectCallPropertySetter(method, targetType));
            }
Exemple #8
0
 public XamlIlAstClrProperty(IXamlIlLineInfo lineInfo, IXamlIlProperty property) : base(lineInfo)
 {
     Name   = property.Name;
     Getter = property.Getter;
     if (property.Setter != null)
     {
         Setters.Add(new XamlIlDirectCallPropertySetter(property.Setter));
     }
     CustomAttributes = property.CustomAttributes.ToList();
     DeclaringType    = (property.Getter ?? property.Setter)?.DeclaringType;
 }
Exemple #9
0
        public TreeViewItemStyle()
        {
            VisualTree = new FrameworkElementFactory(typeof(TreeViewItemTemplate));
            VisualTree.AppendChild(new FrameworkElementFactory(typeof(ItemsPresenter), "ItemsHost"));
            VisualTree.AppendChild(new FrameworkElementFactory(typeof(ContentPresenter), "PART_Header"));

            Template            = new ControlTemplate(typeof(TreeViewItem));
            Template.VisualTree = VisualTree;

            Setters.Add(new Setter(Control.TemplateProperty, Template));
        }
Exemple #10
0
    public override void InitStats()
    {
        base.InitStats();

        Getters.Add("Deaths", delegate() { return(Deaths); });
        Getters.Add("Frags", delegate() { return(Frags); });
        Getters.Add("Score", delegate() { return(Score); });

        Setters.Add("Deaths", delegate(object val) { Deaths = (int)val; });
        Setters.Add("Frags", delegate(object val) { Frags = (int)val; });
        Setters.Add("Score", delegate(object val) { Score = (int)val; });
    }
Exemple #11
0
        void IAddChild.AddChild(object child)
        {
            if (child == null)
            {
                throw new ArgumentNullException("child");
            }

            if (child is SetterBase == false)
            {
                throw new Exception(string.Format("Cannot convert '{0}' to type '{1}'", child.GetType(), typeof(SetterBase)));
            }

            Setters.Add((SetterBase)child);
        }
Exemple #12
0
        public override void DeepCopy(IDeepCopyable source, ICopyManager copyManager)
        {
            base.DeepCopy(source, copyManager);
            TriggerBase tb = (TriggerBase)source;

            foreach (TriggerAction ac in tb.EnterActions)
            {
                EnterActions.Add(copyManager.GetCopy(ac));
            }
            foreach (TriggerAction ac in tb.ExitActions)
            {
                ExitActions.Add(copyManager.GetCopy(ac));
            }
            foreach (Setter s in tb.Setters)
            {
                Setters.Add(copyManager.GetCopy(s));
            }
        }
Exemple #13
0
        ///<summary>
        /// This method is called to Add a Setter object as a child of the Style.
        /// This method is used primarily by the parser to set style properties and events.
        ///</summary>
        ///<param name="value">
        /// The object to add as a child; it must be a SetterBase subclass.
        ///</param>
        void IAddChild.AddChild(Object value)
        {
            // Verify Context Access
            VerifyAccess();

            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            SetterBase sb = value as SetterBase;

            if (sb == null)
            {
                throw new ArgumentException(SR.Get(SRID.UnexpectedParameterType, value.GetType(), typeof(SetterBase)), "value");
            }

            Setters.Add(sb);
        }
Exemple #14
0
        private NativeStyle BuildNativeStyle()
        {
            var targetType = Style.TargetType ?? typeof(FrameworkElement);

            var nativeStyle = new NativeStyle
            {
                TargetType = targetType
            };

#if !SILVERLIGHT
            foreach (var baseStyle in Style.EnumerateBaseStylesAndSelf().OfType <Style>())
            {
                if (baseStyle.Resources.Count == 0)
                {
                    continue;
                }

                foreach (var resourceKey in baseStyle.Resources.Keys)
                {
                    if (nativeStyle.Resources.Contains(resourceKey) == false)
                    {
                        nativeStyle.Resources.Add(resourceKey, baseStyle.Resources[resourceKey]);
                    }
                }
            }
#endif

            Triggers.AddRange(Style.ActualTriggers);

            var flatSetters = Style.ActualSetters.OfType <Setter>().Select(s => s.DeepClone <Setter>()).ToList();

            Dictionary <DependencyProperty, DependencyProperty> dynamicProperties = null;

            foreach (var setter in flatSetters)
            {
                if (string.IsNullOrEmpty(setter.ExpandoProperty) == false || string.IsNullOrEmpty(setter.VisualState))
                {
                    continue;
                }

                var property = setter.ResolveProperty(targetType);

                if (property == null)
                {
                    LogService.LogWarning($"Unable resolve property for setter: {setter}");
                    continue;
                }

                dynamicProperties ??= new Dictionary <DependencyProperty, DependencyProperty>();

                dynamicProperties.GetValueOrCreate(property, GetDynamicProperty);
            }

            if (dynamicProperties != null)
            {
                foreach (var kv in dynamicProperties)
                {
                    nativeStyle.Setters.Add(new NativeSetter {
                        Property = kv.Key, Value = new Binding {
                            Path = new PropertyPath(kv.Value), RelativeSource = XamlConstants.Self
                        }
                    });
                }
            }

            foreach (var setter in flatSetters)
            {
                if (string.IsNullOrEmpty(setter.ExpandoProperty) == false)
                {
                    Setters.Add(setter.Optimize());
                    continue;
                }

                var dependencyProperty = setter.ResolveProperty(targetType);
                var dynamicProperty    = dependencyProperty != null?dynamicProperties?.GetValueOrDefault(dependencyProperty) : null;

                if (dynamicProperty != null)
                {
                    setter.Property = dynamicProperty;
                    Setters.Add(setter.Optimize());
                    continue;
                }

                var nativeSetter = setter.CreateNativeStyleSetter(targetType);

                if (nativeSetter != null)
                {
                    nativeStyle.Setters.Add(nativeSetter);
                }
                else
                {
                    Setters.Add(setter.Optimize());
                }
            }

            nativeStyle.Setters.Add(new NativeSetter(InstanceProperty, this));

            return(nativeStyle);
        }
Exemple #15
0
 public RedBlackDataTrigger()
 {
     Value = string.Empty;
     Setters.Add(new Setter(Rectangle.StrokeProperty, new SolidColorBrush(Colors.Black)));
 }
Exemple #16
0
 public void AddChild(Setter s)
 {
     Setters.Add(s);
 }
Exemple #17
0
        private void Initialize(Type type)
        {
            Type underlying;

            if (type.IsNullable(out underlying) && !type.IsNullablePrimitive())
            {
                Type = underlying;
            }
            else
            {
                Type = type;
            }

            if (Type.IsPrimitive())
            {
                throw new InvalidOperationException("The primitive type cannot be cached.");
            }

            Properties = Type.GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.GetIndexParameters().Length == 0).ToList();

            var getters = Type.GetProperties(BindingFlags.Public | BindingFlags.Instance)
                          .Where(x => x.CanRead && x.GetIndexParameters().Length == 0 && x.GetGetMethod(false) != null);

            foreach (var get in getters)
            {
                var targetParamExp = Expression.Parameter(typeof(object), "target");
                var castExp        = Expression.Convert(targetParamExp, Type);
                var getMethod      = get.GetGetMethod();
                var getExp         = Expression.Call(castExp, getMethod);
                var retExp         = Expression.Convert(getExp, typeof(object));
                var getter         = (Func <object, object>)Expression.Lambda(retExp, targetParamExp).Compile();
                Getters.Add(new Tuple <PropertyInfo, Func <object, object> >(get, getter));
            }

            var setters = Type.GetProperties(BindingFlags.Public | BindingFlags.Instance)
                          .Where(x => x.CanWrite && x.GetIndexParameters().Length == 0 && x.GetSetMethod(false) != null);

            if (!Type.IsValueType())
            {
                foreach (var set in setters)
                {
                    var targetParamExp = Expression.Parameter(typeof(object), "target");
                    var valueParamExp  = Expression.Parameter(typeof(object), "val");
                    var setMethod      = set.GetSetMethod();
                    var castTargetExp  = Expression.Convert(targetParamExp, Type);
                    var testValueExp   = Expression.NotEqual(valueParamExp, Expression.Constant(null));
                    var castValueExp   = Expression.Convert(valueParamExp, set.PropertyType);

                    var setValueExp = Expression.Call(castTargetExp, setMethod, castValueExp);
                    var testExp     = Expression.IfThen(testValueExp, setValueExp);
                    var setter      = (Action <object, object>)Expression.Lambda(testExp, targetParamExp, valueParamExp).Compile();
                    Setters.Add(new Tuple <PropertyInfo, Action <object, object> >(set, setter));
                }
                Constructor = Type.GetConstructor(Type.EmptyTypes);

                if (Constructor != null)
                {
                    var newExp = Expression.New(Constructor);
                    Launcher = (Func <object>)Expression.Lambda(newExp).Compile();
                }
            }
            else
            {
                foreach (var set in setters)
                {
                    Action <object, object> setter = (target, val) => set.SetValue(target, val, null);
                    Setters.Add(new Tuple <PropertyInfo, Action <object, object> >(set, setter));
                }
                var newExp     = Expression.New(Type);
                var convertExp = Expression.Convert(newExp, typeof(object));
                Launcher = (Func <object>)Expression.Lambda(convertExp).Compile();
            }
            // TODO: abstract? inherit?
        }
Exemple #18
0
        private bool ExtractAccessors(MemberInfo member, string fieldName, ref Type dataType, ref bool isKey)
        {
            // Locals
            var getter = default(FieldGetterDelegate);
            var setter = default(FieldSetterDelegate);

            // Homogenize fields and properties
            switch (member.MemberType)
            {
            case System.Reflection.MemberTypes.Field:
                var field = ((FieldInfo)member);
                dataType = field.FieldType;
                getter   = field.GetValue;
                setter   = field.SetValue;
                break;

            case System.Reflection.MemberTypes.Property:
                var property = ((PropertyInfo)member);
                dataType = property.PropertyType;
                getter   = property.GetValue;
                setter   = property.SetValue;
                break;

            default:
                // Ignore other member types
                return(false);
            }

            // Inspect fields for key, specifiable/actual data type
            var bigtableKey = member.GetCustomAttribute <BigTableKeyAttribute>();
            var genDataType = dataType.IsGenericType ? dataType.GetGenericTypeDefinition() : null;
            var isBigField  = genDataType == typeof(BigTableField <>);
            var isBigKey    = genDataType == typeof(BigTableKey <>);

            isKey = bigtableKey != null || genDataType == typeof(BigTableKey <>);
            var isBigWrapper = isBigField || isBigKey;

            IsBigBoxed.Add(fieldName, isBigWrapper);

            // Store accessors
            if (isBigWrapper)
            {
                var subDataType = dataType.GenericTypeArguments[0];
                var access      = isKey ? (BigAccess)GetKeyAccess(subDataType) : GetFieldAccess(subDataType);
                IsSpecified.Add(fieldName, target => ((IBigTableField)getter(target)).IsSpecified);
                Getters.Add(fieldName, target => access.ValueGetter(getter(target)));
                var useDataType = dataType;
                Setters.Add(fieldName, (target, value) =>
                {
                    var newValue = Activator.CreateInstance(useDataType);

                    access.ValueSetter(newValue, value);
                    setter(target, newValue);
                });

                dataType = subDataType;
            }
            else
            {
                IsSpecified.Add(fieldName, target => true);
                Getters.Add(fieldName, getter);
                Setters.Add(fieldName, setter);
            }

            // Indicate is property of field
            return(true);
        }
 public RectangleStyle()
 {
     TargetType = typeof(Rectangle);
     Setters.Add(new Setter(Rectangle.StrokeProperty, new SolidColorBrush(Colors.Red)));
 }