本文整理汇总了C#中IConvertible类的典型用法代码示例。如果您正苦于以下问题:C# IConvertible类的具体用法?C# IConvertible怎么用?C# IConvertible使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IConvertible类属于命名空间,在下文中一共展示了IConvertible类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: SetOperand
private void SetOperand(IConvertible operand)
{
switch (Instruction)
{
case BFInstruction.SetVariable:
case BFInstruction.PushVariable:
case BFInstruction.PushUInt16:
case BFInstruction.JumpIfFalse:
case BFInstruction.Jump:
case BFInstruction.CallProcedure:
case BFInstruction.CallNative:
case BFInstruction.BeginProcedure:
case BFInstruction.PushUInt32:
if (operand == null)
throw new ArgumentException("You must specify 1 operand for this instruction.");
_operand = new BFOperand(Convert.ToInt64(operand));
break;
case BFInstruction.PushFloat:
if (operand == null)
throw new ArgumentException("You must specify 1 operand for this instruction.");
_operand = new BFOperand(Convert.ToSingle(operand));
break;
default:
if (operand != null)
_operand = new BFOperand(Convert.ToInt64(operand));
break;
}
}
开发者ID:TGEnigma,项目名称:Amicitia,代码行数:28,代码来源:BFOpcode.cs
示例2: DoBinOp
protected override IConvertible DoBinOp(IConvertible left, IConvertible right)
{
Boolean left1 = Convert.ToBoolean(left);
Boolean right1 = Convert.ToBoolean(right);
return left1 && right1;
}
开发者ID:vorsters,项目名称:MyLanguage,代码行数:7,代码来源:MyLogicalAndNode.cs
示例3: SpriteKernel
protected SpriteKernel(IConvertible initialVersion)
{
SourceList = new Dictionary<IConvertible, SpriteSource>();
Animation = new PeriodicFunction<SpriteTransformation>(stage => new SpriteTransformation(0));
RegisteredVersion = new Collection<IConvertible>();
Version = initialVersion;
}
开发者ID:simonrouse9461,项目名称:CSE_3902_Mario,代码行数:7,代码来源:SpriteKernel.cs
示例4: GetValue
protected override IConvertible GetValue()
{
// if (!isGotValue)
// {
if (OnGetValue == null)
{
throw new InvalidOperationException("This variable is not bound to a formula, so it's value cannot be read.");
}
VariableReadEventArgs args = new VariableReadEventArgs(Name);
args.Type = Type;
OnGetValue(this, args);
if (Type != typeof(IConvertible))
{
_Value = (IConvertible)Convert.ChangeType(args.Value, Type);
}
else
{
_Value = args.Value;
}
// isGotValue = true;
// }
return _Value;
}
开发者ID:emrahoner,项目名称:CsQuery,代码行数:25,代码来源:Variable.cs
示例5: ValueCell
public ValueCell(StructField def, IConvertible value, string displayValue, int offset)
: base(def)
{
_value = value;
_displayValue = displayValue;
_offset = offset;
}
开发者ID:thawk,项目名称:structorian,代码行数:7,代码来源:ValueCell.cs
示例6: AddNumber
public override string AddNumber(IConvertible number, IList<DbParameter> parameters)
{
if (number == null)
{
throw new ArgumentNullException("number");
}
return number.ToString();
}
开发者ID:Skycweb,项目名称:blqw-Faller,代码行数:8,代码来源:OracleSaw.cs
示例7: ProxyNumber
public ProxyNumber( IConvertible value )
{
if (value is string)
{
this.value = Parse( value as string );
}
else
{
this.value = value;
}
}
开发者ID:gregharding,项目名称:TinyJSON,代码行数:11,代码来源:ProxyNumber.cs
示例8: DoBinOp
protected override IConvertible DoBinOp(IConvertible left, IConvertible right)
{
IComparable left1 = (IComparable)left;
IComparable right1 = (IComparable)right;
if (left1.CompareTo(right1) > 0)
{
return true;
}
return false;
}
开发者ID:vorsters,项目名称:MyLanguage,代码行数:11,代码来源:MyIsGreaterThanNode.cs
示例9: Ignore
public Tokenizer Ignore(int priority, IConvertible tokenName, String tokenRegex)
{
try {
Regex.Replace("", tokenRegex, "");
tokenPriorities[tokenName] = priority;
tokens[tokenName] = new Regex("^" + tokenRegex + "$");
ignore[tokenName] = true;
} catch (Exception e) {
throw (e);
}
return (this);
}
开发者ID:CMertens,项目名称:StrikeVM,代码行数:12,代码来源:Tokenizer.cs
示例10: AddDecimal
private static object AddDecimal(IConvertible Left, IConvertible Right)
{
decimal num = Left.ToDecimal(null);
decimal num2 = Right.ToDecimal(null);
try
{
return decimal.Add(num, num2);
}
catch (OverflowException)
{
return (Convert.ToDouble(num) + Convert.ToDouble(num2));
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:13,代码来源:Operators.cs
示例11: Prop
/// <summary>
/// Set one or more properties for the set of matched elements.
/// </summary>
///
/// <param name="name">
/// The property to set
/// </param>
/// <param name="value">
/// The value
/// </param>
///
/// <returns>
/// The current CQ object
/// </returns>
public CQ Prop(string name, IConvertible value)
{
// Prop actually works on things other than boolean - e.g. SelectedIndex. For now though only use prop for booleans
if (HtmlData.IsBoolean(name))
{
SetProp(name, value);
}
else
{
Attr(name, value);
}
return this;
}
开发者ID:emrahoner,项目名称:CsQuery,代码行数:29,代码来源:Prop.cs
示例12: DateTimeFormatPartOptionTO
public DateTimeFormatPartOptionTO(int length, Func<string, bool, bool> predicate, bool isNumeric,
IConvertible actualValue, Action<IDateTimeResultTO, bool, IConvertible> assignAction, int resultLength = -1)
{
Length = length;
Predicate = predicate;
IsNumeric = isNumeric;
ActualValue = actualValue;
AssignAction = assignAction;
if (resultLength == -1)
{
ResultLength = Length;
}
else
{
ResultLength = resultLength;
}
}
开发者ID:FerdinandOlivier,项目名称:Warewolf-ESB,代码行数:17,代码来源:DateTimeFormatPartOptionTO.cs
示例13: AddDecimal
private static object AddDecimal(IConvertible conv1, IConvertible conv2)
{
decimal num;
if (conv1 != null)
{
num = conv1.ToDecimal(null);
}
decimal num2 = conv2.ToDecimal(null);
try
{
return decimal.Add(num, num2);
}
catch (OverflowException)
{
return (Convert.ToDouble(num) + Convert.ToDouble(num2));
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:17,代码来源:ObjectType.cs
示例14: Eval
public override object Eval (DataRow row)
{
//TODO: implement a better caching strategy and a mechanism for cache invalidation.
//for now only aggregation over the table owning 'row' (e.g. 'sum(parts)'
//in constrast to 'sum(parent.parts)' and 'sum(child.parts)') is cached.
if (cacheResults && result != null && column.ReferencedTable == ReferencedTable.Self)
return result;
count = 0;
result = null;
object[] values;
if (rows == null)
values = column.GetValues (column.GetReferencedRows (row));
else
values = column.GetValues (rows);
foreach (object val in values) {
if (val == null)
continue;
count++;
Aggregate ((IConvertible)val);
}
switch (function) {
case AggregationFunction.StDev:
case AggregationFunction.Var:
result = CalcStatisticalFunction (values);
break;
case AggregationFunction.Avg:
result = Numeric.Divide (result, count);
break;
case AggregationFunction.Count:
result = count;
break;
}
if (result == null)
result = DBNull.Value;
return result;
}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:45,代码来源:Aggregation.cs
示例15: SetProperty
public void SetProperty(string property, IConvertible prop_val)
{
PropertyInfo prop_info = item.GetType ().GetProperty (property);
if (prop_info == null)
throw new ApplicationException (String.Format (
"Unable to set property {0}.{1} to \"{2}\"",
item.GetType (), property, prop_val));
Type prop_type = prop_info.PropertyType;
object param;
try {
param = prop_val.ToType (prop_type, NumberFormatInfo.InvariantInfo);
} catch (FormatException e) {
throw new ApplicationException (String.Format (
"prop_val cannot be converted to a {0}", prop_type), e);
}
prop_info.SetValue (item, param, null);
}
开发者ID:manicolosi,项目名称:questar,代码行数:21,代码来源:ItemBuilder.cs
示例16: DoBinOp
protected override IConvertible DoBinOp(IConvertible left, IConvertible right)
{
TypeCode typeCode = GetValueType(left, right);
switch (typeCode)
{
case TypeCode.SByte:
return (Convert.ToSByte(left) + Convert.ToSByte(right));
case TypeCode.Byte:
return (Convert.ToByte(left) + Convert.ToByte(right));
case TypeCode.Int16:
return (Convert.ToInt16(left) + Convert.ToInt16(right));
case TypeCode.UInt16:
return (Convert.ToUInt16(left) + Convert.ToUInt16(right));
case TypeCode.Int32:
return (Convert.ToInt32(left) + Convert.ToInt32(right));
case TypeCode.UInt32:
return (Convert.ToUInt32(left) + Convert.ToUInt32(right));
case TypeCode.Int64:
return (Convert.ToInt64(left) + Convert.ToInt64(right));
case TypeCode.UInt64:
return (Convert.ToUInt64(left) + Convert.ToUInt64(right));
case TypeCode.Double:
return (Convert.ToDouble(left) + Convert.ToDouble(right));
case TypeCode.Decimal:
return (Convert.ToDecimal(left) + Convert.ToDecimal(right));
}
return left.ToString() + right.ToString();
}
开发者ID:vorsters,项目名称:MyLanguage,代码行数:40,代码来源:MyAddNode.cs
示例17: DoBinOp
protected override IConvertible DoBinOp(IConvertible left, IConvertible right)
{
TypeCode typeCode = GetValueType(left, right);
switch (typeCode)
{
case TypeCode.SByte:
return (Convert.ToSByte(left) * Convert.ToSByte(right));
case TypeCode.Byte:
return (Convert.ToByte(left) * Convert.ToByte(right));
case TypeCode.Int16:
return (Convert.ToInt16(left) * Convert.ToInt16(right));
case TypeCode.UInt16:
return (Convert.ToUInt16(left) * Convert.ToUInt16(right));
case TypeCode.Int32:
return (Convert.ToInt32(left) * Convert.ToInt32(right));
case TypeCode.UInt32:
return (Convert.ToUInt32(left) * Convert.ToUInt32(right));
case TypeCode.Int64:
return (Convert.ToInt64(left) * Convert.ToInt64(right));
case TypeCode.UInt64:
return (Convert.ToUInt64(left) * Convert.ToUInt64(right));
case TypeCode.Double:
return (Convert.ToDouble(left) * Convert.ToDouble(right));
case TypeCode.Decimal:
return (Convert.ToDecimal(left) * Convert.ToDecimal(right));
}
throw new Exception("invalid type for MULTIPLY");
}
开发者ID:vorsters,项目名称:MyLanguage,代码行数:40,代码来源:MyMultiplyNode.cs
示例18: Unify
//extends to Int32/Int64/Decimal/Double
internal static IConvertible Unify (IConvertible o)
{
switch (o.GetTypeCode()) {
case TypeCode.Char:
case TypeCode.SByte:
case TypeCode.Byte:
case TypeCode.Int16:
case TypeCode.UInt16:
return (IConvertible)Convert.ChangeType (o, TypeCode.Int32);
case TypeCode.UInt32:
return (IConvertible)Convert.ChangeType (o, TypeCode.Int64);
case TypeCode.UInt64:
return (IConvertible)Convert.ChangeType (o, TypeCode.Decimal);
case TypeCode.Single:
return (IConvertible)Convert.ChangeType (o, TypeCode.Double);
default:
return o;
}
}
开发者ID:nlhepler,项目名称:mono,代码行数:24,代码来源:Numeric.cs
示例19: SetSelected
/// <summary>
/// Set a specific item, identified by the 2nd parameter, of a named option group, identified by
/// the first parameter, as selected.
/// </summary>
///
/// <param name="groupName">
/// The value of the name attribute identifying this option group.
/// </param>
/// <param name="value">
/// The option value to set as selected
/// </param>
///
/// <returns>
/// The current CQ object
/// </returns>
public CQ SetSelected(string groupName, IConvertible value)
{
var group = this.Find("input[name='" + groupName + "']");
var item = group.Filter("[value='" + value + "']");
if (group.Length == 0)
{
item = this.Find("#" + groupName);
}
if (item.Length > 0)
{
ushort nodeNameID = group[0].NodeNameID;
string type = group[0]["type"].ToUpper();
if (nodeNameID == HtmlData.tagOPTION)
{
var ownerMultiple = group.Closest("select").Prop("multiple");
if (Objects.IsTruthy(ownerMultiple))
{
item.Prop("selected", true);
}
else
{
group.Prop("selected", false);
item.Prop("selected", true);
}
}
else if (nodeNameID == HtmlData.tagINPUT &&
(type == "radio" || type == "checkbox"))
{
if (type == "radio")
{
group.Prop("checked", false);
}
item.Prop("checked", true);
}
}
return this;
}
开发者ID:emrahoner,项目名称:CsQuery,代码行数:53,代码来源:SetSelected.cs
示例20: ToSameType
//(note: o1 and o2 must both be of type Int32/Int64/Decimal/Double)
internal static TypeCode ToSameType (ref IConvertible o1, ref IConvertible o2)
{
TypeCode tc1 = o1.GetTypeCode();
TypeCode tc2 = o2.GetTypeCode();
if (tc1 == tc2)
return tc1;
if (tc1 == TypeCode.DBNull || tc2 == TypeCode.DBNull)
return TypeCode.DBNull;
// is it ok to make such assumptions about the order of an enum?
if (tc1 < tc2)
{
o1 = (IConvertible)Convert.ChangeType (o1, tc2);
return tc2;
}
else
{
o2 = (IConvertible)Convert.ChangeType (o2, tc1);
return tc1;
}
}
开发者ID:nlhepler,项目名称:mono,代码行数:25,代码来源:Numeric.cs
注:本文中的IConvertible类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论