當前位置: 首頁>>代碼示例>>C#>>正文


C# ExpandoObject.FirstOrDefault方法代碼示例

本文整理匯總了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;
        }
開發者ID:paulsoerensen,項目名稱:UIOMatic,代碼行數:63,代碼來源:PetaPocoObjectController.cs

示例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();
        }
開發者ID:paulsoerensen,項目名稱:UIOMatic,代碼行數:26,代碼來源:PetaPocoObjectController.cs

示例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;
        }
開發者ID:tomfulton,項目名稱:UIOMatic,代碼行數:39,代碼來源:PetaPocoObjectController.cs


注:本文中的System.Dynamic.ExpandoObject.FirstOrDefault方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。