本文整理汇总了C#中System.Dynamic.ExpandoObject.FirstOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# ExpandoObject.FirstOrDefault方法的具体用法?C# ExpandoObject.FirstOrDefault怎么用?C# ExpandoObject.FirstOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Dynamic.ExpandoObject
的用法示例。
在下文中一共展示了ExpandoObject.FirstOrDefault方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PostUpdate
public object PostUpdate(ExpandoObject objectToUpdate)
{
var typeOfObject = objectToUpdate.FirstOrDefault(x => x.Key == "typeOfObject").Value.ToString();
objectToUpdate = (ExpandoObject)objectToUpdate.FirstOrDefault(x => x.Key == "objectToUpdate").Value;
var ar = typeOfObject.Split(',');
var currentType = Type.GetType(ar[0] + ", " + ar[1]);
object ob = Activator.CreateInstance(currentType,null);
foreach (var prop in objectToUpdate)
{
var propKey = prop.Key;
PropertyInfo propI = currentType.GetProperty(propKey);
if (propI != null)
{
Helper.SetValue(ob, propI.Name, prop.Value);
}
}
var uioMaticAttri = (UIOMaticAttribute)Attribute.GetCustomAttribute(currentType, typeof(UIOMaticAttribute));
var db = (Database)DatabaseContext.Database;
if (!string.IsNullOrEmpty(uioMaticAttri.ConnectionStringName))
db = new Database(uioMaticAttri.ConnectionStringName);
var tableName = ((TableNameAttribute)Attribute.GetCustomAttribute(currentType, typeof(TableNameAttribute))).Value;
var primaryKeyColum = string.Empty;
var primKeyAttri = currentType.GetCustomAttributes().Where(x => x.GetType() == typeof(PrimaryKeyAttribute));
if (primKeyAttri.Any())
primaryKeyColum = ((PrimaryKeyAttribute)primKeyAttri.First()).Value;
foreach (var prop in currentType.GetProperties())
{
foreach (var attri in prop.GetCustomAttributes(true))
{
if (attri.GetType() == typeof(PrimaryKeyColumnAttribute))
primaryKeyColum = ((PrimaryKeyColumnAttribute)attri).Name ?? prop.Name;
}
}
EventHandler<ObjectEventArgs> tmp = UpdatingObject;
if (tmp != null)
tmp(this, new ObjectEventArgs(ob));
db.Save(tableName, primaryKeyColum, ob);
EventHandler<ObjectEventArgs> temp = UpdatedObject;
if (temp != null)
temp(this, new ObjectEventArgs(ob));
return ob;
}
示例2: Validate
public IEnumerable<Exception> Validate(ExpandoObject objectToValidate)
{
var typeOfObject = objectToValidate.FirstOrDefault(x => x.Key == "typeOfObject").Value.ToString();
objectToValidate = (ExpandoObject)objectToValidate.FirstOrDefault(x => x.Key == "objectToValidate").Value;
var ar = typeOfObject.Split(',');
var currentType = Type.GetType(ar[0] + ", " + ar[1]);
object ob = Activator.CreateInstance(currentType, null);
var values = (IDictionary<string, object>)objectToValidate;
foreach (var prop in currentType.GetProperties())
{
var propKey = prop.Name;
if (values.ContainsKey(propKey))
{
Helper.SetValue(ob, prop.Name, values[propKey]);
}
}
return ((IUIOMaticModel) ob).Validate();
}
示例3: PostUpdate
public object PostUpdate(ExpandoObject objectToUpdate)
{
var typeOfObject = objectToUpdate.FirstOrDefault(x => x.Key == "typeOfObject").Value.ToString();
objectToUpdate = (ExpandoObject)objectToUpdate.FirstOrDefault(x => x.Key == "objectToUpdate").Value;
var ar = typeOfObject.Split(',');
var currentType = Type.GetType(ar[0] + ", " + ar[1]);
object ob = Activator.CreateInstance(currentType,null);
foreach (var prop in objectToUpdate)
{
var propKey = prop.Key;
//foreach (var proper in currentType.GetProperties())
//{
// foreach (var attri in proper.GetCustomAttributes())
// {
// if (attri.GetType() == typeof(ColumnAttribute) && ((ColumnAttribute)attri).Name == propKey)
// propKey = proper.Name;
// }
//}
PropertyInfo propI = currentType.GetProperty(propKey);
if (propI != null)
{
Helper.SetValue(ob, propI.Name, prop.Value);
}
}
var uioMaticAttri = (UIOMaticAttribute)Attribute.GetCustomAttribute(currentType, typeof(UIOMaticAttribute));
var db = (Database)DatabaseContext.Database;
if (!string.IsNullOrEmpty(uioMaticAttri.ConnectionStringName))
db = new Database(uioMaticAttri.ConnectionStringName);
db.Update(ob);
return ob;
}