private static string GetValue(Type cellType, int rowIndex, int columnIndex) { string value; if (NumericTypes.IsNumeric(cellType)) { value = ((9 * rowIndex) + columnIndex).ToString(); } else if (cellType.Name == "String") { value = string.Format("This is a string at {0},{1}.", rowIndex, columnIndex); } else if (cellType.Name == "DateTime") { DateTime temp = new DateTime(2000, 1, 1); temp = temp.AddDays(rowIndex); temp = temp.AddMonths(columnIndex); value = temp.ToShortDateString(); } else { value = string.Format("Unknown type {0}", cellType.Name); } return(value); }
public void NumericConstructorTest1() { NumericTypes type = new NumericTypes(); // TODO: Initialize to an appropriate value Nullable<int> precision = new Nullable<int>(); // TODO: Initialize to an appropriate value Numeric target = new Numeric(type, precision); Assert.Inconclusive("TODO: Implement code to verify target"); }
public void ConvertNumericConstructorTest1() { NumericTypes dataType = new NumericTypes(); // TODO: Initialize to an appropriate value Expression expression = null; // TODO: Initialize to an appropriate value ConvertNumeric target = new ConvertNumeric(dataType, expression); Assert.Inconclusive("TODO: Implement code to verify target"); }
internal static List <Field> GetFields(Type type) { #if !STANDALONE if (type.Is <Entity>()) { return(EntityType.FromNativeType(type).Fields.Select(x => new Field() { Name = x.Name, Get = new Func <object, object>(y => { var ent = (Entity)y; return x.IsStoredIn(ent) ? x.GetStoredValueDirect(ent) : null; }), Type = x.FieldType.NativeType }).ToList()); } ; #endif var emptyArray = new object[] { }; var fields = type.GetTypeInfo().IsPrimitive || type.GetTypeInfo().IsEnum || type == typeof(string) ? new[] { new Field { Name = "Value", Get = new Func <object, object>(y => y), Type = type } }.ToList() : type.GetFields(BindingFlags.Instance | BindingFlags.Public) #if !STANDALONE .Where(x => x.GetCustomAttribute <RestrictedAccessAttribute>() == null) #endif .Select(x => new Field { Name = x.Name, Member = x, Get = ReflectionHelper.GetGetter <object, object>(x), Type = x.FieldType }) .Union(type.GetProperties(BindingFlags.Instance | BindingFlags.Public) .Where(x => x.GetIndexParameters().Length == 0 #if !STANDALONE && x.DeclaringType != typeof(Entity) && x.GetMethod.GetCustomAttribute <RestrictedAccessAttribute>() == null #endif ) .Select(x => new Field { Name = x.Name, Member = x, Get = ReflectionHelper.GetGetter <object, object>(x), Type = x.PropertyType })) .ToList(); foreach (var field in fields) { var t = field.Type; if (t.GetTypeInfo().IsGenericType&& t.GetGenericTypeDefinition() == typeof(Nullable <>)) { t = Nullable.GetUnderlyingType(t); } field.IsNumeric = NumericTypes.Contains(t); } return(fields); }
public static string BuildElasticMapping <T>(string elasticType, IEnumerable <ElasticMappingConfigObject> analyzerConfiguration = null) { return(new MapBuilder <T>() .RootObject(elasticType, ro => ro .Properties(pr => { typeof(T).GetProperties().ToList().ForEach(ord => { if (ord.PropertyType == typeof(Guid)) { pr.MultiField(ord.Name, mfp => mfp.Fields(f => f .String(ord.Name, sp => sp.Analyzer("caseinsensitive")))); } else if (ord.PropertyType == typeof(String)) { var indexAnalyzer = "autocomplete"; var searchAnalyzer = DefaultAnalyzers.standard; if (analyzerConfiguration != null && analyzerConfiguration.Any()) { var fieldCfg = analyzerConfiguration.SingleOrDefault(t => t.fieldName == ord.Name); if (fieldCfg != null) { indexAnalyzer = fieldCfg.analyzerName; if (!String.IsNullOrEmpty(fieldCfg.searchAnalyzer)) { searchAnalyzer = (DefaultAnalyzers)Enum.Parse(typeof(DefaultAnalyzers), fieldCfg.searchAnalyzer); } } } pr.MultiField(ord.Name, mfp => mfp.Fields(f => f .String(ord.Name, sp => sp.IndexAnalyzer(indexAnalyzer).SearchAnalyzer(searchAnalyzer)) .String("lower_case_sort", sp => sp.Analyzer("caseinsensitive")))); } else if (ord.PropertyType == typeof(DateTime)) { pr.MultiField(ord.Name, mfp => mfp.Fields(f => f.Date(ord.Name))); } else if (ord.PropertyType == typeof(Boolean)) { pr.MultiField(ord.Name, mfp => mfp.Fields(f => f.Boolean(ord.Name))); } else if (NumericTypes.Contains(ord.PropertyType)) { pr.MultiField(ord.Name, mfp => mfp.Fields(f => f.Number(ord.Name))); } }); return pr; })).BuildBeautified()); }
public static dynamic GetNumeric(NumericTypes type) { switch (type) { case NumericTypes.INT: { while (true) { try { Console.Write(">> "); var data = Convert.ToInt32(Console.ReadLine()); return(data); } catch (Exception) { LoggerPublisher.OnLogError("Input must be numeric value!"); } } } case NumericTypes.DOUBLE: { while (true) { try { Console.Write(">> "); var data = Convert.ToDouble(Console.ReadLine()); return(data); } catch (Exception) { LoggerPublisher.OnLogError("Input must be numeric value!"); } } } default: { throw new InvalidOperationException("Invalid type!"); } } }
static void MyNumericExamples() { NumericTypes myTypes = new NumericTypes(); myTypes.GetSomeType(); int something = myTypes.ConvertFloatToInt(35.9F); Console.WriteLine(something); Console.WriteLine(myTypes.LongFromInt(5600)); myTypes.BasicMath(); myTypes.CheckOperators(); myTypes.IncrementDecrement(); myTypes.SpecialValues(); myTypes.comparisonOperators(); }
private bool IsWideningPromotion(IType targeType, IType sourceType) { var externalTargetType = targeType as ExternalType; if (null == externalTargetType) { return(false); } var externalSourceType = sourceType as ExternalType; if (null == externalSourceType) { return(false); } return(NumericTypes.IsWideningPromotion(externalTargetType.ActualType, externalSourceType.ActualType)); }
private static string DeriveJsonTypeFromType(Type dataType) { if (NumericTypes.Contains(dataType)) { return("number"); } switch (dataType.Name) { case "Boolean": return("boolean"); case "DateTime": return("date"); case "String": return("string"); default: return("object"); } ; }
private void CoerceTypes(string operatorName, ref Expression leftExpr, ref Expression rightExpr) { if (leftExpr.Type != rightExpr.Type) { var leftType = TypeFns.GetNonNullableType(leftExpr.Type); var rightType = TypeFns.GetNonNullableType(rightExpr.Type); if (leftType == typeof(String)) { ConvertExpr(ref rightExpr, ref leftExpr); } else if (rightType == typeof(String)) { ConvertExpr(ref leftExpr, ref rightExpr); } else if ((TypeFns.IsNumericType(leftType) || TypeFns.IsEnumType(leftType)) && (TypeFns.IsNumericType(rightType) || TypeFns.IsEnumType(rightType))) { var leftIx = NumericTypes.IndexOf(leftType); var rightIx = NumericTypes.IndexOf(rightType); if (leftIx < rightIx) { ConvertExpr(ref leftExpr, ref rightExpr); } else { ConvertExpr(ref rightExpr, ref leftExpr); } } else if (leftType == typeof(Guid) || leftType == typeof(DateTime) || leftType == typeof(Boolean) || leftType == typeof(TimeSpan) || TypeFns.IsNumericType(leftType) || TypeFns.IsEnumType(leftType)) { ConvertExpr(ref rightExpr, ref leftExpr); } else { throw new Exception("Unable to perform operation: " + operatorName + "on types:" + leftExpr.Type + ", " + rightExpr.Type); } } }
private string GetInputTypeFromModel(Type modelType) { if (NumericTypes.Contains(modelType)) { return("number"); } if (DateTypes.Contains(modelType)) { return("date"); } if (modelType == typeof(string)) { return("text"); } return(string.Empty); }
static void Method_ToString(DbMethodCallExpression exp, SqlGenerator generator) { if (exp.Method.Name != "ToString" && exp.Arguments.Count != 0) { throw UtilExceptions.NotSupportedMethod(exp.Method); } if (exp.Object.Type == UtilConstants.TypeOfString) { exp.Object.Accept(generator); return; } if (!NumericTypes.ContainsKey(exp.Object.Type.GetUnderlyingType())) { throw UtilExceptions.NotSupportedMethod(exp.Method); } DbConvertExpression c = DbExpression.Convert(exp.Object, UtilConstants.TypeOfString); c.Accept(generator); }
public unsafe Vector <T> AsVector() { int count = Vector <T> .Count; if (!NumericTypes.Contains(CLRType)) { throw new InvalidOperationException($"{CLRType.Name} is not a numeric type."); } else if (length != count) { throw new InvalidOperationException($"The length of the memory buffer must be {Vector<T>.Count} elements to create a vector of type {CLRType.Name}."); } else { Retain(); object[] args = new object[2] { ptr, 0 }; Vector <T> v = (Vector <T>)VectorInternalConstructorUsingPointer.Invoke(args); return(v); } }
private static void Week2Examples() { Console.WriteLine("----------------------------------------------"); Console.WriteLine("Week2 in-class discussion and testing... "); Console.WriteLine("----------------------------------------------"); ReferenceTypes myReferenceType = new ReferenceTypes(); myReferenceType.JoiningStrings(); NumericTypes myNumericType = new NumericTypes(); myNumericType.SpecialValues(); ValueTypesContinues myValueTypesContinue = new ValueTypesContinues(); myValueTypesContinue.EnumSample(); String myTestName1, myTestName2; myValueTypesContinue.OutSample("John Doe", out myTestName1, out myTestName2); Console.WriteLine(myTestName1 + ' ' + myTestName2); }
/// <summary> /// Initializes a new instance of the <see cref="ExtendedTypeInfo" /> class. /// </summary> /// <param name="t">The t.</param> public ExtendedTypeInfo(Type t) { Type = t ?? throw new ArgumentNullException(nameof(t)); IsNullableValueType = Type.GetTypeInfo().IsGenericType&& Type.GetGenericTypeDefinition() == typeof(Nullable <>); IsValueType = t.GetTypeInfo().IsValueType; UnderlyingType = IsNullableValueType ? new NullableConverter(Type).UnderlyingType : Type; IsNumeric = NumericTypes.Contains(UnderlyingType); // Extract the TryParse method info try { TryParseMethodInfo = UnderlyingType.GetMethod(TryParseMethodName, new[] { typeof(string), typeof(NumberStyles), typeof(IFormatProvider), UnderlyingType.MakeByRefType() }) ?? UnderlyingType.GetMethod(TryParseMethodName, new[] { typeof(string), UnderlyingType.MakeByRefType() }); _tryParseParameters = TryParseMethodInfo?.GetParameters(); } catch { // ignored } // Extract the ToString method Info try { ToStringMethodInfo = UnderlyingType.GetMethod(ToStringMethodName, new[] { typeof(IFormatProvider) }) ?? UnderlyingType.GetMethod(ToStringMethodName, new Type[] { }); _toStringArgumentLength = ToStringMethodInfo?.GetParameters().Length ?? 0; } catch { // ignored } }
/// <summary> /// Determines whether the provided type is a known numeric type /// (ie int / short / byte / double / float / decimal ) /// </summary> /// <param name="type">Type to operate on</param> /// <returns></returns> public static bool IsNumericType(this Type type) { return(NumericTypes.Contains(type)); }
static void OtherNumericExample() { NumericTypes myTypes = new NumericTypes(); myTypes.OtherOperators(); }
/// <summary> /// Indicates whether or not a particular <see cref="Type"/> is numeric or not /// </summary> public static bool IsNumeric(this Type type) { return(NumericTypes.Contains(type) || NumericTypes.Contains(Nullable.GetUnderlyingType(type))); }
public void NumericConstructorTest2() { NumericTypes type = new NumericTypes(); // TODO: Initialize to an appropriate value Numeric target = new Numeric(type); Assert.Inconclusive("TODO: Implement code to verify target"); }
private void AssertMultiplicationResultInRange(ulong left, ulong right, ulong maxValue, bool shouldSucceed, ulong expectedResult, NumericTypes numericTypes) { bool result; if (numericTypes.HasFlag(NumericTypes.ULong)) { result = WinCopies. #if !WinCopies3 Util. #endif Math.IsMultiplicationResultInRange(left, right, maxValue); ulong?resultULong = WinCopies. #if !WinCopies3 Util. #endif Math.TryMultiply(left, right, maxValue); if (shouldSucceed) { Assert.IsTrue(result); Assert.IsTrue(resultULong.HasValue); Assert.AreEqual(expectedResult, resultULong.Value); } else { Assert.IsFalse(result); Assert.IsFalse(resultULong.HasValue); } } if (numericTypes.HasFlag(NumericTypes.UInt)) { var _left = (uint)left; var _right = (uint)right; var _maxValue = (uint)maxValue; result = WinCopies. #if !WinCopies3 Util. #endif Math.IsMultiplicationResultInRange(_left, _right, _maxValue); uint?resultUInt = WinCopies. #if !WinCopies3 Util. #endif Math.TryMultiply(_left, _right, _maxValue); if (shouldSucceed) { Assert.IsTrue(result); Assert.IsTrue(resultUInt.HasValue); Assert.AreEqual((uint)expectedResult, resultUInt.Value); } else { Assert.IsFalse(result); Assert.IsFalse(resultUInt.HasValue); } } if (numericTypes.HasFlag(NumericTypes.UShort)) { var _left = (ushort)left; var _right = (ushort)right; var _maxValue = (ushort)maxValue; result = WinCopies. #if !WinCopies3 Util. #endif Math.IsMultiplicationResultInRange(_left, _right, _maxValue); ushort?resultUShort = WinCopies. #if !WinCopies3 Util. #endif Math.TryMultiply(_left, _right, _maxValue); if (shouldSucceed) { Assert.IsTrue(result); Assert.IsTrue(resultUShort.HasValue); Assert.AreEqual((ushort)expectedResult, resultUShort.Value); } else { Assert.IsFalse(result); Assert.IsFalse(resultUShort.HasValue); } } if (numericTypes.HasFlag(NumericTypes.Byte)) { var _left = (byte)left; var _right = (byte)right; var _maxValue = (byte)maxValue; result = WinCopies. #if !WinCopies3 Util. #endif Math.IsMultiplicationResultInRange(_left, _right, _maxValue); byte?resultByte = WinCopies. #if !WinCopies3 Util. #endif Math.TryMultiply(_left, _right, _maxValue); if (shouldSucceed) { Assert.IsTrue(result); Assert.IsTrue(resultByte.HasValue); Assert.AreEqual((byte)expectedResult, resultByte.Value); } else { Assert.IsFalse(result); Assert.IsFalse(resultByte.HasValue); } } }
public void ToStringTest() { NumericTypes type = new NumericTypes(); // TODO: Initialize to an appropriate value Numeric target = new Numeric(type); // TODO: Initialize to an appropriate value string expected = string.Empty; // TODO: Initialize to an appropriate value string actual; actual = target.ToString(); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public static bool IsNumericType <T>() { return(NumericTypes.Contains(typeof(T))); }
public static bool IsNumeric(this Type t) => NumericTypes.Contains(t);
static void OtherNumbericExamples() { NumericTypes myTypes = new NumericTypes();//deafaltconstaractor myTypes.otherOperator(); }
private static void SecondWeekExamples() { AdditionalExamples myAdditional = new AdditionalExamples(); Console.WriteLine("********"); Console.WriteLine("UseParms"); Console.WriteLine("********"); myAdditional.UseParams(1, 2, 3, 4, 5); Console.WriteLine("********"); Console.WriteLine("GetText"); Console.WriteLine("********"); Console.WriteLine(myAdditional.GetText("GetText String")); Console.WriteLine("********"); Console.WriteLine("SomeMethod Without Parameters"); Console.WriteLine("********"); myAdditional.SomeMethod(); Console.WriteLine("********"); Console.WriteLine("SomeMethod With String Parameters"); Console.WriteLine("********"); myAdditional.SomeMethod("Text in Somemethod"); Console.WriteLine("********"); Console.WriteLine("SomeMethod With Integer Parameters"); Console.WriteLine("********"); Console.WriteLine(myAdditional.SomeMethod(1)); Console.WriteLine("********"); Console.WriteLine("Coalescing Example"); Console.WriteLine("********"); myAdditional.CoalescingExample(); Console.WriteLine("********"); Console.WriteLine("Elvis Operator Example"); Console.WriteLine("********"); myAdditional.ElvisOperatorExample(); Console.WriteLine("********"); Console.WriteLine("Boolean Example"); Console.WriteLine("********"); Console.WriteLine(myAdditional.UseUmbrella(true, true, true)); NumericTypes myNumericTypes = new NumericTypes(); Console.WriteLine("********"); Console.WriteLine("ConvertFloatToInt Example"); Console.WriteLine("********"); myNumericTypes.ConvertFloatToInt(); Console.WriteLine("********"); Console.WriteLine("LongFromInt Example without Parameters"); Console.WriteLine("********"); myNumericTypes.LongFromInt(); Console.WriteLine("********"); Console.WriteLine(" LongFromInt Example with Integer Parameter"); Console.WriteLine("********"); Console.WriteLine(myNumericTypes.LongFromInt(1)); Console.WriteLine("********"); Console.WriteLine(" IncrementDecrement Example"); Console.WriteLine("********"); myNumericTypes.IncrementDecrement(); Console.WriteLine("********"); Console.WriteLine(" GetSomeTypes Example"); Console.WriteLine("********"); myNumericTypes.GetSomeTypes(); Console.WriteLine("********"); Console.WriteLine(" BasitMath Example"); Console.WriteLine("********"); myNumericTypes.BasicMath(); Console.WriteLine("********"); Console.WriteLine(" CheckOperatorType Example"); Console.WriteLine("********"); myNumericTypes.CheckOperatorType(); Console.WriteLine("********"); Console.WriteLine(" SpecialValues Example"); Console.WriteLine("********"); myNumericTypes.SpecialValues(); Console.WriteLine("********"); Console.WriteLine(" MyCheckComparison Example"); Console.WriteLine("********"); myNumericTypes.MyCheckComparison(); ReferenceTypes myReference = new ReferenceTypes(); Console.WriteLine("********"); Console.WriteLine(" JoiningStrings Example"); Console.WriteLine("********"); myReference.JoiningStrings(); Console.WriteLine("********"); Console.WriteLine(" JoiningStringsWithBuilder Example"); Console.WriteLine("********"); myReference.JoinStringsWithBuilder(); Console.WriteLine("********"); Console.WriteLine(" PlaceHolderString Example"); Console.WriteLine("********"); myReference.PlaceHolderString(); Console.WriteLine("********"); Console.WriteLine(" CompareStrings Example"); Console.WriteLine("********"); myReference.CompareStrings(); Console.WriteLine("********"); Console.WriteLine(" CharType Example"); Console.WriteLine("********"); myReference.CharType(); Console.WriteLine("********"); Console.WriteLine(" ArraySingleSample Example"); Console.WriteLine("********"); myReference.ArraySingleSample(); Console.WriteLine("********"); Console.WriteLine(" ArrayRectanglurSample Example"); Console.WriteLine("********"); myReference.ArrayRectanglurSample(); Console.WriteLine("********"); Console.WriteLine(" ArrayJaggedSample Example"); Console.WriteLine("********"); myReference.ArrayJaggedSample(); Statements myStatements = new Statements(); Console.WriteLine("********"); Console.WriteLine(" Constant Example"); Console.WriteLine("********"); myStatements.ConstantExample(); Console.WriteLine("********"); Console.WriteLine(" ExpressionStatement Example"); Console.WriteLine("********"); myStatements.ExpressionStatementExample(1, 2); Console.WriteLine("********"); Console.WriteLine(" If Statement Basic Example"); Console.WriteLine("********"); myStatements.IfStatementBasicExample(1, 2); Console.WriteLine("********"); Console.WriteLine(" If Statement Chain Example"); Console.WriteLine("********"); myStatements.IfStatementChainExample("Sunday"); Console.WriteLine("********"); Console.WriteLine(" Switch Statement Example"); Console.WriteLine("********"); myStatements.SwitchStatemntExample("Monday"); Console.WriteLine("********"); Console.WriteLine(" While Loop Example"); Console.WriteLine("********"); myStatements.WhileLoopExample(); Console.WriteLine("********"); Console.WriteLine(" DoWhile Loop Example"); Console.WriteLine("********"); myStatements.DoWhileLoopExample(); Console.WriteLine("********"); Console.WriteLine(" For Loop Example"); Console.WriteLine("********"); myStatements.ForLoopExample(); Console.WriteLine("********"); Console.WriteLine(" For Each Loop Example"); Console.WriteLine("********"); myStatements.ForEachLoopExample(); Console.WriteLine("********"); Console.WriteLine(" Jump Statement Example"); Console.WriteLine("********"); Console.WriteLine(myStatements.JumpStatementExample("Monday")); ValueTypesContinues myValueType = new ValueTypesContinues(); int x = 3; int y = 4; String myTestName, myTestSecondName; Console.WriteLine("********"); Console.WriteLine(" Enum Example"); Console.WriteLine("********"); myValueType.EnumSample(); Console.WriteLine("********"); Console.WriteLine(" REF Example"); Console.WriteLine("********"); Console.WriteLine("The Value before Ref Sample for X is " + x); myValueType.RefSample(ref x); Console.WriteLine("The Value after Ref Sample for X is " + x); Console.WriteLine("********"); Console.WriteLine(" OUT Example"); Console.WriteLine("********"); myValueType.OutSample("Johnny Quest", out myTestName, out myTestSecondName); Console.WriteLine("myTestName: " + myTestName + ' ' + myTestSecondName); Console.WriteLine(myTestName); Console.WriteLine(myTestSecondName); // Struct Call TestStruct teststruct1 = new TestStruct(); TestStruct teststruct2 = new TestStruct(10, 10); }