/// <summary> /// Converts the value to its directory information object equivalent. /// </summary> /// <param name="mode">The parameter resolving mode.</param> /// <returns>The result value converted.</returns> public DirectoryInfo ParseToDirectoryInfo(ParameterModes mode = ParameterModes.First) { var v = Value(mode); if (string.IsNullOrWhiteSpace(v)) { return(null); } try { return(new DirectoryInfo(v)); } catch (ArgumentException) { } catch (SecurityException) { } catch (UnauthorizedAccessException) { } catch (PathTooLongException) { } catch (NotSupportedException) { } catch (DirectoryNotFoundException) { } return(null); }
/// <summary> /// Converts the value to its URI equivalent. /// </summary> /// <param name="mode">The parameter resolving mode.</param> /// <returns>The result value converted.</returns> public Uri ParseToUri(ParameterModes mode = ParameterModes.First) { var v = Value(mode); if (string.IsNullOrWhiteSpace(v)) { return(null); } return(new Uri(v)); }
/// <summary> /// Converts the value to its boolean equivalent. /// </summary> /// <param name="result">The result value converted when this method returns.</param> /// <param name="mode">The parameter resolving mode.</param> /// <returns>true if the value was converted successfully; otherwise, false.</returns> public bool TryToParse(out bool result, ParameterModes mode = ParameterModes.First) { var str = Value(mode); if (!string.IsNullOrWhiteSpace(str)) { return(bool.TryParse(str, out result)); } result = true; return(true); }
/// <summary> /// Gets the words of the value of a specific parameter matched the key. /// </summary> /// <param name="mode">The parameter getting mode.</param> /// <returns>The words of the value of a specific parameter.</returns> public IReadOnlyList <string> Values(ParameterModes mode = ParameterModes.First) { switch (mode) { case ParameterModes.All: return(MergedValues); case ParameterModes.Last: return(LastValues); default: return(FirstValues); } }
/// <summary> /// Gets the string value of a specific parameter matched the key. /// </summary> /// <param name="mode">The parameter getting mode.</param> /// <returns>A string value of a specific parameter.</returns> public string Value(ParameterModes mode = ParameterModes.First) { switch (mode) { case ParameterModes.All: return(MergedValue); case ParameterModes.Last: return(LastValue); default: return(FirstValue); } }
public static (int opCode, ParameterModes[] parameterModes) CalculateOpCodeAndParameterModes(int i) { // HACK: always 3 parameter modes for now var s = i.ToString("D5", CultureInfo.InvariantCulture); var opCode = int.Parse(s.Substring(3)); var parameterModes = new ParameterModes[3]; parameterModes[0] = (ParameterModes)int.Parse(s[2].ToString()); parameterModes[1] = (ParameterModes)int.Parse(s[1].ToString()); parameterModes[2] = (ParameterModes)int.Parse(s[0].ToString()); return(opCode, parameterModes); }
/// <summary> /// This sub creates a new parameter. /// </summary> /// <param name="paramName">Name of the parameter.</param> /// <param name="paramValue">Value for the parameter.</param> /// <param name="paramType">Type of the parameter.</param> /// <remarks> /// <para> /// Each parameter has an identifying name and an associated value. /// You can automatically bind a parameter to SQL and PL/SQL statements of other objects, /// by using the parameter’s name as a placeholder (@Name) in the SQL statement. /// Such use of parameters can simplify dynamic queries and increase program performance. /// </para> /// <para> /// Although each parameter has a name the mapping to the sql statement is done by position. /// That means if you have several parameters in your sql statement the sequence of all distinct /// parameters must match the sequence of your parameters. /// </para> /// <para> /// For example: /// SELECT * FROM TABLE WHERE COLUMN1 = @P1 AND COLUMN2 = @P2 /// </para> /// <para> /// Now your parameters must be added in the sequence @P1 and then @P2. /// If you would add them as @P2 and then @P1 the value of @P2 would be matched to @P1! /// </para> /// <para> /// If you set an incorrect <paramref name=" paramType "></paramref>, such as /// <see cref="ParameterModes.PARM_INOUT"></see> /// for a stored procedure parameter type IN, this can result in errors. /// In other words <see cref="ParameterModes.PARM_INOUT"></see> means "for IN OUT parameters only". /// It does not mean that you should use the parameter against one stored procedure that has an IN parameter /// and then use it in another that has an OUT parameter. /// In such a case you should use two parameters. /// </para> /// <para> /// Errors caused in this way are rare, but in the case of parameter-related errors, you should verify /// that the <paramref name=" paramType "></paramref> is correct. /// </para> /// <para> /// Don't forget to remove the parameter later on with <see cref="RemoveParameter "></see>, because a parameter /// name is unique within the whole session and trying to create some with an used name will cause an error. /// </para> /// <example> /// This example shows how to use parameters: /// <code lang="C#"> /// private DASAccess.DASDataTable Query(DAS das, string param1, long param2) /// { /// var dt = das.CreateDASDataTable("Table"); /// const string PARAM1 = "@Param1"; /// const string PARAM2 = "@Param2"; /// /// string sql = String.Format(String.Concat(dt.BaseSQL, " WHERE t.COL1 = {0} AND t.COL2 = {1}", PARAM1, PARAM2)); /// /// try /// { /// das.AddParameter(PARAM1, param1, DAS.ParameterModes.PARM_IN, DAS.ServerTypes.STRING); /// das.AddParameter(PARAM2, param2, DAS.ParameterModes.PARM_IN, DAS.ServerTypes.NUMBER); /// /// das.FillDataTable(ref dt, sql); /// } /// finally /// { /// das.RemoveParameter(PARAM1); /// das.RemoveParameter(PARAM2); /// } /// /// return dt; /// } /// </code> /// </example> /// </remarks> /// <exception cref="NotConnectedException">Thrown when there is no established connection.</exception> public void AddParameter(string paramName, object paramValue, ParameterModes paramType) { if (IsConnected) { DbParameter param = _providerFactory.CreateParameter(); param.Direction = (ParameterDirection)paramType; param.ParameterName = paramName.StartsWith("@") ? paramName : string.Concat("@", paramName); param.Value = paramValue; _parameters.Add(param); } else { throw new NotConnectedException(); } }
/// <summary> /// This sub creates a new parameter. /// </summary> /// <param name="paramName">Name of the parameter.</param> /// <param name="paramValue">Value for the parameter.</param> /// <param name="paramType">Type of the parameter.</param> /// <param name="serverType">ServerType of the parameter.</param> /// <remarks> /// <para> /// Each parameter has an identifying name and an associated value. /// You can automatically bind a parameter to SQL and PL/SQL statements of other objects, /// by using the parameter’s name as a placeholder (@Name) in the SQL statement. /// Such use of parameters can simplify dynamic queries and increase program performance. /// </para> /// <para> /// Although each parameter has a name the mapping to the sql statement is done by position. /// That means if you have several parameters in your sql statement the sequence of all distinct /// parameters must match the sequence of your parameters. /// </para> /// <para> /// For example: /// SELECT * FROM TABLE WHERE COLUMN1 = @P1 AND COLUMN2 = @P2 /// </para> /// <para> /// Now your parameters must be added in the sequence @P1 and then @P2. /// If you would add them as @P2 and then @P1 the value of @P2 would be matched to @P1! /// </para> /// <para> /// If you set an incorrect <paramref name=" paramType "></paramref>, such as /// <see cref="ParameterModes.PARM_INOUT"></see> /// for a stored procedure parameter type IN, this can result in errors. /// In other words <see cref="ParameterModes.PARM_INOUT"></see> means "for IN OUT parameters only". /// It does not mean that you should use the parameter against one stored procedure that has an IN parameter /// and then use it in another that has an OUT parameter. /// In such a case you should use two parameters. /// Errors caused in this way are rare, but in the case of parameter-related errors, you should verify /// that the <paramref name=" paramType "></paramref> is correct. /// </para> /// <para> /// Don't forget to remove the parameter later on with <see cref="RemoveParameter "></see>, because a parameter /// name is unique within the whole session and trying to create some with an used name will cause an error. /// </para> /// <example> /// This example shows how to use parameters: /// <code lang="C#"> /// private DASAccess.DASDataTable Query(DAS das, string param1, long param2) /// { /// var dt = das.CreateDASDataTable("Table"); /// const string PARAM1 = "@Param1"; /// const string PARAM2 = "@Param2"; /// /// string sql = String.Format(String.Concat(dt.BaseSQL, " WHERE t.COL1 = {0} AND t.COL2 = {1}", PARAM1, PARAM2)); /// /// try /// { /// das.AddParameter(PARAM1, param1, DAS.ParameterModes.PARM_IN, DAS.ServerTypes.STRING); /// das.AddParameter(PARAM2, param2, DAS.ParameterModes.PARM_IN, DAS.ServerTypes.NUMBER); /// /// das.FillDataTable(ref dt, sql); /// } /// finally /// { /// das.RemoveParameter(PARAM1); /// das.RemoveParameter(PARAM2); /// } /// /// return dt; /// } /// </code> /// </example> /// </remarks> /// <exception cref="NotConnectedException">Thrown when there is no established connection.</exception> public void AddParameter(string paramName, object paramValue, ParameterModes paramType, ServerTypes serverType) { if (IsConnected) { DbParameter param = _providerFactory.CreateParameter(); param.Direction = (ParameterDirection)paramType; param.ParameterName = paramName.StartsWith("@") ? paramName : string.Concat("@", paramName); switch (serverType) { case ServerTypes.DATE: param.DbType = DbType.DateTime; param.Value = paramValue; break; case ServerTypes.NUMBER: int variable; if (Int32.TryParse(paramValue.ToString(), out variable)) { param.DbType = DbType.Int32; param.Value = variable; } else { param.DbType = DbType.Double; param.Value = Convert.ToDouble(paramValue); } break; case ServerTypes.STRING: param.DbType = DbType.String; param.Value = paramValue; break; } _parameters.Add(param); } else { throw new NotConnectedException(); } }
private void PopulateParametermodes() { for (int i = 2; i >= 0; i--) // Starting from position 2, step back through 1 and 0. { switch (_stringOpcode[i]) { case '0': ParameterModes.Add(ParameterMode.Position); break; case '1': ParameterModes.Add(ParameterMode.Immediate); break; case '2': ParameterModes.Add(ParameterMode.Relative); break; default: throw new ArgumentException("Attempted to use an invalid opcode parameter mode"); } } }
/// <summary> /// Converts the value to its date and time with offset relative to UTC equivalent. /// </summary> /// <param name="result">The result value converted when this method returns.</param> /// <param name="mode">The parameter resolving mode.</param> /// <returns>true if the value was converted successfully; otherwise, false.</returns> public bool TryToParse(out DateTimeOffset result, ParameterModes mode = ParameterModes.First) { return(DateTimeOffset.TryParse(Value(mode), out result)); }
/// <summary> /// Converts the value to its GUID equivalent. /// </summary> /// <param name="result">The result value converted when this method returns.</param> /// <param name="mode">The parameter resolving mode.</param> /// <returns>true if the value was converted successfully; otherwise, false.</returns> public bool TryToParse(out Guid result, ParameterModes mode = ParameterModes.First) { return(Guid.TryParse(Value(mode), out result)); }
/// <summary> /// Converts the value to its double-precision floating-point number equivalent. /// </summary> /// <param name="result">The result value converted when this method returns.</param> /// <param name="mode">The parameter resolving mode.</param> /// <returns>true if the value was converted successfully; otherwise, false.</returns> public bool TryToParse(out double result, ParameterModes mode = ParameterModes.First) { return(double.TryParse(Value(mode), out result)); }