コード例 #1
0
ファイル: ParameterResultInfo.cs プロジェクト: drogozh/ceql
        public object CreateInstance(IVirtualDataReader reader, IConnectorFormatter formatter)
        {
            //set contructor arguments
            for (var i = 0; i < ConstArgumentsBuffer.Length; i++)
            {
                var argumentAlias = ArgumentMapping[i];
                var resultObject  = formatter.FormatFrom(reader[argumentAlias.Alias]);

                if (resultObject is DBNull)
                {
                    ConstArgumentsBuffer[i] = null;
                }
                else
                {
                    ConstArgumentsBuffer[i] = resultObject;
                }
            }

            //create instance
            var instance = Constructor.Invoke(ConstArgumentsBuffer);

            //set properties on an instance
            for (var i = 0; i < MemberMapping.Count; i++)
            {
                var tuple    = MemberMapping[i];
                var property = tuple.Item3 as PropertyInfo;
                var v        = reader[tuple.Item1];

                // null values are skipped
                // property vlues will be set to their defaults
                if (v == DBNull.Value)
                {
                    continue;
                }

                //set field
                var field = tuple.Item3 as FieldInfo;
                if (field != null)
                {
                    SetValue(instance, field, formatter.FormatFrom(field.FieldType, v));
                }

                //set property only if set method is available
                if (property != null && property.SetMethod != null)
                {
                    SetValue(instance, property, formatter.FormatFrom(property.PropertyType, v));
                }
            }

            return(instance);
        }
コード例 #2
0
ファイル: SelectEnumerator.cs プロジェクト: jonahgroup/Ceql
        public object CreateInstance(IVirtualDataReader reader)
        {
            //set contructor arguments
            for (var i = 0; i < ConstArgumentsBuffer.Length; i++)
            {
                var idx = ArgumentMapping[i];
                ConstArgumentsBuffer[i] = reader[idx];
            }

            //create instance
            var instance = Constructor.Invoke(ConstArgumentsBuffer);

            //set properties on an instance
            for (var i = 0; i < MemberMapping.Count; i++)
            {
                var tuple = MemberMapping[i];
                var v     = reader[tuple.Item1];

                // null values are skipped
                // property vlues will be set to their defaults
                if (v == DBNull.Value)
                {
                    continue;
                }

                //set field
                var field = tuple.Item3 as FieldInfo;
                if (field != null)
                {
                    SetValue(instance, field, v);
                }

                //set property only if set method is available
                var property = tuple.Item3 as PropertyInfo;
                if (property != null && property.SetMethod != null)
                {
                    SetValue(instance, property, v);
                }
            }

            return(instance);
        }