예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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 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);
            }
예제 #5
0
        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));
                }
            }));
        }