public static void checkGetTypeValueTypeCast(System.ValueType x) { if (x.GetType() == typeof(D)) { ((D)x).incCount(); } if (x.GetType() == typeof(C)) { ((C)x).incCount(); } }
public static void checkGetTypeValueType(System.ValueType x) { if (x.GetType() == typeof(D)) { (new D()).incCount(); } if (x.GetType() == typeof(C)) { (new C()).incCount(); } }
internal static object EnumerateUDT(ValueType oStruct, IRecordEnum intfRecEnum, bool fGet) { Type typ = oStruct.GetType(); if ((Information.VarTypeFromComType(typ) != VariantType.UserDefinedType) || typ.IsPrimitive) { throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue1", new string[] { "oStruct" })); } FieldInfo[] fields = typ.GetFields(BindingFlags.Public | BindingFlags.Instance); int num2 = 0; int num4 = fields.GetUpperBound(0); for (int i = num2; i <= num4; i++) { FieldInfo fieldInfo = fields[i]; Type fieldType = fieldInfo.FieldType; object obj3 = fieldInfo.GetValue(oStruct); if (Information.VarTypeFromComType(fieldType) == VariantType.UserDefinedType) { if (fieldType.IsPrimitive) { throw ExceptionUtils.VbMakeException(new ArgumentException(Utils.GetResourceString("Argument_UnsupportedFieldType2", new string[] { fieldInfo.Name, fieldType.Name })), 5); } EnumerateUDT((ValueType) obj3, intfRecEnum, fGet); } else { intfRecEnum.Callback(fieldInfo, ref obj3); } if (fGet) { fieldInfo.SetValue(oStruct, obj3); } } return null; }
internal static Query CreateNumericRangeQuery(string fieldName, ValueType lowerBound, ValueType upperBound, RangeType lowerRange, RangeType upperRange) { if (lowerBound == null && upperBound == null) { throw new ArgumentException("lowerBound and upperBound may not both be null."); } if (lowerBound == null) { lowerBound = (ValueType) upperBound.GetType().GetField("MinValue").GetValue(null); } else if (upperBound == null) { upperBound = (ValueType) lowerBound.GetType().GetField("MaxValue").GetValue(null); } if (lowerBound.GetType() != upperBound.GetType()) { throw new ArgumentException("Cannot compare different value types " + lowerBound.GetType() + " and " + upperBound.GetType()); } lowerBound = ToNumericFieldValue(lowerBound); upperBound = ToNumericFieldValue(upperBound); var minInclusive = lowerRange == RangeType.Inclusive; var maxInclusive = upperRange == RangeType.Inclusive; if (lowerBound is int) { return NumericRangeQuery.NewIntRange(fieldName, (int)lowerBound, (int)upperBound, minInclusive, maxInclusive); } if (lowerBound is long) { return NumericRangeQuery.NewLongRange(fieldName, (long)lowerBound, (long)upperBound, minInclusive, maxInclusive); } if (lowerBound is float) { return NumericRangeQuery.NewFloatRange(fieldName, (float)lowerBound, (float)upperBound, minInclusive, maxInclusive); } if (lowerBound is double) { return NumericRangeQuery.NewDoubleRange(fieldName, (double)lowerBound, (double)upperBound, minInclusive, maxInclusive); } throw new NotSupportedException("Unsupported numeric range type " + lowerBound.GetType()); }
public override uint ConvertToBasis(ValueType totalValue) { String msg; if (totalValue is ProductVersion) { return Convert.ToUInt32(((ProductVersion)totalValue).TotalVersion); } msg = String.Format("Преобразование невозможно. Передан тип {0}, ожидается {1}", totalValue.GetType().ToString(), typeof(ProductVersion).ToString()); throw new InvalidCastException(msg); }
public override uint ConvertToBasis(ValueType totalValue) { string msg; if (totalValue is Boolean) { return ((bool)totalValue) ? (UInt32)0 : (UInt32)255; } msg = String.Format("Преобразование невозможно. Передан тип {0}, ожидается {1}", totalValue.GetType().ToString(), typeof(Boolean).ToString()); throw new InvalidCastException(msg); }
internal override bool SetValue(ValueType value) { #if DEBUG if (value.GetType() != typeof(vec2)) { throw new ArgumentException(string.Format("[{0}] not match [{1}]'s value.", value.GetType().Name, this.GetType().Name)); } #endif var v = (vec2)value; if (v != this.value) { this.value = v; this.Updated = true; return true; } else { return false; } }
public override uint ConvertToBasis(ValueType totalValue) { string msg; if (totalValue is DateTime) { return Unix.ToUnixTime((DateTime)totalValue); } msg = String.Format("Преобразование невозможно. Передан тип {0}, ожидается {1}", totalValue.GetType(), typeof(DateTime)); throw new InvalidCastException(msg); }
///<summary> /// Find the full document name assuming that we are using the standard conventions /// for generating a document key ///</summary> ///<returns></returns> public string DefaultFindFullDocumentKeyFromValueTypeIdentifier(ValueType id, Type type) { string idPart; var converter = IdentityTypeConvertors.FirstOrDefault(x => x.CanConvertFrom(id.GetType())); if (converter != null) { idPart = converter.ConvertFrom(id); } else { idPart = id.ToString(); } return GetTypeTagName(type) + IdentityPartsSeparator + idPart; }
public override uint ConvertToBasis(ValueType totalValue) { String msg; if (totalValue is Byte) { return Convert.ToUInt32(totalValue); } msg = String.Format("ѕреобразование невозможно. ѕередан тип {0}, ожидаетс¤ {1}", totalValue.GetType(), typeof(Byte)); throw new InvalidCastException(msg); }
public override uint ConvertToBasis(ValueType totalValue) { String msg; if (totalValue is Int16) { return (UInt32)totalValue; } msg = String.Format("Преобразование невозможно. Передан тип {0}, ожидается {1}", totalValue.GetType(), typeof(UInt32)); throw new InvalidCastException(msg); }
public override uint ConvertToBasis(ValueType totalValue) { String msg; if (totalValue is Single) { return Convert.ToUInt32( ((Single)totalValue) / Convert.ToSingle(_Scaler)); } msg = String.Format("Преобразование невозможно. Передан тип {0}, ожидается {1}", totalValue.GetType(), typeof(Single)); throw new InvalidCastException(msg); }
public byte[] ToArray(ValueType value) { if (!(value is UInt16)) { throw new InvalidCastException(String.Format( "Невозможно преобразовать значение типа {0}, требуется тип UInt16", value.GetType())); } return new Byte[] { (Byte)((UInt32)value >> 8), (Byte)((UInt32)value) }; }
/// <summary> /// Returns a list of bits for any ValueType object supplied that isn't a struct. /// </summary> /// <param name="input">The input object</param> /// <returns><see cref="Collections.ICollection"/> of bits</returns> public static ICollection <byte> GetBits(this ValueType input) { if (!input.GetType().IsPrimitive) { throw new ArgumentException("Object cannot be a struct!"); } var bits = Marshal.SizeOf(input) * 8; var output = new byte[bits]; dynamic obj = input; for (var i = 0; i < bits; i++) { output[i] = (byte)((obj >> i) & 1); } return(output); }
// Public methods public static object GetStructure(IntPtr ptr, ValueType structure) { return Marshal.PtrToStructure(ptr, structure.GetType()); }
public PrimitiveGraphNode(ValueType value, Graph parentGraph) : base(parentGraph) { m_isNumber = value.GetType().IsNumeric(); m_value = value; }
protected void NotifyValue(PropertyID id, ValueType value) { Debug.Assert(this.IsInitialized); Debug.Assert(value.GetType().IsValueType); Debug.Assert(!this.IsDestructed); this.World.AddChange(new PropertyValueChange(this, id, value)); }
///// <summary> ///// 写入字符串,返回是否写入成功 ///// </summary> ///// <param name="value"></param> ///// <returns>是否写入成功</returns> //public Int32 WriteString(String value) //{ // Int64 p = BaseStream.Position; // Write(value); // return (Int32)(BaseStream.Position - p); //} ///// <summary> ///// 是否写入成功组,返回是否写入成功 ///// </summary> ///// <param name="buffer"></param> ///// <param name="index"></param> ///// <param name="count"></param> ///// <returns>是否写入成功</returns> //public Int32 WriteBytes(Byte[] buffer, Int32 index, Int32 count) //{ // Write(buffer, index, count); // return count; //} ///// <summary> ///// 写入字符数组,返回写入字符数 ///// </summary> ///// <param name="chars"></param> ///// <param name="index"></param> ///// <param name="count"></param> ///// <returns>写入字符数</returns> //public Int32 WriteChars(Char[] chars, Int32 index, Int32 count) //{ // Write(chars, index, count); // return count; //} /// <summary> /// 写入结构体 /// </summary> /// <param name="value"></param> /// <returns>是否写入成功</returns> public Int32 WriteStruct(ValueType value) { if (value == null) return 0; Type type = value.GetType(); if (type.IsGenericType) return 0; Int32 len = Marshal.SizeOf(type); // 分配全局内存,一并写入 IntPtr p = Marshal.AllocHGlobal(len); try { Marshal.StructureToPtr(value, p, true); Byte[] buffer = new Byte[len]; Marshal.Copy(p, buffer, 0, buffer.Length); Write(buffer, 0, buffer.Length); return buffer.Length; } catch { return 0; } finally { Marshal.DestroyStructure(p, type); } }
protected static void LogBind(SQLiteStatementHandle handle, int index, ValueType value) { IntPtr handleIntPtr = handle; SQLiteLog.LogMessage(UnsafeNativeMethods.StringFormat( CultureInfo.CurrentCulture, "Binding statement {0} paramter #{1} as type {2} with value {{{3}}}...", handleIntPtr, index, value.GetType(), value)); }
public static ValueType Clone(ValueType source) { if (source == null) throw new ArgumentNullException("source"); lock (ms_cloneCache) { var sourceType = source.GetType(); if (!ms_cloneCache.ContainsKey(sourceType)) { ms_cloneCache.Add(sourceType, Array.CreateInstance(sourceType, 1)); } var array = ms_cloneCache[sourceType]; array.SetValue(source, 0); return (ValueType)array.GetValue(0); } }
/// <summary> /// Determines if the <paramref name="instance"/> is not the default value for the <see cref="ValueType"/>. /// </summary> /// <param name="instance">The <see cref="ValueType"/> to check.</param> /// <returns><c>True</c> if the <paramref name="instance"/> is not equal to the default value; otherwise <c>False</c>.</returns> public static bool IsNotDefault(this ValueType instance) { return(!Object.Equals(instance.GetType().GetDefaultValue(), instance)); }
internal static NumericField SetValue(this NumericField field, ValueType value) { if (value.GetType().IsEnum) { value = (ValueType) Convert.ChangeType(value, Enum.GetUnderlyingType(value.GetType())); } if (value is int) { return field.SetIntValue((int) value); } if (value is long) { return field.SetLongValue((long)value); } if (value is double) { return field.SetDoubleValue((double)value); } if (value is float) { return field.SetFloatValue((float)value); } throw new ArgumentException("Unable to store ValueType " + value.GetType() + " as NumericField.", "value"); }
protected static void LogBind(SQLiteStatementHandle handle, int index, ValueType value) { IntPtr handleIntPtr = handle; SQLiteLog.LogMessage(String.Format( "Binding statement {0} paramter #{1} as type {2} with value {{{3}}}...", handleIntPtr, index, value.GetType(), value)); }
internal static NumericField SetValue(this NumericField field, ValueType value) { if (value is int) { return field.SetIntValue((int) value); } if (value is long) { return field.SetLongValue((long)value); } if (value is double) { return field.SetDoubleValue((double)value); } if (value is float) { return field.SetFloatValue((float)value); } throw new ArgumentException("Unable to store ValueType " + value.GetType() + " as NumericField.", "value"); }
/// <summary> /// 验证值类型是否合法 /// </summary> /// <param name="parameter"></param> /// <param name="canZero"></param> public Parameter Validate(ValueType parameter, Boolean canZero = false) { Type type = parameter.GetType(); if (type.IsValueType && type.IsNumeric()) { Boolean flag = !canZero ? parameter.CastTo(0.0) <= 0.0 : parameter.CastTo(0.0) < 0.0; if (flag) { throw ThrowComponentException($"参数 {parameter.GetType().Name} 不在有效范围内引发异常。具体信息请查看系统日志。", new ArgumentOutOfRangeException(parameter.GetType().Name)); } } return this; }