|
|
@@ -274,55 +274,52 @@ namespace BeDesignerSCADA.ViewModel |
|
|
|
{ "Code" , "代码过滤脚本"}, |
|
|
|
{ "GenerateData" , "数据结果"}, |
|
|
|
}; |
|
|
|
//{"EventSendNameList" , "发送事件集"} |
|
|
|
/// <summary> |
|
|
|
/// 数据刷新 |
|
|
|
/// </summary> |
|
|
|
public void DataSX() |
|
|
|
{ |
|
|
|
//if (CanSelectedItem is System.Windows.Controls.Control) |
|
|
|
{ |
|
|
|
//属性变量 |
|
|
|
PropertyGridCommand cmd = new PropertyGridCommand(); |
|
|
|
var content = CanSelectedItem;// as System.Windows.Controls.Control; |
|
|
|
if (content is IExecutable executable) |
|
|
|
executable.PropertyChange += Executable_PropertyChange; |
|
|
|
//属性变量 |
|
|
|
PropertyGridCommand cmd = new PropertyGridCommand(); |
|
|
|
var content = CanSelectedItem;// as System.Windows.Controls.Control; |
|
|
|
if (content is IExecutable executable) |
|
|
|
executable.PropertyChange += Executable_PropertyChange; |
|
|
|
|
|
|
|
foreach (var item in EventName) |
|
|
|
foreach (var item in EventName) |
|
|
|
{ |
|
|
|
System.Reflection.PropertyInfo info = content.GetType().GetProperty(item.Key); |
|
|
|
var propName = info?.GetValue(content,null); |
|
|
|
if (info != null && (item.Key == "Content" ? (propName is string) : true)) |
|
|
|
{ |
|
|
|
System.Reflection.PropertyInfo info = content.GetType().GetProperty(item.Key); |
|
|
|
var propName = info?.GetValue(content,null); |
|
|
|
if (info != null && item.Key == "Content" ? (propName is string) : true) |
|
|
|
{ |
|
|
|
//var taget = this.GetType().GetMembers().Where(t => t.Name.Equals("BrowsableTrue")).FirstOrDefault(); |
|
|
|
//var datas= CustomAttributeData.GetCustomAttributes(taget)[0]; |
|
|
|
//cmd.GetType().GetProperty(item.Value).CustomAttributes.Append(datas); |
|
|
|
cmd.GetType().GetProperty(item.Value).SetValue(cmd,propName); |
|
|
|
} |
|
|
|
SetPropertyVisibility(cmd,item.Value,true); |
|
|
|
cmd.GetType().GetProperty(item.Value).SetValue(cmd,propName); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
SetPropertyVisibility(cmd,item.Value,false); |
|
|
|
} |
|
|
|
cmd.PropertyChanged += Cmd_PropertyChanged; |
|
|
|
PropeObject = cmd; |
|
|
|
} |
|
|
|
cmd.PropertyChanged += Cmd_PropertyChanged; |
|
|
|
PropeObject = null; |
|
|
|
PropeObject = cmd; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// 内部属性变化通知 |
|
|
|
/// </summary> |
|
|
|
/// <param name="sender"></param> |
|
|
|
/// <param name="e"></param> |
|
|
|
private void Executable_PropertyChange(object? sender,EventArgs e) |
|
|
|
{ |
|
|
|
System.Windows.Controls.Control content = CanSelectedItem as System.Windows.Controls.Control; |
|
|
|
System.Reflection.PropertyInfo info = content.GetType().GetProperty("GenerateData"); |
|
|
|
var propName = info?.GetValue(content,null); |
|
|
|
PropeObject.GetType().GetProperty("数据结果").SetValue(PropeObject,propName); |
|
|
|
|
|
|
|
|
|
|
|
DevNameList = new System.Collections.ObjectModel.ObservableCollection<string>(); |
|
|
|
DevValueList = new System.Collections.ObjectModel.ObservableCollection<string>(); |
|
|
|
Class_DataBus.GetInstance().Dic_DeviceData.Keys?.ToList().ForEach(key => { DevNameList.Add(key); }); |
|
|
|
} |
|
|
|
|
|
|
|
[Browsable(true)] |
|
|
|
public void BrowsableTrue() { } |
|
|
|
[Browsable(false)] |
|
|
|
public void BrowsableFalse() { } |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// 修改属性后 |
|
|
|
/// </summary> |
|
|
@@ -377,36 +374,46 @@ namespace BeDesignerSCADA.ViewModel |
|
|
|
} |
|
|
|
#endregion |
|
|
|
|
|
|
|
#region 设置 |
|
|
|
#region 特性控制 |
|
|
|
/// <summary> |
|
|
|
/// 设置Browsable特性的值 |
|
|
|
/// 通过反射控制属性是否可见 |
|
|
|
/// </summary> |
|
|
|
/// <param name="obj"></param> |
|
|
|
/// <param name="propertyName"></param> |
|
|
|
/// <param name="visible"></param> |
|
|
|
public void SetPropertyVisibility(object obj,string propertyName,bool visible) |
|
|
|
public static void SetPropertyVisibility(object obj,string propertyName,bool visible) |
|
|
|
{ |
|
|
|
//Type type = typeof(BrowsableAttribute); |
|
|
|
//PropertyDescriptorCollection props = TypeDescriptor.GetProperties(obj); |
|
|
|
//AttributeCollection attrs = props[propertyName].Attributes; |
|
|
|
//type.GetProperty("Browsable").SetValue(attrs[type], visible); |
|
|
|
|
|
|
|
//AttributeCollection attributes = |
|
|
|
// TypeDescriptor.GetProperties(obj)[propertyName].Attributes; |
|
|
|
//// Checks to see if the property is browsable. |
|
|
|
//BrowsableAttribute myAttribute = (BrowsableAttribute)attributes[typeof( |
|
|
|
//BrowsableAttribute)]; |
|
|
|
|
|
|
|
//if (myAttribute.Browsable) |
|
|
|
//{ |
|
|
|
// // Insert code here. |
|
|
|
//} |
|
|
|
|
|
|
|
//PropertyDescriptorCollection appSetingAttributes = TypeDescriptor.GetProperties(obj); |
|
|
|
//Type type = typeof(BrowsableAttribute); |
|
|
|
//FieldInfo fieldInfo = type.GetField("_displayName", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.CreateInstance); |
|
|
|
//fieldInfo.SetValue(appSetingAttributes["TextID"].Attributes[displayType], "修改后的文本ID"); |
|
|
|
Type type = typeof(BrowsableAttribute); |
|
|
|
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(obj); |
|
|
|
AttributeCollection attrs = props[propertyName].Attributes; |
|
|
|
FieldInfo fld = CallPrivatevariables(type,"<Browsable>k__BackingField"); |
|
|
|
// FieldInfo fld = type.GetField("Browsable",BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreReturn | BindingFlags.GetProperty); |
|
|
|
fld.SetValue(attrs[type],visible); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// 获取指定对象的指定成员变量 |
|
|
|
/// </summary> |
|
|
|
/// <typeparam name="T"></typeparam> |
|
|
|
/// <param name="obj"></param> |
|
|
|
/// <param name="name"></param> |
|
|
|
/// <returns></returns> |
|
|
|
public static FieldInfo CallPrivatevariables(Type type,string name) |
|
|
|
{ |
|
|
|
//BindingFlags flag = System.Reflection.BindingFlags.IgnoreCase | System.Reflection.BindingFlags.NonPublic; |
|
|
|
//Type type = obj.GetType(); |
|
|
|
//var fieldInfos_ = type.GetField(name, flag); |
|
|
|
var fieldInfos = (System.Reflection.FieldInfo[])((System.Reflection.TypeInfo)type).DeclaredFields; |
|
|
|
FieldInfo fieldInfo_ = null; |
|
|
|
foreach (FieldInfo fieldInfo in fieldInfos) |
|
|
|
{ |
|
|
|
if (fieldInfo.Name == name) |
|
|
|
{ |
|
|
|
return fieldInfo;// (T)fieldInfo.GetValue(obj); |
|
|
|
} |
|
|
|
} |
|
|
|
//FieldInfo fieldInfo = type.GetField(name, flag); |
|
|
|
return fieldInfo_;// (T)fieldInfo_.GetValue(obj); |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// 设置Category特性的值 |
|
|
@@ -477,7 +484,7 @@ namespace BeDesignerSCADA.ViewModel |
|
|
|
private string _文本1; |
|
|
|
private object _变量; |
|
|
|
|
|
|
|
[Category("基本属性"), Description("Name"), Browsable(true), PropertyOrder(1)] |
|
|
|
[Category("基本属性"), Description("Name"), Browsable(false), PropertyOrder(1)] |
|
|
|
public string 名称 |
|
|
|
{ |
|
|
|
get |
|
|
|