コード例 #1
0
        private Tuple <ScriptProperty, Action <string> >[] GetScriptProperties(NativeComponent component)
        {
            var type       = component.GetType();
            var properties = type.GetProperties().Where(p => System.Attribute.IsDefined(p, typeof(EditableFieldAttribute)));

            var propArray = new Tuple <ScriptProperty, Action <string> > [properties.Count()];
            var index     = 0;

            foreach (var prop in properties)
            {
                var current = prop;
                var p       = new ScriptProperty()
                {
                    name = current.Name
                };
                Action <string> callback = null;

                if (current.PropertyType == typeof(bool))
                {
                    p.type   = PropertyType.Boolean;
                    p.value  = current.GetValue(component).ToString();
                    callback = s => {
                        current.SetValue(component, s == "true");
                    };
                }
                else if (current.PropertyType == typeof(string))
                {
                    p.type   = PropertyType.String;
                    p.value  = current.GetValue(component).ToString();
                    callback = s => {
                        current.SetValue(component, s);
                    };
                }
                else if (current.PropertyType == typeof(float))
                {
                    p.type   = PropertyType.Number;
                    p.value  = current.GetValue(component).ToString();
                    callback = s => {
                        var floatNum = default(float);
                        if (float.TryParse(s, System.Globalization.NumberStyles.Float, null, out floatNum))
                        {
                            current.SetValue(component, floatNum);
                        }
                    };
                }
                else if (current.PropertyType == typeof(int))
                {
                    p.type   = PropertyType.Number;
                    p.value  = current.GetValue(component).ToString();
                    callback = s => {
                        var intNum = default(int);
                        if (int.TryParse(s, System.Globalization.NumberStyles.Integer, null, out intNum))
                        {
                            current.SetValue(component, intNum);
                        }
                    };
                }
                else if (current.PropertyType == typeof(double))
                {
                    p.type   = PropertyType.Number;
                    p.value  = current.GetValue(component).ToString();
                    callback = s => {
                        var doubleNum = default(double);
                        if (double.TryParse(s, System.Globalization.NumberStyles.None, null, out doubleNum))
                        {
                            current.SetValue(component, doubleNum);
                        }
                    };
                }

                propArray[index++] = new Tuple <ScriptProperty, Action <string> > (p, callback);
            }

            return(propArray);
        }
コード例 #2
0
        private Property[] GetProperties(NativeComponent component)
        {
            var propList = new List <Property> ();

            var type       = component.GetType();
            var properties = type.GetProperties().Where(p => System.Attribute.IsDefined(p, typeof(EditableFieldAttribute)));

            foreach (var prop in properties)
            {
                var current = prop;
                var p       = new Property {
                    name = current.Name
                };

                //TODO: Simplify this large block of code
                if (current.PropertyType == typeof(bool))
                {
                    p.type           = PropertyType.Boolean;
                    p.value          = current.GetValue(component).ToString();
                    p.onPropertyEdit = s => {
                        current.SetValue(component, s == "true");
                    };
                    propList.Add(p);
                }
                else if (current.PropertyType == typeof(string))
                {
                    p.type           = PropertyType.String;
                    p.value          = current.GetValue(component).ToString();
                    p.onPropertyEdit = s => {
                        current.SetValue(component, s);
                    };
                    propList.Add(p);
                }
                else if (current.PropertyType == typeof(float))
                {
                    p.type           = PropertyType.Number;
                    p.value          = current.GetValue(component).ToString();
                    p.onPropertyEdit = s => {
                        var floatNum = default(float);
                        if (float.TryParse(s, System.Globalization.NumberStyles.Float, null, out floatNum))
                        {
                            current.SetValue(component, floatNum);
                        }
                    };
                    propList.Add(p);
                }
                else if (current.PropertyType == typeof(int))
                {
                    p.type           = PropertyType.Number;
                    p.value          = current.GetValue(component).ToString();
                    p.onPropertyEdit = s => {
                        var intNum = default(int);
                        if (int.TryParse(s, System.Globalization.NumberStyles.Integer, null, out intNum))
                        {
                            current.SetValue(component, intNum);
                        }
                    };
                    propList.Add(p);
                }
                else if (current.PropertyType == typeof(double))
                {
                    p.type           = PropertyType.Number;
                    p.value          = current.GetValue(component).ToString();
                    p.onPropertyEdit = s => {
                        var doubleNum = default(double);
                        if (double.TryParse(s, System.Globalization.NumberStyles.None, null, out doubleNum))
                        {
                            current.SetValue(component, doubleNum);
                        }
                    };
                    propList.Add(p);
                }
            }

            return(propList.ToArray());
        }
コード例 #3
0
 public static Bitmap Print(this NativeComponent component, bool clientArea = false)
 {
     return(ScreenCapture.Print(component.Handle, clientArea));
 }