コード例 #1
0
        public void LoadFromString(
      String              AString,
      Char                ASeparator,
      TLoadValueCondition ALoadValueCondition = TLoadValueCondition.lvcAlways,
      Char                AParamPrefix        = '\0',
      TParams             AParams             = null
    )
        {
            if (String.IsNullOrEmpty(AString)) return;
              //TLoadValueCondition LLoadValueCondition = Pub.LoadValueConditionParser(ALoadValueCondition);

              Pub.NamedItemsParser Parser =
            new Pub.NamedItemsParser
            (
              AString,
              new Char[] { ASeparator, '\r', '\n' },
              true
             );

              while (Parser.MoveNext())
              {
            try
            {
              String LName  = Parser.Current.Name.Trim();
              String SValue = Parser.Current.Value;
              if(Parser.Current.Quote == '\0')
            SValue = SValue.Trim();

              Object LValue;
              if
              (
            AParamPrefix != '\0'
                && Parser.Current.Quote == '\0'
                //&& String.IsNullOrEmpty(Parser.Current.CastAs)
                && !String.IsNullOrEmpty(SValue)
                && SValue[0] == AParamPrefix
              )
              {
            if (AParams != null && AParams.FData.TryGetValue(SValue.Substring(1), out LValue))
            {
              if (ALoadValueCondition != TLoadValueCondition.lvcIfNotPresent || !FData.ContainsKey(LName))
                AddParam(LName, LValue);
            }
            else if (ALoadValueCondition == TLoadValueCondition.lvcAlways)
              AddParam(LName, DBNull.Value);
              }
              else if (ALoadValueCondition != TLoadValueCondition.lvcIfNotPresent || !FData.ContainsKey(LName))
              {
            // Парсим значение
            SqlDbType LSqlDbType = Sql.TypeFromString(Parser.Current.CastAs);

            if (LSqlDbType == SqlDbType.Udt)
              LValue = new SqlUdt(Parser.Current.CastAs, SValue);
            else
              LValue = Sql.ValueFromString(SValue, LSqlDbType, Sql.ValueDbStyle.SQL);
            AddParam(LName, LValue);
              }

            }
            catch (Exception E)
            {
              throw new Exception(String.Format("Неверно задано значение TParams '{0}': {1}", AString, E.Message));
            }
              }
        }
コード例 #2
0
        /// <summary>
        /// Удаляет параметры из списка параметров
        /// </summary>
        /// <param name="name"></param>
        protected void Load(TParams ASource, String AAliases, TLoadValueCondition ALoadValueCondition = TLoadValueCondition.lvcAlways)
        {
            if (ASource == null) return;

              String LTarget, LSource;
              foreach (String LAlias in AAliases.Split(';'))
              {
            int LEqual = LAlias.IndexOf('=');
            if (LEqual == -1)
            {
              LTarget = LAlias;
              LSource = LAlias;
            }
            else
            {
              LTarget = LAlias.Substring(0, LEqual);
              LSource = LAlias.Substring(LEqual + 1);
            }

            Object LValue;
            if (ASource.FData.TryGetValue(LSource, out LValue))
            {
              if (ALoadValueCondition != TLoadValueCondition.lvcIfNotPresent || !FData.ContainsKey(LTarget))
            AddParam(LTarget, LValue);
            }
            else if (ALoadValueCondition == TLoadValueCondition.lvcAlways)
              AddParam(LTarget, DBNull.Value);
              }
        }