private void SetValue(object value) { if (value == null) { _value = null; _nodeType = PluginTreeNodeType.Empty; this.Plugin = null; return; } if (typeof(Builtin).IsAssignableFrom(value.GetType())) { this.SetBuiltin((Builtin)value); } else { _value = value; _nodeType = PluginTreeNodeType.Custom; this.Plugin = null; var properties = _properties; if (properties != null && properties.Count > 0) { foreach (PluginExtendedProperty property in properties) { Type propertyType; Reflection.MemberAccess.TryGetMemberType(_value, property.Name, out propertyType); Reflection.MemberAccess.TrySetMemberValue(_value, property.Name, property.GetValue(propertyType)); } } } }
private void SetValue(object value) { if (value == null) { _value = null; _nodeType = PluginTreeNodeType.Empty; this.Plugin = null; return; } if (TypeExtension.IsAssignableFrom(typeof(Builtin), value.GetType())) { this.SetBuiltin((Builtin)value); } else { _value = value; _nodeType = PluginTreeNodeType.Custom; this.Plugin = null; var properties = _properties; if (properties != null && properties.Count > 0) { foreach (PluginExtendedProperty property in properties) { var propertyType = Tiandao.Common.Converter.GetMemberType(_value, property.Name); Tiandao.Common.Converter.SetValue(_value, property.Name, property.GetValue(propertyType)); } } } }
private void SetValue(object value) { if (value == null) { _value = null; _nodeType = PluginTreeNodeType.Empty; this.Plugin = null; return; } if (value is Builtin builtin) { if (builtin.Node != null) { throw new InvalidOperationException(); } //将构建的所属节点指向本节点 builtin.Node = this; //更新当前节点的属性值 _value = builtin; _nodeType = PluginTreeNodeType.Builtin; this.Plugin = builtin.Plugin; } else { _value = value; _nodeType = PluginTreeNodeType.Custom; this.Plugin = null; var properties = _properties; if (properties != null && properties.Count > 0) { foreach (PluginExtendedProperty property in properties) { //Reflection.MemberAccess.TryGetMemberType(_value, property.Name, out var propertyType, out _); //Reflection.MemberAccess.TrySetMemberValue(_value, property.Name, property.GetValue(propertyType)); Reflection.Reflector.SetValue(ref _value, property.Name, property.GetValue(null)); } } } }
private void SetBuiltin(Builtin builtin) { if (builtin == null) { throw new ArgumentNullException("builtin"); } if (builtin.Node != null) { throw new InvalidOperationException(); } //将构建的所属节点指向本节点 builtin.Node = this; //更新当前节点的属性值 _value = builtin; _nodeType = PluginTreeNodeType.Builtin; this.Plugin = builtin.Plugin; }