private Type getPropertyType(DesignerPropertyInfo prop, object obj, string valueClass) { if (prop.Property != null && obj != null) { object propertyMember = prop.Property.GetValue(obj, null); if (propertyMember != null) { VariableDef variable = propertyMember as VariableDef; if (variable != null) { variable.ValueClass = valueClass; return(variable.GetValueType()); } RightValueDef varRV = propertyMember as RightValueDef; if (varRV != null) { return(varRV.ValueType); } } } if (prop.Attribute != null) { DesignerPropertyEnum enumAtt = prop.Attribute as DesignerPropertyEnum; if (enumAtt != null) { return(enumAtt.FilterType); } } return(null); }
private Type getDependedPropertyType(DesignerPropertyInfo prop, object obj) { Debug.Check(obj != null); PropertyInfo pi = getDependedProperty(prop, obj); if (pi != null) { object propertyMember = pi.GetValue(obj, null); VariableDef variable = propertyMember as VariableDef; if (variable != null) { return(variable.GetValueType()); } RightValueDef varRV = propertyMember as RightValueDef; if (varRV != null) { return(varRV.ValueType); } MethodDef method = propertyMember as MethodDef; if (method != null) { return(method.ReturnType); } } return(null); }
public override void SetVariable(VariableDef variable, object obj) { base.SetVariable(variable, obj); _valueWasAssigned = false; clear(); if (variable != null) { Type enumtype = variable.GetValueType(); if (enumtype.IsEnum) { Array list = Enum.GetValues(enumtype); string enumName = DesignerEnum.GetDisplayName(variable.Value); foreach (object enumVal in list) { _allValues.Add(enumVal); if (DesignerEnum.GetDisplayName(enumVal) == enumName) { _values.Add(enumVal); comboBox.Items.Add(enumName); } } comboBox.Text = enumName; } } _valueWasAssigned = true; }
public override void SetVariable(VariableDef variable, object obj) { base.SetVariable(variable, obj); if (variable != null) { Type valueType = variable.GetValueType(); if (valueType == typeof(bool)) { checkBox.Checked = (bool)variable.Value; } } }
public override void SetProperty(DesignerPropertyInfo property, object obj) { base.SetProperty(property, obj); _resetMethods = false; DesignerRightValueEnum enumAttRV = _property.Attribute as DesignerRightValueEnum; this.FilterType = null; if (enumAttRV != null && enumAttRV.DependedProperty != "") { Type objType = _object.GetType(); PropertyInfo pi = objType.GetProperty(enumAttRV.DependedProperty); object propMember = pi.GetValue(_object, null); VariableDef var = propMember as VariableDef; if (var != null) { this.FilterType = var.GetValueType(); } else { MethodDef method = propMember as MethodDef; if (method != null) { this.FilterType = method.ReturnType; } else { RightValueDef varRVp = propMember as RightValueDef; if (varRVp != null) { this.FilterType = varRVp.ValueType; } } } } else { this.FilterType = _property.Attribute.FilterType; } setComboBox(); }
public override void SetParameter(MethodDef.Param param, object obj) { base.SetParameter(param, obj); if (param.IsFromStruct && (param.Type == typeof(VariableDef))) { VariableDef v = param.Value as VariableDef; FilterType = v.GetValueType(); } else { FilterType = param.Type; } string[] tokens = param.Value.ToString().Split(' '); setComboBox(tokens[tokens.Length - 1]); }
public override void SetVariable(VariableDef variable, object obj) { base.SetVariable(variable, obj); if (variable != null) { string str = trimQuotes(variable.Value.ToString()); if (textBox.Text != str) { textBox.Text = str; _modified = true; valueChanged(); } if (Plugin.IsCharType(variable.GetValueType())) { textBox.MaxLength = 1; } } }
public override void SetVariable(VariableDef variable, object obj) { base.SetVariable(variable, obj); if (variable != null) { // extract the value decimal value = 0; Type valueType = variable.GetValueType(); if (Plugin.IsFloatType(valueType)) { const float maxValue = 1000000000000; SetRange(2, (decimal)(-maxValue), (decimal)maxValue, (decimal)0.01); float val = Convert.ToSingle(variable.Value); value = (decimal)val; numericUpDown.DecimalPlaces = 2; } else if (valueType == typeof(int)) { SetRange(0, (decimal)int.MinValue, (decimal)int.MaxValue, (decimal)1); int val = (int)variable.Value; value = (decimal)val; } else if (valueType == typeof(uint)) { SetRange(0, (decimal)int.MinValue, (decimal)int.MaxValue, (decimal)1); uint val = (uint)variable.Value; value = (decimal)val; } else if (valueType == typeof(short)) { SetRange(0, (decimal)short.MinValue, (decimal)short.MaxValue, (decimal)1); short val = (short)variable.Value; value = (decimal)val; } else if (valueType == typeof(ushort)) { SetRange(0, (decimal)ushort.MinValue, (decimal)ushort.MaxValue, (decimal)1); ushort val = (ushort)variable.Value; value = (decimal)val; } else if (valueType == typeof(sbyte)) { SetRange(0, (decimal)sbyte.MinValue, (decimal)sbyte.MaxValue, (decimal)1); sbyte val = (sbyte)variable.Value; value = (decimal)val; } else if (valueType == typeof(byte)) { SetRange(0, (decimal)byte.MinValue, (decimal)byte.MaxValue, (decimal)1); byte val = (byte)variable.Value; value = (decimal)val; } else if (valueType == typeof(long)) { SetRange(0, (decimal)int.MinValue, (decimal)int.MaxValue, (decimal)1); long val = (long)variable.Value; value = (decimal)val; } else if (valueType == typeof(ulong)) { SetRange(0, (decimal)uint.MinValue, (decimal)uint.MaxValue, (decimal)1); ulong val = (ulong)variable.Value; value = (decimal)val; } // assign value within limits numericUpDown.Value = Math.Max(numericUpDown.Minimum, Math.Min(numericUpDown.Maximum, value)); } }
private void setEditor(DesignerPropertyEditor editor, string valueType) { if (editor == null) { return; } if (valueType == VariableDef.kConst) { if (_param.Value != null && (_param.Value is VariableDef || _param.Value is PropertyDef || _param.Value is ParInfo)) { if (!(_param.IsFromStruct)) { _param.Value = Plugin.DefaultValue(_param.Type); } else { if (_param.Value is VariableDef) { VariableDef v = _param.Value as VariableDef; _param.Value = Plugin.DefaultValue(v.GetValueType()); } else if (_param.Value is ParInfo) { ParInfo v = _param.Value as ParInfo; _param.Value = Plugin.DefaultValue(v.Variable.GetValueType()); } } } } else { DesignerPropertyEnumEditor propertyEnumEditor = editor as DesignerPropertyEnumEditor; if (_param.Value is VariableDef) { VariableDef v = _param.Value as VariableDef; if (v.ValueClass != valueType) { Type t1 = v.GetValueType() != null?v.GetValueType() : _param.Type; object dv = Plugin.DefaultValue(t1); _param.Value = new VariableDef(dv, valueType); } propertyEnumEditor.FilterType = (v.GetValueType() != null ? v.GetValueType() : _param.Type); } else if (_param.Value is ParInfo) { ParInfo v = _param.Value as ParInfo; if (v.Variable.ValueClass != valueType) { object dv = Plugin.DefaultValue(v.Variable.GetValueType()); _param.Value = new VariableDef(dv, valueType); } propertyEnumEditor.FilterType = v.Variable.GetValueType(); } else { _param.Value = new VariableDef(_param.Value, valueType); propertyEnumEditor.FilterType = _param.Type; } } editor.SetParameter(_param, _object, false); editor.ValueWasAssigned(); editor.ValueWasChanged += editor_ValueWasChanged; }
static private void WritePropertyValue(BsonSerializer file, DesignerPropertyInfo property, object o) { string str = property.GetExportValue(o); string[] tokens = str.Split(' '); string valueString = null; if (tokens.Length == 3 && tokens[0] == "const") { valueString = tokens[2]; } else if (tokens.Length == 1) { valueString = str; } bool bW = false; if (valueString != null) { object obj = property.Property.GetValue(o, null); object v = null; Type valueType = null; VariableDef varType = obj as VariableDef; if (varType != null) { valueType = varType.GetValueType(); } else { RightValueDef rvarType = obj as RightValueDef; if (rvarType != null) { if (rvarType.Method == null) { valueType = rvarType.ValueType; } } else { MethodDef mType = obj as MethodDef; if (mType != null) { Debug.Check(true); } else { valueType = obj.GetType(); } } } if (valueType != null && Plugin.InvokeTypeParser(null, valueType, valueString, (object value) => v = value, null)) { file.WriteAttribute(property.Property.Name, v); bW = true; } } if (!bW) { file.WriteAttributeString(property.Property.Name, str); } }
private void setEditor(DesignerPropertyEditor editor, string valueType) { if (editor == null) { return; } if (valueType == VariableDef.kConst) { if (_param.Value != null && (_param.Value is VariableDef || _param.Value is PropertyDef || _param.Value is ParInfo)) { if (!(_param.IsFromStruct)) { _param.Value = Plugin.DefaultValue(_param.Type); } else { if (_param.Value is VariableDef) { VariableDef v = _param.Value as VariableDef; _param.Value = Plugin.DefaultValue(v.GetValueType()); } else if (_param.Value is ParInfo) { ParInfo v = _param.Value as ParInfo; _param.Value = Plugin.DefaultValue(v.Variable.GetValueType()); } } } } else if (valueType == VariableDef.kPar) { if (_param.IsFromStruct) { if (!(_param.Value is ParInfo) && !(_param.Value is VariableDef)) { ParInfo par = new ParInfo(this._root); par.Name = _param.Attribute.DisplayName; par.TypeName = _param.Type.FullName; par.Variable = new VariableDef(_param.Value, VariableDef.kPar); _param.Value = par; } else { if (_param.Value is VariableDef) { VariableDef v = _param.Value as VariableDef; if (v.ValueClass != valueType) { Type t1 = v.GetValueType() != null?v.GetValueType() : _param.Type; object dv = Plugin.DefaultValue(t1); _param.Value = new VariableDef(dv, valueType); } } } } } else { if (!_param.IsFromStruct) { if (valueType == VariableDef.kSelf) { DesignerPropertyEnumEditor propertyEnumEditor = editor as DesignerPropertyEnumEditor; propertyEnumEditor.GlobalType = null; propertyEnumEditor.FilterType = _param.Type; } else { DesignerPropertyEnumEditor propertyEnumEditor = editor as DesignerPropertyEnumEditor; propertyEnumEditor.GlobalType = valueType; propertyEnumEditor.FilterType = _param.Type; } } else { DesignerPropertyEnumEditor propertyEnumEditor = editor as DesignerPropertyEnumEditor; if (valueType == VariableDef.kSelf) { propertyEnumEditor.GlobalType = null; } else { propertyEnumEditor.GlobalType = valueType; } if (_param.Value is VariableDef) { VariableDef v = _param.Value as VariableDef; if (v.ValueClass != valueType) { Type t1 = v.GetValueType() != null?v.GetValueType() : _param.Type; object dv = Plugin.DefaultValue(t1); _param.Value = new VariableDef(dv, valueType); } propertyEnumEditor.FilterType = (v.GetValueType() != null ? v.GetValueType() : _param.Type); } else if (_param.Value is ParInfo) { ParInfo v = _param.Value as ParInfo; if (v.Variable.ValueClass != valueType) { object dv = Plugin.DefaultValue(v.Variable.GetValueType()); _param.Value = new VariableDef(dv, valueType); } propertyEnumEditor.FilterType = v.Variable.GetValueType(); } else { _param.Value = new VariableDef(_param.Value, valueType); propertyEnumEditor.FilterType = _param.Type; } } } editor.SetParameter(_param, _object); editor.ValueWasAssigned(); editor.ValueWasChanged += editor_ValueWasChanged; }
protected VariableDef parseConstVar(NodeTag.DefaultObject node, object parentObject, string str) { Debug.Check(str.StartsWith("const")); //const Int32 1 object propertyMemberDepended = null; Type objType = node.GetType(); if (this.DependedProperty != "") { System.Reflection.PropertyInfo pi = objType.GetProperty(this.DependedProperty); if (pi != null) { propertyMemberDepended = pi.GetValue(node, null); } else if (pi == null && parentObject != null) { Type parentType = parentObject.GetType(); pi = parentType.GetProperty(this.DependedProperty); propertyMemberDepended = pi.GetValue(parentObject, null); } } Type valueType = null; VariableDef variableDepended = propertyMemberDepended as VariableDef; if (variableDepended != null) { valueType = variableDepended.GetValueType(); } else if (propertyMemberDepended != null) { MethodDef methodDepended = propertyMemberDepended as MethodDef; if (methodDepended != null) { valueType = methodDepended.ReturnType; } else { RightValueDef varRV = propertyMemberDepended as RightValueDef; if (varRV != null) { valueType = varRV.ValueType; } } } else { string[] tokens = str.Split(' '); Debug.Check(tokens.Length == 3); valueType = Plugin.GetTypeFromName(tokens[1]); } if (valueType != null) { VariableDef variable = new VariableDef(null); string[] tokens = str.Split(' '); Debug.Check(tokens.Length == 3); Plugin.InvokeTypeParser(valueType, tokens[2], (object value) => variable.Value = value, node); return(variable); } return(null); }
public override void SetProperty(DesignerPropertyInfo property, object obj) { base.SetProperty(property, obj); _resetProperties = false; Type enumtype = null; DesignerPropertyEnum enumAtt = property.Attribute as DesignerPropertyEnum; if (enumAtt != null) { enumtype = property.Property.PropertyType; } if (enumtype == null) { throw new Exception(string.Format(Resources.ExceptionDesignerAttributeExpectedEnum, property.Property.Name)); } Behaviac.Design.Attachments.Attach evt = obj as Behaviac.Design.Attachments.Attach; Behaviac.Design.Nodes.BaseNode baseNode = (evt != null) ? evt.Node : obj as Behaviac.Design.Nodes.BaseNode; Behaviac.Design.Nodes.Behavior behavior = (baseNode != null) ? baseNode.Behavior as Behaviac.Design.Nodes.Behavior : null; if (behavior == null && this._root != null) { behavior = this._root.Behavior as Behaviac.Design.Nodes.Behavior; } _agentType = null; if (behavior != null) { _agentType = behavior.AgentType; if (_agentType == null) { return; } } object propertyMember = property.Property.GetValue(obj, null); VariableDef variable = propertyMember as VariableDef; RightValueDef variableRV = propertyMember as RightValueDef; if (variable != null && variable.ValueClass != VariableDef.kSelf) { _agentType = Plugin.GetInstanceAgentType(variable.ValueClass); } if (variableRV != null && variableRV.ValueClassReal != VariableDef.kSelf) { string gloablClass = variableRV.ValueClassReal; _agentType = Plugin.GetInstanceAgentType(gloablClass); } string selectionName = string.Empty; if (variable != null && variable.Property != null) { selectionName = variable.Property.DisplayName; } else if (variableRV != null && variableRV.Var != null && variableRV.Var.Property != null) { selectionName = variableRV.Var.Property.DisplayName; } this.FilterType = null; if (enumAtt != null) { if (enumAtt.DependedProperty != "") { Type objType = _object.GetType(); PropertyInfo pi = objType.GetProperty(enumAtt.DependedProperty); object propMember = pi.GetValue(obj, null); VariableDef var = propMember as VariableDef; if (var != null) { this.FilterType = var.GetValueType(); } else { MethodDef method = propMember as MethodDef; if (method != null) { this.FilterType = method.ReturnType; } else { RightValueDef varRV = propMember as RightValueDef; if (varRV != null) { this.FilterType = varRV.ValueType; } } } } else { this.FilterType = enumAtt.FilterType; } } setComboBox(selectionName); //after the left is changed, the right might need to be invalidated if (this.comboBox.Text != selectionName) { property.Property.SetValue(_object, null, null); } }