Best NBi code snippet using NBi.Core.Query.DbTypeBuilder.TryParseEquivalent
DbTypeBuilder.cs
Source:DbTypeBuilder.cs
...2122 DbType value;23 if (!Enum.TryParse<DbType>(typeName, true, out value))24 {25 if (!TryParseEquivalent(typeName, out value))26 {27 throw new ArgumentException(String.Format("Unknown type for database: {0}", typeName), "name");28 }29 }30 result.Value = value;3132 if (CanDefinePrecision(value))33 {34 byte precison;35 if (TryDefinePrecision(name, out precison))36 result.Precision = precison;37 }3839 if (CanDefineSize(value))40 {41 int size;42 if (TryDefineSize(name, out size))43 result.Size = size;44 }4546 return result;47 }4849 private bool TryDefineSize(string name, out int size)50 {51 size = 0;52 var start = name.IndexOf("(");53 var end = name.IndexOf(",");54 if (end == -1)55 end = name.IndexOf(")");5657 if (start == -1 || end == -1)58 return false;5960 var valueString = name.Substring(start + 1, end - start -1);6162 return int.TryParse(valueString, out size);63 }6465 private bool CanDefineSize(DbType value)66 {67 if (value == DbType.Decimal)68 return true;6970 return Enum.GetName(typeof(DbType), value).Contains("String");71 }7273 private bool TryDefinePrecision(string name, out byte precison)74 {75 precison = 0;76 var start = name.IndexOf(",");77 var end = name.IndexOf(")");7879 if (start == -1 || end == -1)80 return false;8182 var valueString = name.Substring(start + 1, end - start - 1);8384 return byte.TryParse(valueString, out precison);8586 }8788 private bool CanDefinePrecision(DbType value)89 {90 return (value == DbType.Decimal);91 }9293 private bool TryParseEquivalent(string name, out DbType value)94 {95 value = DbType.Object;96 SqlDbType sqlValue = SqlDbType.Variant;97 if (Enum.TryParse<SqlDbType>(name, true, out sqlValue))98 {99 switch (sqlValue)100 {101 //Boolean102 case SqlDbType.Bit: value = DbType.Boolean;103 break;104 //Integers105 case SqlDbType.TinyInt: value = DbType.Byte;106 break;107 case SqlDbType.SmallInt: value = DbType.Int16;
...
TryParseEquivalent
Using AI Code Generation
1using System;2using NBi.Core.Query;3{4 public static void Main()5 {6 var dbTypeBuilder = new DbTypeBuilder();7 var dbType = dbTypeBuilder.TryParseEquivalent("varchar");8 Console.WriteLine(dbType);9 }10}
TryParseEquivalent
Using AI Code Generation
1using System;2using NBi.Core.Query;3{4 {5 static void Main(string[] args)6 {7 if (DbTypeBuilder.TryParseEquivalent("System.Data.DbType.Int32,System.Data", out var dbType))8 {9 Console.WriteLine(dbType.ToString());10 }11 {12 Console.WriteLine("Unab
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!