protected virtual object CreateValue() { if (this.Type == null) { return(null); } try { object result = PluginUtility.BuildType(this.Type, (Type parameterType, string parameterName, out object parameterValue) => { return(PluginUtility.ObtainParameter(this.Plugin, parameterType, parameterName, out parameterValue)); }); if (result == null) { throw new PluginException(string.Format("Can not build instance of '{0}' type, Maybe that's cause type-generator not found matched constructor with parameters. in '{1}' plugin.", this.Type.FullName, this.Plugin)); } return(result); } catch (Exception ex) { throw new PluginException(string.Format("Occurred an exception on create a fixed-element instance of '{0}' type, at '{1}' plugin.", this.Type.FullName, this.Plugin), ex); } }
internal Builtin CreateBuiltin(string builderName, string name) { if (string.IsNullOrWhiteSpace(name)) { name = "$" + builderName + "-" + PluginUtility.GetAnonymousId(builderName).ToString(); } return(new Builtin(builderName, name, this)); }
internal static object BuildType(string typeName, Builtin builtin) { Type type = PluginUtility.GetType(typeName); if (type == null) { throw new PluginException(string.Format("Can not get type from '{0}' text for '{1}' builtin.", typeName, builtin)); } try { object result = BuildType(type, (Type parameterType, string parameterName, out object parameterValue) => { if (parameterType == typeof(Builtin)) { parameterValue = builtin; return(true); } if (parameterType == typeof(PluginTreeNode)) { parameterValue = builtin.Node; return(true); } if (parameterType == typeof(string) && string.Equals(parameterName, "name", StringComparison.OrdinalIgnoreCase)) { parameterValue = builtin.Name; return(true); } if (TypeExtension.IsAssignableFrom(typeof(Tiandao.Services.IServiceProvider), parameterType)) { parameterValue = FindServiceProvider(builtin); return(true); } return(ObtainParameter(builtin.Plugin, parameterType, parameterName, out parameterValue)); }); if (result == null) { throw new PluginException(string.Format("Can not build instance of '{0}' type, Maybe that's cause type-generator not found matched constructor with parameters. in '{1}' builtin.", type.FullName, builtin)); } //注入依赖属性 InjectProperties(result, builtin); return(result); } catch (Exception ex) { throw new PluginException(string.Format("Occurred an exception on create a builtin instance of '{0}' type, at '{1}' builtin.", type.FullName, builtin), ex); } }
public object GetValue(Type valueType, object defaultValue) { if (_valueNode == null) { return(PluginUtility.ResolveValue(_owner, _rawValue, _name, valueType, defaultValue)); } var result = _valueNode.UnwrapValue(ObtainMode.Auto, _owner); if (valueType != null) { result = Tiandao.Common.Converter.ConvertValue(result, valueType, defaultValue); } return(result); }
public object GetPropertyValue(string propertyName, Type valueType, object defaultValue = null) { if (string.IsNullOrWhiteSpace(propertyName)) { throw new ArgumentNullException("propertyName"); } string rawValue; if (_properties.TryGetValue(propertyName, out rawValue)) { return(PluginUtility.ResolveValue(_builtin, rawValue, propertyName, valueType, defaultValue)); } return(defaultValue); }
public T GetPropertyValue <T>(string propertyName, T defaultValue = default(T)) { if (string.IsNullOrWhiteSpace(propertyName)) { throw new ArgumentNullException("propertyName"); } string rawValue; if (_properties.TryGetValue(propertyName, out rawValue)) { return(Converter.ConvertValue <T>(PluginUtility.ResolveValue(_builtin, rawValue, propertyName, typeof(T), defaultValue))); } return(defaultValue); }
public static object BuildBuiltin(Builtin builtin, IEnumerable <string> ignoredProperties = null) { if (builtin == null) { throw new ArgumentNullException("builtin"); } var result = PluginUtility.BuildType(builtin); //设置更新目标对象的属性集 if (result != null) { UpdateProperties(result, builtin, ignoredProperties); } return(result); }
public object GetValue(Type valueType) { var original = System.Threading.Interlocked.CompareExchange(ref _evaluateValueRequired, 1, 0); if (original == 0) { if (valueType != null && string.IsNullOrEmpty(_parameterTypeName)) { _value = PluginUtility.ResolveValue(_constructor.Builtin, _rawValue, null, valueType, null); } else { _value = PluginUtility.ResolveValue(_constructor.Builtin, _rawValue, null, this.ParameterType, null); } } return(_value); }
public T Populate <T>(Func <T> creator = null) { var dictionary = DictionaryExtension.ToDictionary <string, object>((System.Collections.IDictionary)_properties); return(DictionarySerializer.Default.Deserialize <T>((System.Collections.IDictionary)dictionary, creator, ctx => { if (ctx.Direction == Converter.ObjectResolvingDirection.Get) { ctx.Handled = false; return; } var text = ctx.Value as string; if (text != null) { ctx.Value = PluginUtility.ResolveValue(_builtin, text, ctx.MemberName, ctx.MemberType, Converter.GetDefaultValue(ctx.MemberType)); } })); }