本文整理汇总了C#中System.ValueType.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# ValueType.GetType方法的具体用法?C# ValueType.GetType怎么用?C# ValueType.GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ValueType
的用法示例。
在下文中一共展示了ValueType.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EnumerateUDT
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;
}
示例2: CreateNumericRangeQuery
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());
}
示例3: ConvertToBasis
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);
}
示例4: ConvertToBasis
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);
}
示例5: SetValue
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;
}
}
示例6: ConvertToBasis
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);
}
示例7: DefaultFindFullDocumentKeyFromValueTypeIdentifier
///<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;
}
示例8: ConvertToBasis
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);
}
示例9: ConvertToBasis
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);
}
示例10: ConvertToBasis
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);
}
示例11: ToArray
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)
};
}
示例12: GetStructure
// Public methods
public static object GetStructure(IntPtr ptr, ValueType structure)
{
return Marshal.PtrToStructure(ptr, structure.GetType());
}
示例13: PrimitiveGraphNode
public PrimitiveGraphNode(ValueType value, Graph parentGraph)
: base(parentGraph)
{
m_isNumber = value.GetType().IsNumeric();
m_value = value;
}
示例14: NotifyValue
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));
}
示例15: WriteStruct
///// <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);
}
}