Here are the examples of the csharp api System.Convert.ToDecimal(object) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
613 Examples
19
Source : DBHelperMySQL.cs
with Apache License 2.0
from 0nise
with Apache License 2.0
from 0nise
public static string Top30Money()
{
// 未提取存款
Hashtable userMoney = new Hashtable();
Hashtable userInfo = new Hashtable();
// 已经提取存款
Hashtable userBlank = new Hashtable();
// 财富榜前20
Hashtable userData = new Hashtable();
string resultMsg = "";
MySqlConnection connection = null;
try
{
connection = ConnectionPool.getPool().getConnection();
// 链接为null就执行等待
while (connection == null)
{
}
string sql = "SELECT bbs_nick_name,user_money,user_qq FROM ichunqiu_blank";
using (MySqlCommand cmd = new MySqlCommand(sql,connection))
{
using (MySqlDataReader myDataReader = cmd.ExecuteReader())
{
while (myDataReader.Read() == true)
{
userMoney.Add(myDataReader["bbs_nick_name"], myDataReader["user_money"]);
userInfo.Add(myDataReader["user_qq"], myDataReader["bbs_nick_name"]);
}
}
}
// 提取历史提取总金额
userBlank = getAllHistorySumMoney(userInfo);
// ArrayList allMoney = new ArrayList();
List<Decimal> allMoney = new List<decimal>();
foreach (DictionaryEntry item in userMoney)
{
decimal blance = Convert.ToDecimal(item.Value);
decimal historyBlance = Convert.ToDecimal(userBlank[item.Key]);
userData.Add(item.Key, historyBlance + blance);
allMoney.Add(historyBlance + blance);
}
/*
List<decimal> allMoney = new List<decimal>();
foreach (string item in userData.Values)
{
allMoney.Add(Convert.ToDecimal(item));
}*/
// 降序
allMoney.Sort((x, y) => -x.CompareTo(y));
int i = 0;
foreach (decimal money in allMoney)
{
foreach (DictionaryEntry item in userData)
{
if (Convert.ToDecimal(item.Value) == money)
{
resultMsg += string.Format("NO【{0}】:{1}身价{2},已提取存款{3},未提取存款{4}\n", (i + 1).ToString(), Convert.ToString(item.Key), Convert.ToString(money), Convert.ToString(userBlank[item.Key]), Convert.ToString(userMoney[item.Key]));
// 删除用户避免出现重复的情况
userData.Remove(item.Key);
break;
}
}
i++;
if (i > 29)
{
break;
}
}
}
catch (Exception)
{
throw;
}
finally {
if (connection != null) {
connection.Close();
}
// 关闭数据库链接
ConnectionPool.getPool().closeConnection(connection);
}
return resultMsg;
}
19
Source : NpcCommandHandler.cs
with GNU Lesser General Public License v3.0
from 8720826
with GNU Lesser General Public License v3.0
from 8720826
private bool CheckField(PlayerEnreplacedy player, string field, string strValue, string strRelation)
{
try
{
var relations = GetRelations(strRelation);// 1 大于,0 等于 ,-1 小于
var fieldProp = GetFieldPropertyInfo(player, field);
if (fieldProp == null)
{
return false;
}
var objectValue = fieldProp.GetValue(player);
var typeCode = Type.GetTypeCode(fieldProp.GetType());
switch (typeCode)
{
case TypeCode.Int32:
return relations.Contains(Convert.ToInt32(strValue).CompareTo(Convert.ToInt32(objectValue)));
case TypeCode.Int64:
return relations.Contains(Convert.ToInt64(strValue).CompareTo(Convert.ToInt64(objectValue)));
case TypeCode.Decimal:
return relations.Contains(Convert.ToDecimal(strValue).CompareTo(Convert.ToDecimal(objectValue)));
case TypeCode.Double:
return relations.Contains(Convert.ToDouble(strValue).CompareTo(Convert.ToDouble(objectValue)));
case TypeCode.Boolean:
return relations.Contains(Convert.ToBoolean(strValue).CompareTo(Convert.ToBoolean(objectValue)));
case TypeCode.DateTime:
return relations.Contains(Convert.ToDateTime(strValue).CompareTo(Convert.ToDateTime(objectValue)));
case TypeCode.String:
return relations.Contains(strValue.CompareTo(objectValue));
default:
throw new Exception($"不支持的数据类型: {typeCode}");
}
}
catch (Exception ex)
{
_logger.LogError($"CheckField Exception:{ex}");
return false;
}
}
19
Source : EntityFormFunctions.cs
with MIT License
from Adoxio
with MIT License
from Adoxio
internal static string TryConvertAttributeValueToString(OrganizationServiceContext context, Dictionary<string, AttributeTypeCode?> attributeTypeCodeDictionary, string enreplacedyName, string attributeName, object value)
{
if (context == null || string.IsNullOrWhiteSpace(enreplacedyName) || string.IsNullOrWhiteSpace(attributeName))
{
return string.Empty;
}
var newValue = string.Empty;
var attributeTypeCode = attributeTypeCodeDictionary.FirstOrDefault(a => a.Key == attributeName).Value;
if (attributeTypeCode == null)
{
ADXTrace.Instance.TraceError(TraceCategory.Application, "Unable to recognize the attribute specified.");
return string.Empty;
}
try
{
switch (attributeTypeCode)
{
case AttributeTypeCode.BigInt:
newValue = value == null ? string.Empty : Convert.ToInt64(value).ToString(CultureInfo.InvariantCulture);
break;
case AttributeTypeCode.Boolean:
newValue = value == null ? string.Empty : Convert.ToBoolean(value).ToString(CultureInfo.InvariantCulture);
break;
case AttributeTypeCode.Customer:
if (value is EnreplacedyReference)
{
var enreplacedyref = value as EnreplacedyReference;
newValue = enreplacedyref.Id.ToString();
}
break;
case AttributeTypeCode.DateTime:
newValue = value == null ? string.Empty : Convert.ToDateTime(value).ToUniversalTime().ToString(CultureInfo.InvariantCulture);
break;
case AttributeTypeCode.Decimal:
newValue = value == null ? string.Empty : Convert.ToDecimal(value).ToString(CultureInfo.InvariantCulture);
break;
case AttributeTypeCode.Double:
newValue = value == null ? string.Empty : Convert.ToDouble(value).ToString(CultureInfo.InvariantCulture);
break;
case AttributeTypeCode.Integer:
newValue = value == null ? string.Empty : Convert.ToInt32(value).ToString(CultureInfo.InvariantCulture);
break;
case AttributeTypeCode.Lookup:
if (value is EnreplacedyReference)
{
var enreplacedyref = value as EnreplacedyReference;
newValue = enreplacedyref.Id.ToString();
}
break;
case AttributeTypeCode.Memo:
newValue = value as string;
break;
case AttributeTypeCode.Money:
newValue = value == null ? string.Empty : Convert.ToDecimal(value).ToString(CultureInfo.InvariantCulture);
break;
case AttributeTypeCode.Picklist:
newValue = value == null ? string.Empty : Convert.ToInt32(value).ToString(CultureInfo.InvariantCulture);
break;
case AttributeTypeCode.State:
newValue = value == null ? string.Empty : Convert.ToInt32(value).ToString(CultureInfo.InvariantCulture);
break;
case AttributeTypeCode.Status:
newValue = value == null ? string.Empty : Convert.ToInt32(value).ToString(CultureInfo.InvariantCulture);
break;
case AttributeTypeCode.String:
newValue = value as string;
break;
case AttributeTypeCode.Uniqueidentifier:
if (value is Guid)
{
var id = (Guid)value;
newValue = id.ToString();
}
break;
default:
ADXTrace.Instance.TraceWarning(TraceCategory.Application, string.Format("Attribute type '{0}' is unsupported.", attributeTypeCode));
break;
}
}
catch (Exception ex)
{
WebEventSource.Log.GenericWarningException(ex, string.Format("Attribute specified is expecting a {0}. The value provided is not valid.", attributeTypeCode));
}
return newValue;
}
19
Source : EntityFormFunctions.cs
with MIT License
from Adoxio
with MIT License
from Adoxio
internal static dynamic TryConvertAttributeValue(OrganizationServiceContext context, string enreplacedyName, string attributeName, object value, Dictionary<string, AttributeTypeCode?> AttributeTypeCodeDictionary)
{
if (context == null || string.IsNullOrWhiteSpace(enreplacedyName) || string.IsNullOrWhiteSpace(attributeName)) return null;
if (AttributeTypeCodeDictionary == null || !AttributeTypeCodeDictionary.Any())
{
AttributeTypeCodeDictionary = MetadataHelper.BuildAttributeTypeCodeDictionary(context, enreplacedyName);
}
object newValue = null;
var attributeTypeCode = AttributeTypeCodeDictionary.FirstOrDefault(a => a.Key == attributeName).Value;
if (attributeTypeCode == null)
{
ADXTrace.Instance.TraceError(TraceCategory.Application, string.Format("Unable to recognize the attribute '{0}' specified.", attributeName));
return null;
}
try
{
switch (attributeTypeCode)
{
case AttributeTypeCode.BigInt:
newValue = value == null ? (object)null : Convert.ToInt64(value);
break;
case AttributeTypeCode.Boolean:
newValue = value == null ? (object)null : Convert.ToBoolean(value);
break;
case AttributeTypeCode.Customer:
if (value is EnreplacedyReference)
{
newValue = value as EnreplacedyReference;
}
else if (value is Guid)
{
var metadata = MetadataHelper.GetEnreplacedyMetadata(context, enreplacedyName);
var attribute = metadata.Attributes.FirstOrDefault(a => a.LogicalName == attributeName);
if (attribute != null)
{
var lookupAttribute = attribute as LookupAttributeMetadata;
if (lookupAttribute != null && lookupAttribute.Targets.Length == 1)
{
var lookupEnreplacedyType = lookupAttribute.Targets[0];
newValue = new EnreplacedyReference(lookupEnreplacedyType, (Guid)value);
}
}
}
break;
case AttributeTypeCode.DateTime:
newValue = value == null ? (object)null : Convert.ToDateTime(value).ToUniversalTime();
break;
case AttributeTypeCode.Decimal:
newValue = value == null ? (object)null : Convert.ToDecimal(value);
break;
case AttributeTypeCode.Double:
newValue = value == null ? (object)null : Convert.ToDouble(value);
break;
case AttributeTypeCode.Integer:
newValue = value == null ? (object)null : Convert.ToInt32(value);
break;
case AttributeTypeCode.Lookup:
if (value is EnreplacedyReference)
{
newValue = value as EnreplacedyReference;
}
else if (value is Guid)
{
var metadata = MetadataHelper.GetEnreplacedyMetadata(context, enreplacedyName);
var attribute = metadata.Attributes.FirstOrDefault(a => a.LogicalName == attributeName);
if (attribute != null)
{
var lookupAttribute = attribute as LookupAttributeMetadata;
if (lookupAttribute != null && lookupAttribute.Targets.Length == 1)
{
var lookupEnreplacedyType = lookupAttribute.Targets[0];
newValue = new EnreplacedyReference(lookupEnreplacedyType, (Guid)value);
}
}
}
break;
case AttributeTypeCode.Memo:
newValue = value as string;
break;
case AttributeTypeCode.Money:
newValue = value == null ? (object)null : Convert.ToDecimal(value);
break;
case AttributeTypeCode.Picklist:
var plMetadata = MetadataHelper.GetEnreplacedyMetadata(context, enreplacedyName);
var plAttribute = plMetadata.Attributes.FirstOrDefault(a => a.LogicalName == attributeName);
if (plAttribute != null)
{
var picklistAttribute = plAttribute as PicklistAttributeMetadata;
if (picklistAttribute != null)
{
int picklistInt;
OptionMetadata picklistValue;
if (int.TryParse(string.Empty + value, out picklistInt))
{
picklistValue = picklistAttribute.OptionSet.Options.FirstOrDefault(o => o.Value == picklistInt);
}
else
{
picklistValue = picklistAttribute.OptionSet.Options.FirstOrDefault(o => o.Label.GetLocalizedLabelString() == string.Empty + value);
}
if (picklistValue != null && picklistValue.Value.HasValue)
{
newValue = value == null ? null : new OptionSetValue(picklistValue.Value.Value);
}
}
}
break;
case AttributeTypeCode.State:
ADXTrace.Instance.TraceWarning(TraceCategory.Application, string.Format("Attribute '{0}' type '{1}' is unsupported. The state attribute is created automatically when the enreplacedy is created. The options available for this attribute are read-only.", attributeName, attributeTypeCode));
break;
case AttributeTypeCode.Status:
if (value == null)
{
return false;
}
var optionSetValue = new OptionSetValue(Convert.ToInt32(value));
newValue = optionSetValue;
break;
case AttributeTypeCode.String:
newValue = value as string;
break;
default:
ADXTrace.Instance.TraceWarning(TraceCategory.Application, string.Format("Attribute '{0}' type '{1}' is unsupported.", attributeName, attributeTypeCode));
break;
}
}
catch (Exception ex)
{
WebEventSource.Log.GenericWarningException(ex, string.Format("Attribute '{0}' specified is expecting a {1}. The value provided is not valid.", attributeName, attributeTypeCode));
}
return newValue;
}
19
Source : TypeFilters.cs
with MIT License
from Adoxio
with MIT License
from Adoxio
public static decimal? Decimal(object input)
{
if (input == null)
{
return null;
}
try
{
return Convert.ToDecimal(input);
}
catch (FormatException) { }
catch (InvalidCastException) { }
return null;
}
19
Source : MathFilters.cs
with MIT License
from Adoxio
with MIT License
from Adoxio
public static int Ceil(object value)
{
return value == null
? 0
: Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(value)));
}
19
Source : MathFilters.cs
with MIT License
from Adoxio
with MIT License
from Adoxio
public static int Floor(object value)
{
return value == null
? 0
: Convert.ToInt32(Math.Floor(Convert.ToDecimal(value)));
}
19
Source : MathFilters.cs
with MIT License
from Adoxio
with MIT License
from Adoxio
public static object Round(object value, int decimals = 0)
{
if (value == null)
{
return 0;
}
return decimals == 0
? Convert.ToInt32(Math.Round(Convert.ToDecimal(value), decimals))
: Math.Round(Convert.ToDecimal(value), decimals);
}
19
Source : NumberFormatFilters.cs
with MIT License
from Adoxio
with MIT License
from Adoxio
private static string FormatCurrency(object value, string format, IFormatProvider formatProvider)
{
var money = value as Money;
return string.Format(
formatProvider,
string.IsNullOrEmpty(format) ? "{0}" : "{{0:{0}}}".FormatWith(format),
money ?? new Money(Convert.ToDecimal(value ?? 0)));
}
19
Source : NumberFormatFilters.cs
with MIT License
from Adoxio
with MIT License
from Adoxio
public static string Format(object number, string format, string culture = "")
{
var cultureInfo = string.IsNullOrEmpty(culture)
? CultureInfo.CurrentUICulture
: CultureInfo.GetCultureInfoByIetfLanguageTag(culture);
var dec = Convert.ToDecimal(number);
return dec.ToString(format, cultureInfo);
}
19
Source : Expression.cs
with MIT License
from Adoxio
with MIT License
from Adoxio
protected bool Evaluate(Expression left, Expression right, Func<object, object, bool> compare, Func<object, Type, object> convert)
{
object testValue;
var attributeName = ((LeftLiteralExpression)left).Value as string;
var expressionValue = ((RightLiteralExpression)right).Value;
if (EvaluateEnreplacedy == null)
{
throw new NullReferenceException("EvaluateEnreplacedy is null.");
}
if (string.IsNullOrWhiteSpace(attributeName))
{
throw new InvalidOperationException(string.Format("Unable to recognize the attribute {0} specified in the expression.", attributeName));
}
var attributeTypeCode = AttributeTypeCodeDictionary.FirstOrDefault(a => a.Key == attributeName).Value;
if (attributeTypeCode == null)
{
throw new InvalidOperationException(string.Format("Unable to recognize the attribute {0} specified in the expression.", attributeName));
}
var attributeValue = EvaluateEnreplacedy.Attributes.ContainsKey(attributeName) ? EvaluateEnreplacedy.Attributes[attributeName] : null;
switch (attributeTypeCode)
{
case AttributeTypeCode.BigInt:
if (expressionValue != null && !(expressionValue is long | expressionValue is double))
{
throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
}
testValue = expressionValue == null ? (object)null : Convert.ToInt64(expressionValue);
break;
case AttributeTypeCode.Boolean:
if (expressionValue != null && !(expressionValue is bool))
{
throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
}
testValue = expressionValue == null ? (object)null : (bool)expressionValue;
break;
case AttributeTypeCode.Customer:
var enreplacedyReference = EvaluateEnreplacedy.Attributes.ContainsKey(attributeName) ? (EnreplacedyReference)EvaluateEnreplacedy.Attributes[attributeName] : null;
attributeValue = enreplacedyReference != null ? (object)enreplacedyReference.Id : null;
if (expressionValue != null && !(expressionValue is Guid))
{
throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
}
testValue = expressionValue == null ? (object)null : (Guid)expressionValue;
break;
case AttributeTypeCode.DateTime:
if (expressionValue != null && !(expressionValue is DateTime))
{
throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
}
testValue = expressionValue == null ? (object)null : ((DateTime)expressionValue).ToUniversalTime();
break;
case AttributeTypeCode.Decimal:
if (expressionValue != null && !(expressionValue is int | expressionValue is double | expressionValue is decimal))
{
throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
}
testValue = expressionValue == null ? (object)null : Convert.ToDecimal(expressionValue);
break;
case AttributeTypeCode.Double:
if (expressionValue != null && !(expressionValue is int | expressionValue is double))
{
throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
}
testValue = expressionValue == null ? (object)null : Convert.ToDouble(expressionValue);
break;
case AttributeTypeCode.Integer:
if (expressionValue != null && !(expressionValue is int | expressionValue is double))
{
throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
}
testValue = expressionValue == null ? (object)null : Convert.ToInt32(expressionValue);
break;
case AttributeTypeCode.Lookup:
var lookupEnreplacedyReference = EvaluateEnreplacedy.Attributes.ContainsKey(attributeName) ? (EnreplacedyReference)EvaluateEnreplacedy.Attributes[attributeName] : null;
attributeValue = lookupEnreplacedyReference != null ? (object)lookupEnreplacedyReference.Id : null;
if (expressionValue != null && !(expressionValue is Guid))
{
throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
}
testValue = expressionValue == null ? (object)null : (Guid)expressionValue;
break;
case AttributeTypeCode.Memo:
if (expressionValue != null && !(expressionValue is string))
{
throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
}
testValue = expressionValue as string;
break;
case AttributeTypeCode.Money:
var money = EvaluateEnreplacedy.Attributes.ContainsKey(attributeName) ? (Money)EvaluateEnreplacedy.Attributes[attributeName] : null;
attributeValue = money != null ? (object)Convert.ToDecimal(money.Value) : null;
if (expressionValue != null && !(expressionValue is int | expressionValue is double | expressionValue is decimal))
{
throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
}
testValue = expressionValue == null ? (object)null : Convert.ToDecimal(expressionValue);
break;
case AttributeTypeCode.Picklist:
var optionSetValue = EvaluateEnreplacedy.Attributes.ContainsKey(attributeName) ? (OptionSetValue)EvaluateEnreplacedy.Attributes[attributeName] : null;
attributeValue = optionSetValue != null ? (object)optionSetValue.Value : null;
if (expressionValue != null && !(expressionValue is int | expressionValue is double))
{
throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
}
testValue = expressionValue == null ? (object)null : Convert.ToInt32(expressionValue);
break;
case AttributeTypeCode.State:
var stateOptionSetValue = EvaluateEnreplacedy.Attributes.ContainsKey(attributeName) ? (OptionSetValue)EvaluateEnreplacedy.Attributes[attributeName] : null;
attributeValue = stateOptionSetValue != null ? (object)stateOptionSetValue.Value : null;
if (expressionValue != null && !(expressionValue is int | expressionValue is double))
{
throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
}
testValue = expressionValue == null ? (object)null : Convert.ToInt32(expressionValue);
break;
case AttributeTypeCode.Status:
var statusOptionSetValue = EvaluateEnreplacedy.Attributes.ContainsKey(attributeName) ? (OptionSetValue)EvaluateEnreplacedy.Attributes[attributeName] : null;
attributeValue = statusOptionSetValue != null ? (object)statusOptionSetValue.Value : null;
if (expressionValue != null && !(expressionValue is int | expressionValue is double))
{
throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
}
testValue = expressionValue == null ? (object)null : Convert.ToInt32(expressionValue);
break;
case AttributeTypeCode.String:
if (expressionValue != null && !(expressionValue is string))
{
throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
}
testValue = expressionValue as string;
break;
case AttributeTypeCode.Uniqueidentifier:
if (expressionValue != null && !(expressionValue is Guid))
{
throw new InvalidOperationException(string.Format("Attribute {0} specified in the expression is expecting a {1}. The value provided isn't valid.", attributeName, attributeTypeCode));
}
testValue = expressionValue == null ? (object)null : (Guid)expressionValue;
break;
default:
throw new InvalidOperationException(string.Format("Unsupported type of attribute {0} specified in the expression.", attributeName));
}
return compare(attributeValue, testValue);
}
19
Source : PriceLevel.cs
with Apache License 2.0
from AlexWan
with Apache License 2.0
from AlexWan
public static PriceLevel CreateFromJArray(JArray priceLevelTokens)
{
return new PriceLevel
{
Price = Convert.ToDecimal(priceLevelTokens[0]),
Volume = Convert.ToDecimal(priceLevelTokens[1]),
Timestamp = Convert.ToDecimal(priceLevelTokens[2]),
};
}
19
Source : SpreadMessage.cs
with Apache License 2.0
from AlexWan
with Apache License 2.0
from AlexWan
public static SpreadMessage CreateFromString(string rawSpreadMessage)
{
var spreadMessage = KrakenDataMessageHelper.EnsureRawMessage(rawSpreadMessage);
var spreadTokens = spreadMessage[1] as JArray;
return new SpreadMessage
{
ChannelId = Convert.ToInt64(spreadMessage.First),
Bid = Convert.ToDecimal(spreadTokens[0]),
Ask = Convert.ToDecimal(spreadTokens[1]),
Time = Convert.ToDecimal(spreadTokens[2]),
};
}
19
Source : BestPriceVolume.cs
with Apache License 2.0
from AlexWan
with Apache License 2.0
from AlexWan
internal static BestPriceVolume CreateFromJArray(JArray tokenArray)
{
return new BestPriceVolume
{
BestPrice = Convert.ToDecimal(tokenArray[0]),
WholeLotVolume = Convert.ToInt32(tokenArray[1]),
LotVolume = Convert.ToDecimal(tokenArray[2])
};
}
19
Source : ClosePriceVolume.cs
with Apache License 2.0
from AlexWan
with Apache License 2.0
from AlexWan
public static ClosePriceVolume CreateFromJArray(JArray tokenArray)
{
return new ClosePriceVolume
{
Price = Convert.ToDecimal(tokenArray[0]),
LotVolume = Convert.ToDecimal(tokenArray[1])
};
}
19
Source : OhlcMessage.cs
with Apache License 2.0
from AlexWan
with Apache License 2.0
from AlexWan
public static OhlcMessage CreateFromString(string rawOhlcMessage)
{
var ohlcMessage = KrakenDataMessageHelper.EnsureRawMessage(rawOhlcMessage);
var dataArray = ohlcMessage[1] as JArray;
return new OhlcMessage
{
ChannelId = Convert.ToInt64(ohlcMessage.First),
Time = Convert.ToDecimal(dataArray[0]),
EndTime = Convert.ToDecimal(dataArray[1]),
Open = Convert.ToDecimal(dataArray[2]),
High = Convert.ToDecimal(dataArray[3]),
Low = Convert.ToDecimal(dataArray[4]),
Close = Convert.ToDecimal(dataArray[5]),
Vwap = Convert.ToDecimal(dataArray[6]),
Volume = Convert.ToDecimal(dataArray[7]),
Count = Convert.ToInt64(dataArray[8])
};
}
19
Source : TodayAnd24HourValue.cs
with Apache License 2.0
from AlexWan
with Apache License 2.0
from AlexWan
private static object ConvertToken(JToken token)
{
if (typeof(TValue) == typeof(decimal))
{
return Convert.ToDecimal(token);
}
if (typeof(TValue) == typeof(int))
{
return Convert.ToInt32(token);
}
return null;
}
19
Source : TradeValues.cs
with Apache License 2.0
from AlexWan
with Apache License 2.0
from AlexWan
public static TradeValues CreateFromJArray(JArray tradeValueTokens)
{
return new TradeValues
{
Price = Convert.ToDecimal(tradeValueTokens[0]),
Volume = Convert.ToDecimal(tradeValueTokens[1]),
Time = Convert.ToDecimal(tradeValueTokens[2]),
Side = Convert.ToString(tradeValueTokens[3]),
OrderType = Convert.ToString(tradeValueTokens[4]),
Misc = Convert.ToString(tradeValueTokens[5]),
};
}
19
Source : QuikDde.cs
with Apache License 2.0
from AlexWan
with Apache License 2.0
from AlexWan
private void PositionDerivativeUpdated(long id, object[,] table)
{
int countElem = table.GetLength(0);
if (countElem == 0)
{
return;
}
for (int i = 0; i < countElem; i++)
{
PositionOnBoard position = new PositionOnBoard();
position.PortfolioName = table[i, 0].ToString();
position.SecurityNameCode = table[i, 1].ToString();
position.ValueBegin = Convert.ToDecimal(table[i, 2]);
position.ValueCurrent = Convert.ToDecimal(table[i, 3]);
position.ValueBlocked = Math.Abs(Convert.ToDecimal(table[i, 4])) +
Math.Abs(Convert.ToDecimal(table[i, 5]));
UpDatePosition(position);
}
}
19
Source : QuikDde.cs
with Apache License 2.0
from AlexWan
with Apache License 2.0
from AlexWan
private void PositionSpotUpdated(long id, object[,] table)
{
int countElem = table.GetLength(0);
if (countElem == 0)
{
return;
}
for (int i = 0; i < countElem; i++)
{
PositionOnBoard position = new PositionOnBoard();
position.PortfolioName = table[i, 0].ToString();
position.SecurityNameCode = table[i, 1].ToString();
position.ValueBegin = Convert.ToDecimal(table[i, 2]);
position.ValueCurrent = Convert.ToDecimal(table[i, 3]);
position.ValueBlocked = Math.Abs(Convert.ToDecimal(table[i, 4]));
UpDatePosition(position);
}
}
19
Source : ConvertUtilTest.cs
with Apache License 2.0
from Appdynamics
with Apache License 2.0
from Appdynamics
internal T GetTypedValue<T>(object v)
{
if (v == null)
{
return default(T);
}
Type fromType = v.GetType();
Type toType = typeof(T);
Type toType2 = (TypeCompat.IsGenericType(toType) && toType.GetGenericTypeDefinition().Equals(typeof(Nullable<>)))
? Nullable.GetUnderlyingType(toType)
: null;
if (fromType == toType || fromType == toType2)
{
return (T)v;
}
var cnv = TypeDescriptor.GetConverter(fromType);
if (toType == typeof(DateTime) || toType2 == typeof(DateTime)) //Handle dates
{
if (fromType == typeof(TimeSpan))
{
return ((T)(object)(new DateTime(((TimeSpan)v).Ticks)));
}
else if (fromType == typeof(string))
{
DateTime dt;
if (DateTime.TryParse(v.ToString(), out dt))
{
return (T)(object)(dt);
}
else
{
return default(T);
}
}
else
{
if (cnv.CanConvertTo(typeof(double)))
{
return (T)(object)(DateTime.FromOADate((double)cnv.ConvertTo(v, typeof(double))));
}
else
{
return default(T);
}
}
}
else if (toType == typeof(TimeSpan) || toType2 == typeof(TimeSpan)) //Handle timespan
{
if (fromType == typeof(DateTime))
{
return ((T)(object)(new TimeSpan(((DateTime)v).Ticks)));
}
else if (fromType == typeof(string))
{
TimeSpan ts;
if (TimeSpan.TryParse(v.ToString(), out ts))
{
return (T)(object)(ts);
}
else
{
return default(T);
}
}
else
{
if (cnv.CanConvertTo(typeof(double)))
{
return (T)(object)(new TimeSpan(DateTime.FromOADate((double)cnv.ConvertTo(v, typeof(double))).Ticks));
}
else
{
try
{
// Issue 14682 -- "GetValue<decimal>() won't convert strings"
// As suggested, after all special cases, all .NET to do it's
// preferred conversion rather than simply returning the default
return (T)Convert.ChangeType(v, typeof(T));
}
catch (Exception)
{
// This was the previous behaviour -- no conversion is available.
return default(T);
}
}
}
}
else
{
if (cnv.CanConvertTo(toType))
{
return (T)cnv.ConvertTo(v, typeof(T));
}
else
{
if (toType2 != null)
{
toType = toType2;
if (cnv.CanConvertTo(toType))
{
return (T)cnv.ConvertTo(v, toType); //Fixes issue 15377
}
}
if (fromType == typeof(double) && toType == typeof(decimal))
{
return (T)(object)Convert.ToDecimal(v);
}
else if (fromType == typeof(decimal) && toType == typeof(double))
{
return (T)(object)Convert.ToDouble(v);
}
else
{
return default(T);
}
}
}
}
19
Source : PriceFormatConverter.cs
with Apache License 2.0
from AppRopio
with Apache License 2.0
from AppRopio
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
return null;
var price = System.Convert.ToDecimal(value);
var format = parameter as NumberFormatInfo ?? _defaultFormat;
if (!string.IsNullOrEmpty(CurrencySymbol))
format.CurrencySymbol = CurrencySymbol;
return price.ToString(CurrencyFormat, format);
}
19
Source : PriceFormatUnitConverter.cs
with Apache License 2.0
from AppRopio
with Apache License 2.0
from AppRopio
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
return null;
var price = System.Convert.ToDecimal(value);
var priceString = string.Empty;
var unitParameter = parameter as PriceFormatUnitParameter ?? new PriceFormatUnitParameter();
var format = unitParameter.Format;
if (!string.IsNullOrEmpty(unitParameter.CurrencySymbol))
format.CurrencySymbol = unitParameter.CurrencySymbol;
if (!unitParameter.PrefixString.IsNullOrEmpty())
priceString += unitParameter.PrefixString;
priceString += price.ToString(unitParameter.CurrencyFormat, format);
if (!unitParameter.UnitName.IsNullOrEmpty())
priceString += $"/{unitParameter.UnitName}";
if (parameter is string strFormating)
return string.Format(strFormating, priceString);
return priceString;
}
19
Source : ExpressionEvaluator.cs
with MIT License
from aprilyush
with MIT License
from aprilyush
private static bool ConvertToBool(object value)
{
if (value is bool)
{
return (bool)value;
}
else
{
return Convert.ToDecimal(value) == 1;
}
}
19
Source : ExpressionEvaluator.cs
with MIT License
from aprilyush
with MIT License
from aprilyush
private static decimal ConvertToDecimal(object value)
{
if (value is bool)
{
return ((bool)value ? 1 : 0);
}
else
{
return Convert.ToDecimal(value);
}
}
19
Source : Utility.cs
with MIT License
from aprilyush
with MIT License
from aprilyush
public static decimal ConverToDecimal(object value)
{
if (value == null || value == DBNull.Value) return 0M;
decimal v;
try
{
v = Convert.ToDecimal(value);
}
catch
{
v = 0M;
}
return v;
}
19
Source : DecimalDynamicFieldMapping.cs
with MIT License
from aquilahkj
with MIT License
from aquilahkj
public override object ToProperty (object value)
{
if (Equals (value, DBNull.Value) || Equals (value, null)) {
return null;
}
if (value.GetType() != ObjectType)
{
value = Convert.ToDecimal(value);
}
return value;
}
19
Source : DecimalFieldMapping.cs
with MIT License
from aquilahkj
with MIT License
from aquilahkj
public override object ToProperty(object value)
{
if (Equals(value, DBNull.Value) || Equals(value, null))
{
return null;
}
if (value.GetType() != ObjectType)
{
value = Convert.ToDecimal(value);
}
return value;
}
19
Source : MssqlProvider.cs
with MIT License
from aquilahkj
with MIT License
from aquilahkj
public override IDataParameter CreateParameter(string name, object value, string dbType, ParameterDirection direction, Type dataType, CommandType commandType)
{
var parameterName = name;
if (!parameterName.StartsWith(ParameterPrefix, StringComparison.Ordinal)) {
parameterName = ParameterPrefix + parameterName;
}
var sp = new SqlParameter() {
ParameterName = parameterName,
Direction = direction
};
if (value == null) {
sp.Value = DBNull.Value;
if (string.IsNullOrEmpty(dbType) && dataType != null) {
if (ConvertDbType(dataType, out var sqlType)) {
sp.SqlDbType = sqlType;
}
}
}
else if (value is sbyte) {
sp.Value = Convert.ToInt16(value);
}
else if (value is ushort) {
sp.Value = Convert.ToInt32(value);
}
else if (value is uint) {
sp.Value = Convert.ToInt64(value);
}
else if (value is ulong) {
sp.Value = Convert.ToDecimal(value);
}
else {
sp.Value = value;
}
if (!string.IsNullOrEmpty(dbType)) {
if (!dbTypeDict.TryGetValue(dbType, out var info)) {
lock (dbTypeDict) {
if (!dbTypeDict.TryGetValue(dbType, out info)) {
info = new DbTypeInfo();
try {
if (ParseSqlDbType(dbType, out var sqlType)) {
info.SqlDbType = sqlType;
}
else if (Utility.ParseDbType(dbType, out var dType)) {
info.DbType = dType;
}
if (Utility.ParseSize(dbType, out var size, out var scale)) {
info.Size = size;
info.Scale = scale;
}
}
catch (Exception ex) {
info.InnerException = ex;
}
finally {
dbTypeDict.Add(dbType, info);
}
}
}
}
if (info != null) {
if (info.InnerException != null) {
throw info.InnerException;
}
if (info.SqlDbType != null) {
sp.SqlDbType = info.SqlDbType.Value;
}
else if (info.DbType != null) {
sp.DbType = info.DbType.Value;
}
if (info.Size != null) {
if (sp.SqlDbType == SqlDbType.Decimal) {
sp.Precision = (byte)info.Size.Value;
}
else {
sp.Size = info.Size.Value;
}
}
if (info.Scale != null) {
sp.Scale = info.Scale.Value;
}
}
}
return sp;
}
19
Source : PostgreProvider.cs
with MIT License
from aquilahkj
with MIT License
from aquilahkj
public override IDataParameter CreateParameter(string name, object value, string dbType,
ParameterDirection direction, Type dataType, CommandType commandType)
{
var parameterName = name;
if (commandType == CommandType.StoredProcedure)
{
if (parameterName.StartsWith(ParameterPrefix, StringComparison.Ordinal))
{
parameterName = parameterName.TrimStart(ParameterPrefix[0]);
}
}
else
{
if (!parameterName.StartsWith(ParameterPrefix, StringComparison.Ordinal))
{
parameterName = ParameterPrefix + parameterName;
}
}
var sp = new NpgsqlParameter()
{
ParameterName = parameterName,
Direction = direction
};
if (value == null)
{
sp.Value = DBNull.Value;
if (string.IsNullOrEmpty(dbType) && dataType != null)
{
if (ConvertDbType(dataType, out var sqlType))
{
sp.NpgsqlDbType = sqlType;
}
}
}
else if (value is UInt16)
{
sp.Value = Convert.ToInt32(value);
}
else if (value is UInt32)
{
sp.Value = Convert.ToInt64(value);
}
else if (value is UInt64)
{
sp.Value = Convert.ToDecimal(value);
}
else
{
sp.Value = value;
}
if (!string.IsNullOrEmpty(dbType))
{
if (!dbTypeDict.TryGetValue(dbType, out var info))
{
lock (dbTypeDict)
{
if (!dbTypeDict.TryGetValue(dbType, out info))
{
info = new DbTypeInfo();
try
{
if (ParseSqlDbType(dbType, out var sqlType))
{
info.NpgsqlDbType = sqlType;
}
else if (Utility.ParseDbType(dbType, out var dType))
{
info.DbType = dType;
}
if (Utility.ParseSize(dbType, out var size, out var scale))
{
info.Size = size;
info.Scale = scale;
}
}
catch (Exception ex)
{
info.InnerException = ex;
}
finally
{
dbTypeDict.Add(dbType, info);
}
}
}
}
if (info != null)
{
if (info.InnerException != null)
{
throw info.InnerException;
}
if (info.NpgsqlDbType != null)
{
sp.NpgsqlDbType = info.NpgsqlDbType.Value;
}
else if (info.DbType != null)
{
sp.DbType = info.DbType.Value;
}
if (info.Size != null)
{
if (sp.NpgsqlDbType == NpgsqlDbType.Numeric)
{
sp.Precision = (byte) info.Size.Value;
}
else
{
sp.Size = info.Size.Value;
}
}
if (info.Scale != null && sp.NpgsqlDbType == NpgsqlDbType.Numeric)
{
sp.Scale = info.Scale.Value;
}
}
}
return sp;
}
19
Source : DomainHelper.cs
with MIT License
from ark-mod
with MIT License
from ark-mod
public override void WriteJson(
JsonWriter writer,
object value,
JsonSerializer serializer)
{
if (value == null)
{
writer.WriteNull();
return;
}
decimal f = Convert.ToDecimal(value);
writer.WriteValue(Math.Round(f, 2));
}
19
Source : Configuration.cs
with GNU General Public License v3.0
from ASCOMInitiative
with GNU General Public License v3.0
from ASCOMInitiative
public void SetValueInvariant<T>(string KeyName, string SubKey, T Value)
{
if (LOG_CONFIGURATION_CALLS) ServerForm.LogMessage(0, 0, 0, "SetValue DateTime", string.Format("Setting {0} value '{1}' in subkey '{2}' to: '{3}'", typeof(T).Name, KeyName, SubKey, Value.ToString()));
if ((typeof(T) == typeof(Int32)) | (typeof(T) == typeof(int)))
{
int intValue = Convert.ToInt32(Value);
if (SubKey == "") baseRegistryKey.SetValue(KeyName, intValue.ToString(CultureInfo.InvariantCulture));
else baseRegistryKey.CreateSubKey(SubKey).SetValue(KeyName, intValue.ToString(CultureInfo.InvariantCulture));
return;
}
if (typeof(T) == typeof(bool))
{
bool boolValue = Convert.ToBoolean(Value);
if (SubKey == "") baseRegistryKey.SetValue(KeyName, boolValue.ToString(CultureInfo.InvariantCulture));
else baseRegistryKey.CreateSubKey(SubKey).SetValue(KeyName, boolValue.ToString(CultureInfo.InvariantCulture));
return;
}
if (typeof(T) == typeof(decimal))
{
decimal decimalValue = Convert.ToDecimal(Value);
if (SubKey == "") baseRegistryKey.SetValue(KeyName, decimalValue.ToString(CultureInfo.InvariantCulture));
else baseRegistryKey.CreateSubKey(SubKey).SetValue(KeyName, decimalValue.ToString(CultureInfo.InvariantCulture));
return;
}
if (typeof(T) == typeof(DateTime))
{
DateTime dateTimeValue = Convert.ToDateTime(Value);
if (SubKey == "") baseRegistryKey.SetValue(KeyName, dateTimeValue.ToString("HH:mm:ss", CultureInfo.InvariantCulture));
else baseRegistryKey.CreateSubKey(SubKey).SetValue(KeyName, dateTimeValue.ToString("HH:mm:ss", CultureInfo.InvariantCulture));
return;
}
throw new DriverException("SetValueInvariant: Unknown type: " + typeof(T).Name);
}
19
Source : Configuration.cs
with GNU General Public License v3.0
from ASCOMInitiative
with GNU General Public License v3.0
from ASCOMInitiative
public T GetValue<T>(string KeyName, string SubKey, T DefaultValue)
{
if (LOG_CONFIGURATION_CALLS) ServerForm.LogMessage(0, 0, 0, "GetValue", string.Format("Getting {0} value '{1}' in subkey '{2}', default: '{3}'", typeof(T).Name, KeyName, SubKey, DefaultValue.ToString()));
if (typeof(T) == typeof(bool))
{
string registryValue;
if (SubKey == "")
{
if (LOG_CONFIGURATION_CALLS) ServerForm.LogMessage(0, 0, 0, "GetValue", "SubKey is empty so getting value directly");
registryValue = (string)baseRegistryKey.GetValue(KeyName);
if (LOG_CONFIGURATION_CALLS) ServerForm.LogMessage(0, 0, 0, "GetValue", "Value retrieved OK: " + registryValue);
}
else
{
if (LOG_CONFIGURATION_CALLS) ServerForm.LogMessage(0, 0, 0, "GetValue", "SubKey has a value so using it...");
registryValue = (string)baseRegistryKey.CreateSubKey(SubKey).GetValue(KeyName);
if (LOG_CONFIGURATION_CALLS) ServerForm.LogMessage(0, 0, 0, "GetValue", "Value retrieved OK: " + registryValue);
}
if (registryValue == null)
{
SetValueInvariant<T>(KeyName, SubKey, DefaultValue);
bool defaultValue = Convert.ToBoolean(DefaultValue);
registryValue = defaultValue.ToString(CultureInfo.InvariantCulture);
}
bool RetVal = Convert.ToBoolean(registryValue, CultureInfo.InvariantCulture);
if (LOG_CONFIGURATION_CALLS) ServerForm.LogMessage(0, 0, 0, "GetValue", string.Format("Retrieved {0} = {1}", KeyName, RetVal.ToString()));
return (T)((object)RetVal);
}
if (typeof(T) == typeof(string))
{
string RetVal;
if (SubKey == "")
{
if (LOG_CONFIGURATION_CALLS) ServerForm.LogMessage(0, 0, 0, "GetValue", "SubKey is empty so getting value directly");
RetVal = (string)baseRegistryKey.GetValue(KeyName);
if (LOG_CONFIGURATION_CALLS) ServerForm.LogMessage(0, 0, 0, "GetValue", "Value retrieved OK: " + RetVal);
}
else
{
if (LOG_CONFIGURATION_CALLS) ServerForm.LogMessage(0, 0, 0, "GetValue", "SubKey has a value so using it...");
RetVal = (string)baseRegistryKey.CreateSubKey(SubKey).GetValue(KeyName);
if (LOG_CONFIGURATION_CALLS) ServerForm.LogMessage(0, 0, 0, "GetValue", "Value retrieved OK: " + RetVal);
}
if (RetVal == null)
{
SetValue<T>(KeyName, SubKey, DefaultValue);
RetVal = DefaultValue.ToString();
}
if (LOG_CONFIGURATION_CALLS) ServerForm.LogMessage(0, 0, 0, "GetValue", string.Format("Retrieved {0} = {1}", KeyName, RetVal.ToString()));
return (T)((object)RetVal);
}
if (typeof(T) == typeof(decimal))
{
string registryValue;
if (SubKey == "")
{
if (LOG_CONFIGURATION_CALLS) ServerForm.LogMessage(0, 0, 0, "GetValue", "SubKey is empty so getting value directly");
registryValue = (string)baseRegistryKey.GetValue(KeyName);
if (LOG_CONFIGURATION_CALLS) ServerForm.LogMessage(0, 0, 0, "GetValue", "Value retrieved OK: " + registryValue);
}
else
{
if (LOG_CONFIGURATION_CALLS) ServerForm.LogMessage(0, 0, 0, "GetValue", "SubKey has a value so using it...");
registryValue = (string)baseRegistryKey.CreateSubKey(SubKey).GetValue(KeyName);
if (LOG_CONFIGURATION_CALLS) ServerForm.LogMessage(0, 0, 0, "GetValue", "Value retrieved OK: " + registryValue);
}
if (registryValue == null)
{
SetValueInvariant<T>(KeyName, SubKey, DefaultValue);
decimal defaultValue = Convert.ToDecimal(DefaultValue);
registryValue = defaultValue.ToString(CultureInfo.InvariantCulture);
}
decimal RetVal = Convert.ToDecimal(registryValue, CultureInfo.InvariantCulture);
if (LOG_CONFIGURATION_CALLS) ServerForm.LogMessage(0, 0, 0, "GetValue", string.Format("Retrieved {0} = {1}", KeyName, RetVal.ToString()));
return (T)((object)RetVal);
}
if (typeof(T) == typeof(DateTime))
{
string registryValue;
if (SubKey == "")
{
if (LOG_CONFIGURATION_CALLS) ServerForm.LogMessage(0, 0, 0, "GetValue", "SubKey is empty so getting value directly");
registryValue = (string)baseRegistryKey.GetValue(KeyName);
if (LOG_CONFIGURATION_CALLS) ServerForm.LogMessage(0, 0, 0, "GetValue", "Value retrieved OK: " + registryValue);
}
else
{
if (LOG_CONFIGURATION_CALLS) ServerForm.LogMessage(0, 0, 0, "GetValue", "SubKey has a value so using it...");
registryValue = (string)baseRegistryKey.CreateSubKey(SubKey).GetValue(KeyName);
if (LOG_CONFIGURATION_CALLS) ServerForm.LogMessage(0, 0, 0, "GetValue", "Value retrieved OK: " + registryValue);
}
if (registryValue == null)
{
SetValueInvariant<T>(KeyName, SubKey, DefaultValue);
return DefaultValue;
}
if (LOG_CONFIGURATION_CALLS) ServerForm.LogMessage(0, 0, 0, "GetValue DateTime", $"String value prior to Convert: {registryValue}");
if (DateTime.TryParse(registryValue, CultureInfo.InvariantCulture, DateTimeStyles.AllowWhiteSpaces, out DateTime RetVal))
{
// The string parsed OK so return the parsed value;
if (LOG_CONFIGURATION_CALLS) ServerForm.LogMessage(0, 0, 0, "GetValue DateTime", string.Format("Retrieved {0} = {1}", KeyName, RetVal.ToString()));
return (T)((object)RetVal);
}
else // If the string fails to parse, overwrite with the default value and return this
{
if (LOG_CONFIGURATION_CALLS) ServerForm.LogMessage(0, 0, 0, "GetValue DateTime", $"Failed to parse registry value, persisting and returning the default value: {DefaultValue}");
SetValueInvariant<T>(KeyName, SubKey, DefaultValue);
return DefaultValue;
}
}
if ((typeof(T) == typeof(Int32)) | (typeof(T) == typeof(int)))
{
string registryValue;
if (SubKey == "")
{
if (LOG_CONFIGURATION_CALLS) ServerForm.LogMessage(0, 0, 0, "GetValue", "SubKey is empty so getting value directly");
registryValue = (string)baseRegistryKey.GetValue(KeyName);
if (LOG_CONFIGURATION_CALLS) ServerForm.LogMessage(0, 0, 0, "GetValue", "Value retrieved OK: " + registryValue);
}
else
{
if (LOG_CONFIGURATION_CALLS) ServerForm.LogMessage(0, 0, 0, "GetValue", "SubKey has a value so using it...");
registryValue = (string)baseRegistryKey.CreateSubKey(SubKey).GetValue(KeyName);
if (LOG_CONFIGURATION_CALLS) ServerForm.LogMessage(0, 0, 0, "GetValue", "Value retrieved OK: " + registryValue);
}
if (registryValue == null)
{
SetValueInvariant<T>(KeyName, SubKey, DefaultValue);
int defaultValue = Convert.ToInt32(DefaultValue);
registryValue = defaultValue.ToString(CultureInfo.InvariantCulture);
}
int RetVal = Convert.ToInt32(registryValue, CultureInfo.InvariantCulture);
if (LOG_CONFIGURATION_CALLS) ServerForm.LogMessage(0, 0, 0, "GetValue", string.Format("Retrieved {0} = {1}", KeyName, RetVal.ToString()));
return (T)((object)RetVal);
}
throw new DriverException("GetValue: Unknown type: " + typeof(T).Name);
}
19
Source : Math.cs
with GNU Lesser General Public License v2.1
from axiom3d
with GNU Lesser General Public License v2.1
from axiom3d
public static object Evaluate (object a, object b, TypeCode tc, ExpressionType et)
{
switch (tc) {
case TypeCode.Boolean:
return Evaluate (Convert.ToBoolean (a), Convert.ToBoolean (b), et);
case TypeCode.Char:
return Evaluate (Convert.ToChar (a), Convert.ToChar (b), et);
case TypeCode.Byte:
return unchecked ((Byte) Evaluate (Convert.ToByte (a), Convert.ToByte (b), et));
case TypeCode.Decimal:
return Evaluate (Convert.ToDecimal (a), Convert.ToDecimal (b), et);
case TypeCode.Double:
return Evaluate (Convert.ToDouble (a), Convert.ToDouble (b), et);
case TypeCode.Int16:
return unchecked ((Int16) Evaluate (Convert.ToInt16 (a), Convert.ToInt16 (b), et));
case TypeCode.Int32:
return Evaluate (Convert.ToInt32 (a), Convert.ToInt32 (b), et);
case TypeCode.Int64:
return Evaluate (Convert.ToInt64 (a), Convert.ToInt64 (b), et);
case TypeCode.UInt16:
return unchecked ((UInt16) Evaluate (Convert.ToUInt16 (a), Convert.ToUInt16 (b), et));
case TypeCode.UInt32:
return Evaluate (Convert.ToUInt32 (a), Convert.ToUInt32 (b), et);
case TypeCode.UInt64:
return Evaluate (Convert.ToUInt64 (a), Convert.ToUInt64 (b), et);
case TypeCode.SByte:
return unchecked ((SByte) Evaluate (Convert.ToSByte (a), Convert.ToSByte (b), et));
case TypeCode.Single:
return Evaluate (Convert.ToSingle (a), Convert.ToSingle (b), et);
}
throw new NotImplementedException ();
}
19
Source : Math.cs
with GNU Lesser General Public License v2.1
from axiom3d
with GNU Lesser General Public License v2.1
from axiom3d
public static object NegateChecked (object a, TypeCode tc)
{
switch (tc) {
case TypeCode.Char:
return checked (-Convert.ToChar (a));
case TypeCode.Byte:
return checked (-Convert.ToByte (a));
case TypeCode.Decimal:
return checked (-Convert.ToDecimal (a));
case TypeCode.Double:
return checked (-Convert.ToDouble (a));
case TypeCode.Int16:
return checked (-Convert.ToInt16 (a));
case TypeCode.Int32:
return checked (-Convert.ToInt32 (a));
case TypeCode.Int64:
return checked (-Convert.ToInt64 (a));
case TypeCode.UInt16:
return checked (-Convert.ToUInt16 (a));
case TypeCode.UInt32:
return checked (-Convert.ToUInt32 (a));
case TypeCode.SByte:
return checked (-Convert.ToSByte (a));
case TypeCode.Single:
return checked (-Convert.ToSingle (a));
}
throw new NotImplementedException ();
}
19
Source : Math.cs
with GNU Lesser General Public License v2.1
from axiom3d
with GNU Lesser General Public License v2.1
from axiom3d
public static object Negate (object a, TypeCode tc)
{
switch (tc) {
case TypeCode.Char:
return unchecked (-Convert.ToChar (a));
case TypeCode.Byte:
return unchecked (-Convert.ToByte (a));
case TypeCode.Decimal:
return unchecked (-Convert.ToDecimal (a));
case TypeCode.Double:
return unchecked (-Convert.ToDouble (a));
case TypeCode.Int16:
return unchecked (-Convert.ToInt16 (a));
case TypeCode.Int32:
return unchecked (-Convert.ToInt32 (a));
case TypeCode.Int64:
return unchecked (-Convert.ToInt64 (a));
case TypeCode.UInt16:
return unchecked (-Convert.ToUInt16 (a));
case TypeCode.UInt32:
return unchecked (-Convert.ToUInt32 (a));
case TypeCode.SByte:
return unchecked (-Convert.ToSByte (a));
case TypeCode.Single:
return unchecked (-Convert.ToSingle (a));
}
throw new NotImplementedException ();
}
19
Source : MathConverter.cs
with MIT License
from ay2015
with MIT License
from ay2015
public decimal Eval(object[] args)
{
if (_index >= args.Length)
{
throw new ArgumentException(String.Format("MathConverter: parameter index {0} is out of range. {1} parameter(s) supplied", _index, args.Length));
}
return System.Convert.ToDecimal(args[_index]);
}
19
Source : Evaluator.cs
with Apache License 2.0
from azizamari
with Apache License 2.0
from azizamari
private object EvaluateConversionExpression(BoundConversionExpression node)
{
var value = EvaluateExpression(node.Expression);
if (node.Type == TypeSymbol.Bool)
return Convert.ToBoolean(value);
else if (node.Type == TypeSymbol.Int)
try
{
return Convert.ToInt32(value);
}
catch (Exception)
{
_diagnostics.ReportCannotConvertToInt(node.Location, value);
return new BoundErrorExpression();
}
else if (node.Type == TypeSymbol.String)
return Convert.ToString(value);
else if (node.Type == TypeSymbol.Decimal)
{
try
{
return Convert.ToDecimal(value);
}
catch (Exception)
{
_diagnostics.ReportCannotConvertToDecimal(node.Location, value);
return new BoundErrorExpression();
}
}
else
throw new Exception($"Unexpected type {node.Type}");
}
19
Source : Evaluator.cs
with Apache License 2.0
from azizamari
with Apache License 2.0
from azizamari
private object EvaluateBinaryExpression(BoundBinaryExpression b)
{
var left = EvaluateExpression(b.Left);
var right = EvaluateExpression(b.Right);
switch (b.Op.Kind)
{
case BoundBinaryOperatorKind.Addition:
{
if (b.Type == TypeSymbol.String)
return (string)left + (string)right;
var res= Convert.ToDecimal(left) + Convert.ToDecimal(right);
if (b.Type == TypeSymbol.Decimal)
return res;
return (int)res;
}
case BoundBinaryOperatorKind.Substraction:
{
var res = Convert.ToDecimal(left) - Convert.ToDecimal(right);
if (b.Type == TypeSymbol.Decimal)
return res;
return (int)res;
}
case BoundBinaryOperatorKind.Multiplication:
{
var res = Convert.ToDecimal(left) * Convert.ToDecimal(right);
if (b.Type == TypeSymbol.Decimal)
return res;
return (int)res;
}
case BoundBinaryOperatorKind.Power:
{
var res = Convert.ToDecimal(Math.Pow(Convert.ToDouble(left), Convert.ToDouble(right)));
if (b.Type == TypeSymbol.Decimal)
return res;
return (int)res;
}
case BoundBinaryOperatorKind.EuclidianDivision:
return (int)left / (int)right;
case BoundBinaryOperatorKind.DecimalDivision:
return Convert.ToDecimal(left) / Convert.ToDecimal(right);
case BoundBinaryOperatorKind.DivisionRemainder:
return (int)left % (int)right;
case BoundBinaryOperatorKind.BitwiseAnd:
if(b.Type==TypeSymbol.Int)
return (int)left & (int)right;
else
return (bool)left & (bool)right;
case BoundBinaryOperatorKind.BitwiseOr:
if (b.Type == TypeSymbol.Int)
return (int)left | (int)right;
else
return (bool)left | (bool)right;
case BoundBinaryOperatorKind.BitwiseXor:
if (b.Type == TypeSymbol.Int)
return (int)left ^ (int)right;
else
return (bool)left ^ (bool)right;
case BoundBinaryOperatorKind.LogicalAnd:
return (bool)left && (bool)right;
case BoundBinaryOperatorKind.LogicalOr:
return (bool)left || (bool)right;
case BoundBinaryOperatorKind.LessThan:
if (b.Type == TypeSymbol.String)
return string.Compare(Convert.ToString(left) , Convert.ToString(right), StringComparison.Ordinal)<0;
return Convert.ToDecimal(left)< Convert.ToDecimal(right);
case BoundBinaryOperatorKind.LessThanOrEquals:
if (b.Type == TypeSymbol.String)
return string.Compare(Convert.ToString(left), Convert.ToString(right), StringComparison.Ordinal) <= 0;
return Convert.ToDecimal(left) <= Convert.ToDecimal(right);
case BoundBinaryOperatorKind.GreaterThan:
if (b.Type == TypeSymbol.String)
return string.Compare(Convert.ToString(left), Convert.ToString(right), StringComparison.Ordinal)>0;
return Convert.ToDecimal(left) > Convert.ToDecimal(right);
case BoundBinaryOperatorKind.GreaterThanOrEquals:
if (b.Type == TypeSymbol.String)
return string.Compare(Convert.ToString(left), Convert.ToString(right), StringComparison.Ordinal) >= 0;
return Convert.ToDecimal(left) >= Convert.ToDecimal(right);
case BoundBinaryOperatorKind.Equals:
{
if (b.Left.Type == TypeSymbol.Decimal ^ b.Right.Type == TypeSymbol.Decimal)
{
return Equals(Convert.ToDecimal(left), Convert.ToDecimal(right));
}
return Equals(left, right);
}
case BoundBinaryOperatorKind.NotEquals:
{
if (b.Left.Type == TypeSymbol.Decimal ^ b.Right.Type == TypeSymbol.Decimal)
{
return !Equals(Convert.ToDecimal(left), Convert.ToDecimal(right));
}
return !Equals(left, right);
}
default:
throw new Exception($"Unexpected Operator {b.Op.Kind}");
}
}
19
Source : Kit.Attribute.cs
with MIT License
from BigBigZBBing
with MIT License
from BigBigZBBing
static bool NumericValidation(FastProperty propertie, NumericRuleAttribute attr, StringBuilder strBuilder)
{
string Name = propertie.PropertyName;
object Value = propertie.Get();
if (attr.Greater.NotNull(false) && Value.NotNull(false) && Convert.ToDecimal(Value) > Convert.ToDecimal(attr.Greater))
{
strBuilder.AppendLine(string.Format(attr.Message, Name, attr.Name, Value ?? "NULL", $"不能大于{attr.Greater}"));
return false;
}
if (attr.Less.NotNull(false) && Value.NotNull(false) && Convert.ToDecimal(Value) < Convert.ToDecimal(attr.Less))
{
strBuilder.AppendLine(string.Format(attr.Message, Name, attr.Name, Value ?? "NULL", $"不能小于{attr.Less}"));
return false;
}
if (attr.Equal.NotNull(false) && Value.NotNull(false) && Convert.ToDecimal(Value) == Convert.ToDecimal(attr.Equal))
{
strBuilder.AppendLine(string.Format(attr.Message, Name, attr.Name, Value ?? "NULL", $"不能等于{attr.Equal}"));
return false;
}
if (attr.NoEqual.NotNull(false) && Value.NotNull(false) && Convert.ToDecimal(Value) != Convert.ToDecimal(attr.NoEqual))
{
strBuilder.AppendLine(string.Format(attr.Message, Name, attr.Name, Value ?? "NULL", $"必须等于{attr.NoEqual}"));
return false;
}
return true;
}
19
Source : AdapterGX.cs
with MIT License
from BigBigZBBing
with MIT License
from BigBigZBBing
internal static void EmitValue(this EmitBasic basic, Object value, Type type)
{
if (type == typeof(String))
{
basic.Emit(OpCodes.Ldstr, Convert.ToString(value));
}
else if (type == typeof(Boolean))
{
switch (Convert.ToBoolean(value))
{
case true: basic.Emit(OpCodes.Ldc_I4_1); break;
case false: basic.Emit(OpCodes.Ldc_I4_0); break;
default: throw new Exception("boolean to error!");
}
}
else if (type == typeof(SByte))
{
basic.IntegerMap(Convert.ToSByte(value));
}
else if (type == typeof(Byte))
{
basic.IntegerMap((SByte)Convert.ToByte(value));
}
else if (type == typeof(Int16))
{
basic.IntegerMap(Convert.ToInt16(value));
}
else if (type == typeof(UInt16))
{
basic.IntegerMap((Int16)Convert.ToUInt16(value));
}
else if (type == typeof(Int32))
{
basic.IntegerMap(Convert.ToInt32(value));
}
else if (type == typeof(UInt32))
{
basic.IntegerMap((Int32)Convert.ToUInt32(value));
}
else if (type == typeof(Int64))
{
basic.IntegerMap(Convert.ToInt64(value));
}
else if (type == typeof(UInt64))
{
basic.IntegerMap((Int64)Convert.ToUInt64(value));
}
else if (type == typeof(Single))
{
basic.Emit(OpCodes.Ldc_R4, Convert.ToSingle(value));
}
else if (type == typeof(Double))
{
basic.Emit(OpCodes.Ldc_R8, Convert.ToDouble(value));
}
else if (type == typeof(Decimal))
{
Int32[] bits = Decimal.GetBits(Convert.ToDecimal(value));
basic.IntegerMap(bits[0]);
basic.IntegerMap(bits[1]);
basic.IntegerMap(bits[2]);
basic.Emit((bits[3] & 0x80000000) != 0 ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0);
basic.IntegerMap((bits[3] >> 16) & 0x7f);
basic.Emit(OpCodes.Newobj, typeof(Decimal)
.GetConstructor(new Type[] { typeof(Int32), typeof(Int32), typeof(Int32), typeof(Boolean), typeof(Byte) }));
}
else if (type == typeof(DateTime))
{
basic.Emit(OpCodes.Ldc_I8, Convert.ToDateTime(value).Ticks);
basic.Emit(OpCodes.Newobj, typeof(DateTime).GetConstructor(new Type[] { typeof(Int64) }));
}
else
{
throw new Exception("not exist datatype!");
}
}
19
Source : Kit.Attribute.cs
with MIT License
from BigBigZBBing
with MIT License
from BigBigZBBing
static bool DecimalValidation(FastProperty propertie, DecimalRuleAttribute attr, StringBuilder strBuilder)
{
string Name = propertie.PropertyName;
object Value = propertie.Get();
if (attr.Greater.NotNull(false) && Value.NotNull(false) && Convert.ToDecimal(Value) > Convert.ToDecimal(attr.Greater))
{
strBuilder.AppendLine(string.Format(attr.Message, Name, attr.Name, Value ?? "NULL", $"不能大于{attr.Greater}"));
return false;
}
if (attr.Less.NotNull(false) && Value.NotNull(false) && Convert.ToDecimal(Value) < Convert.ToDecimal(attr.Less))
{
strBuilder.AppendLine(string.Format(attr.Message, Name, attr.Name, Value ?? "NULL", $"不能小于{attr.Less}"));
return false;
}
if (attr.Equal.NotNull(false) && Value.NotNull(false) && Convert.ToDecimal(Value) == Convert.ToDecimal(attr.Equal))
{
strBuilder.AppendLine(string.Format(attr.Message, Name, attr.Name, Value ?? "NULL", $"不能等于{attr.Equal}"));
return false;
}
if (attr.NoEqual.NotNull(false) && Value.NotNull(false) && Convert.ToDecimal(Value) != Convert.ToDecimal(attr.NoEqual))
{
strBuilder.AppendLine(string.Format(attr.Message, Name, attr.Name, Value ?? "NULL", $"必须等于{attr.NoEqual}"));
return false;
}
if (attr.Precision.NotNull(false) && Value.NotNull(false) && Convert.ToDecimal(Value).GetPrecision() > (int?)attr.Precision)
{
strBuilder.AppendLine(string.Format(attr.Message, Name, attr.Name, Value ?? "NULL", $"精度不能超过{attr.Precision}"));
return false;
}
return true;
}
19
Source : AdapterGX.cs
with MIT License
from BigBigZBBing
with MIT License
from BigBigZBBing
internal static void EmitValue<T>(this EmitBasic basic, T value)
{
if (value == null)
{
basic.Emit(OpCodes.Ldnull);
}
else if (value.GetType() == typeof(String))
{
basic.Emit(OpCodes.Ldstr, Convert.ToString(value));
}
else if (value.GetType() == typeof(Boolean))
{
switch (Convert.ToBoolean(value))
{
case true: basic.Emit(OpCodes.Ldc_I4_1); break;
case false: basic.Emit(OpCodes.Ldc_I4_0); break;
default: throw new Exception("boolean to error!");
}
}
else if (value.GetType() == typeof(SByte))
{
basic.IntegerMap(Convert.ToSByte(value));
}
else if (value.GetType() == typeof(Byte))
{
basic.IntegerMap((SByte)Convert.ToByte(value));
}
else if (value.GetType() == typeof(Int16))
{
basic.IntegerMap(Convert.ToInt16(value));
}
else if (value.GetType() == typeof(UInt16))
{
basic.IntegerMap((Int16)Convert.ToUInt16(value));
}
else if (value.GetType() == typeof(Int32))
{
basic.IntegerMap(Convert.ToInt32(value));
}
else if (value.GetType() == typeof(UInt32))
{
basic.IntegerMap((Int32)Convert.ToUInt32(value));
}
else if (value.GetType() == typeof(Int64))
{
basic.IntegerMap(Convert.ToInt64(value));
}
else if (value.GetType() == typeof(UInt64))
{
basic.IntegerMap((Int64)Convert.ToUInt64(value));
}
else if (value.GetType() == typeof(Single))
{
basic.Emit(OpCodes.Ldc_R4, Convert.ToSingle(value));
}
else if (value.GetType() == typeof(Double))
{
basic.Emit(OpCodes.Ldc_R8, Convert.ToDouble(value));
}
else if (value.GetType() == typeof(Decimal))
{
Int32[] bits = Decimal.GetBits(Convert.ToDecimal(value));
basic.IntegerMap(bits[0]);
basic.IntegerMap(bits[1]);
basic.IntegerMap(bits[2]);
basic.Emit((bits[3] & 0x80000000) != 0 ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0);
basic.IntegerMap((bits[3] >> 16) & 0x7f);
basic.Emit(OpCodes.Newobj, typeof(Decimal)
.GetConstructor(new Type[] { typeof(Int32), typeof(Int32), typeof(Int32), typeof(Boolean), typeof(Byte) }));
}
else if (value.GetType() == typeof(DateTime))
{
basic.Emit(OpCodes.Ldc_I8, Convert.ToDateTime(value).Ticks);
basic.Emit(OpCodes.Newobj, typeof(DateTime).GetConstructor(new Type[] { typeof(Int64) }));
}
else if (value is Enum)
{
basic.IntegerMap(Convert.ToInt32(value));
}
else if (value.GetType().IsClreplaced)
{
basic.Emit(OpCodes.Newobj, value.GetType().GetConstructor(Type.EmptyTypes));
}
else
{
throw new Exception("not exist datatype!");
}
}
19
Source : NumericUpDownEditor.cs
with MIT License
from bonsai-rx
with MIT License
from bonsai-rx
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
var editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (context != null && editorService != null)
{
var decimalPlaces = 0;
var propertyDescriptor = context.PropertyDescriptor;
var propertyType = GetPropertyType(propertyDescriptor.PropertyType);
var range = (RangeAttribute)propertyDescriptor.Attributes[typeof(RangeAttribute)];
var typeCode = Type.GetTypeCode(propertyType);
var precision = (PrecisionAttribute)propertyDescriptor.Attributes[typeof(PrecisionAttribute)];
if (precision != null && (typeCode == TypeCode.Single || typeCode == TypeCode.Double || typeCode == TypeCode.Decimal))
{
decimalPlaces = precision.DecimalPlaces;
}
var numericUpDown = new PreviewNumericUpDown();
numericUpDown.Minimum = range.Minimum;
numericUpDown.Maximum = range.Maximum;
numericUpDown.DecimalPlaces = decimalPlaces;
if (precision != null)
{
numericUpDown.Increment = precision.Increment;
}
var changed = false;
var cancelled = false;
numericUpDown.Value = Math.Max(numericUpDown.Minimum, Math.Min(Convert.ToDecimal(value), numericUpDown.Maximum));
numericUpDown.PreviewKeyDown += (sender, e) => cancelled = e.KeyCode == Keys.Escape;
numericUpDown.ValueChanged += (sender, e) =>
{
changed = true;
propertyDescriptor.SetValue(context.Instance, Convert.ChangeType(numericUpDown.Value, propertyType));
};
editorService.DropDownControl(numericUpDown);
if (cancelled && changed) propertyDescriptor.SetValue(context.Instance, value);
return cancelled ? value : Convert.ChangeType(numericUpDown.Value, propertyType);
}
return base.EditValue(context, provider, value);
}
19
Source : EnumEqualityStep.cs
with Apache License 2.0
from BoundfoxStudios
with Apache License 2.0
from BoundfoxStudios
private static decimal? ExtractDecimal(object o)
{
return o != null ? Convert.ToDecimal(o) : (decimal?)null;
}
19
Source : JetDataReader.cs
with Apache License 2.0
from bubibubi
with Apache License 2.0
from bubibubi
public override decimal GetDecimal(int ordinal)
{
var value = _wrappedDataReader.GetValue(ordinal);
return JetConfiguration.UseDefaultValueOnDBNullConversionError &&
Convert.IsDBNull(value)
? default
: Convert.ToDecimal(value);
}
19
Source : PdfArray.cs
with Apache License 2.0
from cajuncoding
with Apache License 2.0
from cajuncoding
public void AddArray(Array data)
{
foreach (object entry in data)
{
Add(new PdfNumeric(Convert.ToDecimal(entry)));
}
}
19
Source : DeviceRuner.cs
with Apache License 2.0
from cdy816
with Apache License 2.0
from cdy816
private object ConvertValue(Tagbase tag, object value)
{
if (value == null) return null;
switch (tag.Type)
{
case TagType.Bool:
if (value is string)
{
var vtmp = value.ToString().ToLower();
if (vtmp == "true" || vtmp == "false")
{
return bool.Parse(value.ToString());
}
else
{
return Convert.ToBoolean(Convert.ToDecimal(value));
}
}
else if (value is byte[])
{
return BitConverter.ToBoolean(value as byte[]);
}
else
{
return Convert.ToBoolean(value);
}
case TagType.Byte:
if (value is string)
{
return byte.Parse(value.ToString());
}
else if (value is byte[])
{
return (value as byte[])[0];
}
else
{
return Convert.ToByte(value);
}
case TagType.DateTime:
if (value is string)
{
return DateTime.Parse(value.ToString());
}
else if (value is byte[])
{
return Convert.ToDateTime(BitConverter.ToInt64(value as byte[]));
}
else
{
return Convert.ToDateTime(value);
}
case TagType.Double:
if (value is string)
{
return double.Parse(value.ToString());
}
else if (value is byte[])
{
return BitConverter.ToDouble(value as byte[]);
}
else
{
return Convert.ToDouble(value);
}
case TagType.Float:
if (value is string)
{
return float.Parse(value.ToString());
}
else if (value is byte[])
{
return BitConverter.ToSingle(value as byte[]);
}
else
{
return Convert.ToSingle(value);
}
case TagType.Int:
if (value is string)
{
return int.Parse(value.ToString());
}
else if (value is byte[])
{
return BitConverter.ToInt32(value as byte[]);
}
else
{
return Convert.ToInt32(value);
}
case TagType.Long:
if (value is string)
{
return long.Parse(value.ToString());
}
else if (value is byte[])
{
return BitConverter.ToInt64(value as byte[]);
}
else
{
return Convert.ToInt64(value);
}
case TagType.Short:
if (value is string)
{
return short.Parse(value.ToString());
}
else if (value is byte[])
{
return BitConverter.ToInt16(value as byte[]);
}
else
{
return Convert.ToInt16(value);
}
case TagType.String:
if (value is byte[])
{
return Encoding.UTF8.GetString(value as byte[]);
}
else
{
return value.ToString();
}
case TagType.UInt:
if (value is string)
{
return uint.Parse(value.ToString());
}
else if (value is byte[])
{
return BitConverter.ToUInt32(value as byte[]);
}
else
{
return Convert.ToUInt32(value);
}
case TagType.ULong:
if (value is string)
{
return ulong.Parse(value.ToString());
}
else if (value is byte[])
{
return BitConverter.ToUInt64(value as byte[]);
}
else
{
return Convert.ToUInt64(value);
}
case TagType.UShort:
if (value is string)
{
return ushort.Parse(value.ToString());
}
else if (value is byte[])
{
return BitConverter.ToUInt16(value as byte[]);
}
else
{
return Convert.ToUInt16(value);
}
case TagType.IntPoint:
if (value is string)
{
string[] sval = value.ToString().Split(new char[] { ',' });
return new IntPoint() { X = int.Parse(sval[0]), Y = int.Parse(sval[1]) };
}
else if (value is byte[])
{
byte[] bval = value as byte[];
return new IntPoint() { X = BitConverter.ToInt32(bval.replacedpan(0, 4)), Y = BitConverter.ToInt32(bval.replacedpan(4, 4)) };
}
else
{
return (IntPoint)value;
}
case TagType.IntPoint3:
if (value is string)
{
string[] sval = value.ToString().Split(new char[] { ',' });
return new IntPoint3() { X = int.Parse(sval[0]), Y = int.Parse(sval[1]), Z = int.Parse(sval[2]) };
}
else if (value is byte[])
{
byte[] bval = value as byte[];
return new IntPoint3() { X = BitConverter.ToInt32(bval.replacedpan(0, 4)), Y = BitConverter.ToInt32(bval.replacedpan(4, 4)), Z = BitConverter.ToInt32(bval.replacedpan(8, 4)) };
}
else
{
return (IntPoint3)value;
}
case TagType.UIntPoint:
if (value is string)
{
string[] sval = value.ToString().Split(new char[] { ',' });
return new UIntPoint() { X = uint.Parse(sval[0]), Y = uint.Parse(sval[1]) };
}
else if (value is byte[])
{
byte[] bval = value as byte[];
return new UIntPoint() { X = BitConverter.ToUInt32(bval.replacedpan(0, 4)), Y = BitConverter.ToUInt32(bval.replacedpan(4, 4)) };
}
else
{
return (UIntPoint)value;
}
case TagType.UIntPoint3:
if (value is string)
{
string[] sval = value.ToString().Split(new char[] { ',' });
return new UIntPoint3() { X = uint.Parse(sval[0]), Y = uint.Parse(sval[1]), Z = uint.Parse(sval[2]) };
}
else if (value is byte[])
{
byte[] bval = value as byte[];
return new UIntPoint3() { X = BitConverter.ToUInt32(bval.replacedpan(0, 4)), Y = BitConverter.ToUInt32(bval.replacedpan(4, 4)), Z = BitConverter.ToUInt32(bval.replacedpan(8, 4)) };
}
else
{
return (UIntPoint3)value;
}
case TagType.LongPoint:
if (value is string)
{
string[] sval = value.ToString().Split(new char[] { ',' });
return new LongPoint() { X = long.Parse(sval[0]), Y = long.Parse(sval[1]) };
}
else if (value is byte[])
{
byte[] bval = value as byte[];
return new LongPoint() { X = BitConverter.ToInt64(bval.replacedpan(0, 8)), Y = BitConverter.ToInt64(bval.replacedpan(8, 8)) };
}
else
{
return (LongPoint)value;
}
case TagType.LongPoint3:
if (value is string)
{
string[] sval = value.ToString().Split(new char[] { ',' });
return new LongPoint3() { X = long.Parse(sval[0]), Y = long.Parse(sval[1]), Z = long.Parse(sval[2]) };
}
else if (value is byte[])
{
byte[] bval = value as byte[];
return new LongPoint3() { X = BitConverter.ToInt64(bval.replacedpan(0, 8)), Y = BitConverter.ToInt64(bval.replacedpan(8, 8)), Z = BitConverter.ToInt64(bval.replacedpan(16, 8)) };
}
else
{
return (LongPoint3)value;
}
case TagType.ULongPoint:
if (value is string)
{
string[] sval = value.ToString().Split(new char[] { ',' });
return new ULongPoint() { X = ulong.Parse(sval[0]), Y = ulong.Parse(sval[1]) };
}
else if (value is byte[])
{
byte[] bval = value as byte[];
return new ULongPoint() { X = BitConverter.ToUInt64(bval.replacedpan(0, 8)), Y = BitConverter.ToUInt64(bval.replacedpan(8, 8)) };
}
else
{
return (ULongPoint)value;
}
case TagType.ULongPoint3:
if (value is string)
{
string[] sval = value.ToString().Split(new char[] { ',' });
return new ULongPoint3() { X = ulong.Parse(sval[0]), Y = ulong.Parse(sval[1]), Z = ulong.Parse(sval[2]) };
}
else if (value is byte[])
{
byte[] bval = value as byte[];
return new ULongPoint3() { X = BitConverter.ToUInt64(bval.replacedpan(0, 8)), Y = BitConverter.ToUInt64(bval.replacedpan(8, 8)), Z = BitConverter.ToUInt64(bval.replacedpan(16, 8)) };
}
else
{
return (ULongPoint3)value;
}
}
return null;
}
19
Source : SqlTableDependencyFilter.cs
with MIT License
from christiandelbianco
with MIT License
from christiandelbianco
private string ToSqlFormat(Type type, object value)
{
if (type == typeof(bool)) return (bool)value ? "1" : "0";
if (type == typeof(string)) return value.ToString();
if (type == typeof(decimal)) return Convert.ToDecimal(value).ToString("g", CultureInfo.InvariantCulture);
if (type == typeof(double)) return Convert.ToDouble(value).ToString("g", CultureInfo.InvariantCulture);
if (type == typeof(DateTime)) return Convert.ToDateTime(value).ToString("s", CultureInfo.InvariantCulture);
return value.ToString();
}
19
Source : ObjectExtension.cs
with MIT License
from cixingguangming55555
with MIT License
from cixingguangming55555
public static decimal YusToDecimal(this object obj)
{
return Convert.ToDecimal(obj);
}
See More Examples