Exemplo n.º 1
0
        public void InvokeTest()
        {
            var model = new Model {
                name = "laojiu"
            };
            var setter = new PropertySetter(model.GetType().GetProperty("name"));

            setter.Invoke(model, "ee");
            Assert.True("ee" == model.name);
        }
Exemplo n.º 2
0
 internal void SetValue(TTarget target, TProperty value)
 {
     _setter.Invoke(target, value);
 }
Exemplo n.º 3
0
        protected IDbDataParameter CreateParameter(PropertyMetadata propertyMetadata, object paramValue, ref int paramIndex, out string parameterName)
        {
            parameterName = QueryLite.DataService.EntityLiteProvider.ParameterPrefix + "P" + paramIndex.ToString();
            IDbDataParameter parameter = QueryLite.DataService.DbProviderFactory.CreateParameter();

            parameter.ParameterName = parameterName;
            parameter.Size          = propertyMetadata.SqlField.Size;

            Type propertyType = propertyMetadata.PropertyInfo.PropertyType.UndelyingType();
            var  sqlParam     = parameter as SqlParameter;

            if (propertyType.FullName.StartsWith("Microsoft.SqlServer.Types.Sql"))
            {
                if (sqlParam != null)
                {
                    sqlParam.SqlDbType = SqlDbType.Udt;
                    //TODO: En .NET Core no va a funcionar porque no existe la propiedad "UdtTypeName" y dará un error en tiempo de ejecución.
                    udtTypeNameSetter?.Invoke(sqlParam, propertyType.Name.Substring(3).ToLower());
                }
                else
                {
                    parameter.DbType = DbType.String;
                    if (propertyType.Name.StartsWith("SqlHierarchyId"))
                    {
                        parameter.Size = 4000;
                    }
                    else
                    {
                        parameter.Size = 1073741823;
                    }
                }
            }
            else
            {
                if (propertyMetadata.SqlField.ProviderType != int.MaxValue)
                {
                    this.QueryLite.DataService.EntityLiteProvider.SetProviderTypeToParameter(parameter, propertyMetadata.SqlField.ProviderType);
                }
                else if (propertyMetadata.SqlField.DbType == DbType.AnsiStringFixedLength)
                {
                    parameter.DbType = DbType.AnsiString;
                }
                else if (propertyMetadata.SqlField.DbType == DbType.StringFixedLength)
                {
                    parameter.DbType = DbType.String;
                }
                else if (propertyMetadata.SqlField.DbType == DbType.Time && sqlParam != null)
                {
                    sqlParam.SqlDbType = SqlDbType.Time;
                }
                else
                {
                    parameter.DbType = propertyMetadata.SqlField.DbType;
                }
                parameter.SourceColumn = propertyMetadata.PropertyInfo.Name;
                if (propertyMetadata.SqlField.Precision != 255 && propertyMetadata.SqlField.Precision != 0)
                {
                    parameter.Precision = propertyMetadata.SqlField.Precision;
                }
                if (propertyMetadata.SqlField.Scale != 255)
                {
                    parameter.Scale = propertyMetadata.SqlField.Scale;
                }
            }

            if (paramValue != null && (parameter.DbType == DbType.String || parameter.DbType == DbType.AnsiString) && !(paramValue is string))
            {
                var convertible = paramValue as IConvertible;
                if (convertible != null)
                {
                    paramValue = convertible.ToString(CultureInfo.InvariantCulture);
                }
                else
                {
                    paramValue = paramValue.ToString();
                }
            }
            INullable sqlNullable = paramValue as INullable;

            parameter.Value = (paramValue == null || (sqlNullable != null && sqlNullable.IsNull)) ? DBNull.Value : paramValue;
            paramIndex++;
            return(parameter);
        }
 void SetPropertyValue(TValue data)
 {
     setter.Invoke(data);
 }