本文整理汇总了C#中Field.GetDefaultValue方法的典型用法代码示例。如果您正苦于以下问题:C# Field.GetDefaultValue方法的具体用法?C# Field.GetDefaultValue怎么用?C# Field.GetDefaultValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Field
的用法示例。
在下文中一共展示了Field.GetDefaultValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExtractFieldValue
public static object ExtractFieldValue(object value, Field field, bool encryptPasswordFields = false)
{
if (value == null)
return field.GetDefaultValue();
if (value is JToken)
value = ((JToken)value).ToObject<object>();
if (field is AutoNumberField)
{
if (value == null)
return null;
if (value is string)
return decimal.Parse(value as string);
return Convert.ToDecimal(value);
}
else if (field is CheckboxField)
return value as bool?;
else if (field is CurrencyField)
{
if (value == null)
return null;
if (value is string)
{
if (string.IsNullOrWhiteSpace(value as string))
return null;
if ((value as string).StartsWith("$"))
value = (value as string).Substring(1);
return decimal.Parse(value as string);
}
return Convert.ToDecimal(value);
}
else if (field is DateField)
{
if (value == null)
return null;
DateTime? date = null;
if (value is string)
{
if (string.IsNullOrWhiteSpace(value as string))
return null;
date = DateTime.Parse(value as string);
}
else
date = value as DateTime?;
if (date != null)
return new DateTime(date.Value.Year, date.Value.Month, date.Value.Day, 0, 0, 0, DateTimeKind.Utc);
}
else if (field is DateTimeField)
{
if (value == null)
return null;
if (value is string)
{
if (string.IsNullOrWhiteSpace(value as string))
return null;
return DateTime.Parse(value as string);
}
return value as DateTime?;
}
else if (field is EmailField)
return value as string;
else if (field is FileField)
//TODO convert file path to url path
return value as string;
else if (field is ImageField)
//TODO convert image path to url path
return value as string;
else if (field is HtmlField)
return value as string;
else if (field is MultiLineTextField)
return value as string;
else if (field is MultiSelectField)
{
if (value == null)
return null;
else if (value is JArray)
return ((JArray)value).Select(x => ((JToken)x).Value<string>()).ToList<string>();
else if (value is List<object>)
return ((List<object>)value).Select(x => ((object)x).ToString()).ToList<string>();
else if (value is string[])
return new List<string>(value as string[]);
else
return value as IEnumerable<string>;
}
else if (field is NumberField)
{
if (value == null)
return null;
if (value is string)
return decimal.Parse(value as string);
return Convert.ToDecimal(value);
//.........这里部分代码省略.........
示例2: ExtractFieldValue
//.........这里部分代码省略.........
else if (field is DateTimeField)
{
if (pair.Value == null)
return null;
if (pair.Value is string)
return DateTime.Parse(pair.Value as string);
return pair.Value as DateTime?;
}
else if (field is EmailField)
return pair.Value as string;
else if (field is FileField)
//TODO convert file path to url path
return pair.Value as string;
else if (field is ImageField)
//TODO convert image path to url path
return pair.Value as string;
else if (field is HtmlField)
return pair.Value as string;
else if (field is MultiLineTextField)
return pair.Value as string;
else if (field is MultiSelectField)
{
if (pair.Value == null)
return null;
else if (pair.Value is JArray)
return ((JArray)pair.Value).Select(x => ((JToken)x).Value<string>()).ToList<string>();
else if (pair.Value is List<object>)
return ((List<object>)pair.Value).Select(x => ((object)x).ToString()).ToList<string>();
else
return pair.Value as IEnumerable<string>;
}
else if (field is NumberField)
{
if (pair.Value == null)
return null;
if (pair.Value is string)
return decimal.Parse(pair.Value as string);
return Convert.ToDecimal(pair.Value);
}
else if (field is PasswordField)
{
if (encryptPasswordFields)
{
if (((PasswordField)field).Encrypted == true)
{
if (string.IsNullOrWhiteSpace(pair.Value as string))
return null;
return PasswordUtil.GetMd5Hash(pair.Value as string);
}
}
return pair.Value;
}
else if (field is PercentField)
{
if (pair.Value == null)
return null;
if (pair.Value is string)
return decimal.Parse(pair.Value as string);
return Convert.ToDecimal(pair.Value);
}
else if (field is PhoneField)
return pair.Value as string;
else if (field is GuidField)
{
if (pair.Value is string)
{
if (string.IsNullOrWhiteSpace(pair.Value as string))
return null;
return new Guid(pair.Value as string);
}
if (pair.Value is Guid)
return (Guid?)pair.Value;
if (pair.Value == null)
return (Guid?)null;
throw new Exception("Invalid Guid field value.");
}
else if (field is SelectField)
return pair.Value as string;
else if (field is TextField)
return pair.Value as string;
else if (field is UrlField)
return pair.Value as string;
}
else
{
return field.GetDefaultValue();
}
throw new Exception("System Error. A field type is not supported in field value extraction process.");
}
示例3: CreateRecordField
public void CreateRecordField(string entityName, Field field)
{
string tableName = RECORD_COLLECTION_PREFIX + entityName;
DbRepository.CreateColumn(tableName, field.Name, field.GetFieldType(), false, field.GetDefaultValue(), !field.Required, field.Unique);
if (field.Unique)
DbRepository.CreateUniqueConstraint("idx_u_" + entityName + "_" + field.Name, tableName, new List<string> { field.Name });
if (field.Searchable)
DbRepository.CreateIndex("idx_s_" + entityName + "_" + field.Name, tableName, field.Name);
}