public OptionValueProcessorInput(string expression,
                                  OptionValueProcessorKind kind,
                                  ITypeNameResolver resolver)
 {
     Expression = expression;
     Kind       = kind;
     Resolver   = resolver;
 }
示例#2
0
            public PropInfo GetPropertyTypeName(OptionValueProcessorKind kind, ITypeNameResolver res,
                                                NamespaceAndName enumTypeName)
            {
                var    v = ValueType.FixedType;
                string elementName;

                if (v != null)
                {
                    switch (kind)
                    {
                    case OptionValueProcessorKind.List:
                    case OptionValueProcessorKind.Dictionary:
                        elementName = res.GetTypeName(v);
                        break;

                    case OptionValueProcessorKind.SingleValue:
                        if (v.IsValueType)
                        {
                            v = typeof(Nullable <>).MakeGenericType(v);
                        }
                        elementName = res.GetTypeName(v);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(kind), kind, null);
                    }
                }
                else
                {
                    var suffix = kind == OptionValueProcessorKind.SingleValue ? "?" : ";";
                    elementName = res.GetTypeName(enumTypeName) + suffix;
                }

                var tqq = new PropInfo(elementName);

                switch (kind)
                {
                case OptionValueProcessorKind.Dictionary:
                    return(tqq.MakeDict(res));

                case OptionValueProcessorKind.SingleValue:
                    return(tqq);

                case OptionValueProcessorKind.List:
                    return(tqq.MakeList(res));

                default:
                    throw new ArgumentOutOfRangeException(nameof(kind), kind, null);
                }
            }
示例#3
0
            public string GetCondition(string expression, OptionValueProcessorKind kind)
            {
                switch (kind)
                {
                case OptionValueProcessorKind.SingleValue:
                {
                    var type = ValueType.FixedType;
                    if (type == typeof(string))
                    {
                        return($"!string.IsNullOrEmpty({expression})");
                    }
                    return($"!({expression} is null)");
                }

                case OptionValueProcessorKind.Dictionary:
                case OptionValueProcessorKind.List:
                    return(expression.CodeHasElements());

                default:
                    throw new ArgumentOutOfRangeException(nameof(kind), kind, null);
                }
            }