예제 #1
0
        public DataValidationException Validate(object data)
        {
            DataValidationException exception = null;

            foreach (IValidator ValueConfig in ValueConfigs)
            {
                exception = ValueConfig.Validate(data as Data);
                if (exception != null)
                {
                    return(exception);
                }
            }
            return(exception);
        }
예제 #2
0
 protected virtual object GetNotFieldValue(BindingFlags bindFlag)
 {
     string[] config = ValueConfig.Split(',');
     if (config.Length == 3)
     {
         Assembly assembly = Assembly.Load(config[2]);
         Type     type     = assembly.GetType(config[1]);
         _value = type.InvokeMember(config[0], bindFlag, null, null, null);
     }
     else
     {
         Type type = Type.GetType(config[1]);
         _value = type.InvokeMember(config[0], bindFlag, null, null, null);
     }
     return(_value);
 }
        public void ProcessSecretValue(bool firstRun, bool isArray, PropertyType type, string typeDeclaration, string value, string valueDeclaration)
        {
            var pair        = new KeyValuePair <string, string>(TestKey, value);
            var generator   = GetGenerator();
            var valueConfig = new ValueConfig
            {
                Name         = TestKey,
                PropertyType = type,
                IsArray      = isArray
            };
            var secretsConfig = new SettingsConfig {
                Properties = new List <ValueConfig> {
                    valueConfig
                }
            };
            var output = generator.ProcessSecret(pair, secretsConfig, firstRun);

            Assert.Contains($"{typeDeclaration} {TestKey}", output);
            Assert.Contains(valueDeclaration, output);
        }
예제 #4
0
        private void AddProperty(ref ClassBuilder builder, IDictionary <string, string> secrets, ValueConfig valueConfig, IEnumerable <INamedTypeSymbol> interfaces, string delimeter)
        {
            if (!secrets.ContainsKey(valueConfig.Name))
            {
                return;
            }

            var value           = secrets[valueConfig.Name];
            var output          = string.Empty;
            var isArray         = valueConfig.IsArray.HasValue ? valueConfig.IsArray.Value : false;
            var mapping         = valueConfig.PropertyType.GetPropertyTypeMapping();
            var valueHandler    = mapping.Handler;
            var typeDeclaration = mapping.Type.GetStandardTypeName();
            var type            = isArray ? mapping.Type.MakeArrayType() : mapping.Type;
            var propBuilder     = builder.AddProperty(valueConfig.Name)
                                  .SetType(type)
                                  .MakePublicProperty();

            var symbol = interfaces.SelectMany(x => x.GetMembers())
                         .OfType <IPropertySymbol>()
                         .Where(x => x.Name == valueConfig.Name)
                         .FirstOrDefault();

            var valueType = GetValueType(value, valueConfig.PropertyType);

            if (value is null || value.ToLower() == "null" || value.ToLower() == "default")
            {
                if (type == typeof(bool) && !isArray)
                {
                    output = bool.FalseString.ToLower();
                }
                else if (isArray)
                {
                    output = $"global::System.Array.Empty<{typeDeclaration}>()";
                }
                else
                {
                    output = "default";
                }
            }