NPoco.PocoDataFactory.ForObjectStatic C# (CSharp) Method

ForObjectStatic() public static method

public static ForObjectStatic ( object o, string primaryKeyName, bool autoIncrement, PocoData>.Func fallback ) : NPoco.PocoData
o object
primaryKeyName string
autoIncrement bool
fallback PocoData>.Func
return NPoco.PocoData
        public static PocoData ForObjectStatic(object o, string primaryKeyName, bool autoIncrement, Func<Type, PocoData> fallback)
        {
            var t = o.GetType();
            #if !NET35
            if (t == typeof (System.Dynamic.ExpandoObject) || t == typeof (PocoExpando))
            {
                var pd = new PocoData
                {
                    TableInfo = new TableInfo
                    {
                        PrimaryKey = primaryKeyName,
                        AutoIncrement = autoIncrement
                    },
                    Columns = new Dictionary<string, PocoColumn>(StringComparer.OrdinalIgnoreCase)
                };
                foreach (var col in ((IDictionary<string, object>)o))
                {
                    pd.Columns.Add(col.Key, new ExpandoColumn
                    {
                        ColumnName = col.Key,
                        MemberInfoData = new MemberInfoData(col.Key, col.Value.GetTheType() ?? typeof(object), typeof(object)),
                    });
                }
                if (!pd.Columns.ContainsKey(primaryKeyName))
                {
                    pd.Columns.Add(primaryKeyName, new ExpandoColumn { ColumnName = primaryKeyName, ColumnType = typeof(object) });
                }
                return pd;
            }
            else
            #endif
                return fallback(t);
        }

Usage Example

コード例 #1
0
 public PocoData ForObject(object o, string primaryKeyName, bool autoIncrement)
 {
     return(PocoDataFactory.ForObjectStatic(o, primaryKeyName, autoIncrement, ForType));
 }