Exemplo n.º 1
0
        public static void ApplyCorrectYeKe(this object entity)
        {
            if (entity == null)
            {
                return;
            }

            var properties = entity
                             .GetType()
                             .GetProperties()
                             .Where(p => string.Equals(p.PropertyType.Name, AppConsts.StringDataTypeName, StringComparison.CurrentCultureIgnoreCase))
                             .ToList();

            var propertyReflector = new PropertyReflector();

            foreach (var memberInfo in properties)
            {
                var name = memberInfo.Name;
                var targetObjectValue = propertyReflector.GetValue(entity, name);

                if (targetObjectValue != null)
                {
                    propertyReflector
                    .SetValue(entity, name, targetObjectValue.ToString().ApplyUnifiedYeKe());
                }
            }
        }
Exemplo n.º 2
0
        public CompanyInformationModel GetCompanyInformationModel()
        {
            //if (getcompanyInformationModel==null)
            //{


            var companyInformationModel = new CompanyInformationModel();
            var pr   = new PropertyReflector();
            var dict = companyInformationModel.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)
                       .ToDictionary(prop => prop.Name, prop => prop?.GetValue(companyInformationModel, null)?.ToString() ?? "");
            var keyValues = _keyValues.Where(x => dict.Keys.Contains(x.Key)).ToList();

            if (keyValues.Any())
            {
                //keyValues.ForEach(x => x.Value = dict[x.Key]);
                foreach (var keyValue in keyValues)
                {
                    pr.SetValue(companyInformationModel, keyValue.Key, keyValue.Value);
                }
            }
            getcompanyInformationModel = companyInformationModel;
            return(companyInformationModel);
            //}
            //else
            //{
            //    return getcompanyInformationModel;
            //}
        }
Exemplo n.º 3
0
        public static void ApplyCorrectYeKeToProperties(this object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            var propertyInfos = obj.GetType().GetProperties(
                BindingFlags.Public | BindingFlags.Instance
                ).Where(p => p.CanRead && p.CanWrite && p.PropertyType == typeof(string));

            var propertyReflector = new PropertyReflector();

            foreach (var propertyInfo in propertyInfos)
            {
                var propName = propertyInfo.Name;
                var value    = propertyReflector.GetValue(obj, propName);
                if (value != null)
                {
                    var strValue = value.ToString();
                    var newVal   = strValue.ApplyCorrectYeKe();
                    if (newVal == strValue)
                    {
                        continue;
                    }

                    propertyReflector.SetValue(obj, propName, newVal);
                }
            }
        }
Exemplo n.º 4
0
 public void Test_StronglyTyped_InvalidCast_Set( )
 {
     using (var property = new PropertyReflector <string>(Agent007, "id"))
     {
         Assert.Catch <ArgumentException>(() => property.SetValue(Agent007, "Abacus"), "Expected InvalidCastException to be raised when attempting to" +
                                          " retrieve field of type Guid as a string.");
     }
 }
Exemplo n.º 5
0
 public void Test_WeaklyTyped_TargetException_Set( )
 {
     using (var property = new PropertyReflector(typeof(Person), "id"))
     {
         // This is a non-static field thus field access requires a target object instance.
         Assert.Catch <TargetException>(() => property.SetValue(null, Guid.NewGuid( )), "Expected TargetException to be raised when attempting to " +
                                        "assign the value of non-static property.");
     }
 }
Exemplo n.º 6
0
        public void Resolve(IServiceProvider provider, object implementation)
        {
            Check.NotNull(provider, nameof(provider));
            Check.NotNull(implementation, nameof(implementation));
            var value = _propertyFactory(provider);

            if (value != null)
            {
                _reflector.SetValue(implementation, value);
            }
        }
Exemplo n.º 7
0
        public void Test_WeaklyTyped_Set( )
        {
            using (var property = new PropertyReflector(Agent007, "id"))
            {
                Assert.NotNull(property.PropertyInfo, $"Property named \"id\" not found in type {Agent007.GetType( )}");
                Assert.NotNull(property.GetValue(Agent007), $"Value returned was null.");

                var id = property.GetValue(Agent007);
                property.SetValue(Agent007, Guid.NewGuid( ));

                Assert.AreNotEqual(id, property.GetValue(Agent007), "Expected change in Agent007's id did not occur.");
            }
        }
Exemplo n.º 8
0
        public static void ApplyCorrectYeKe(this DbContext dbContext)
        {
            if (dbContext == null)
            {
                return;
            }

            //پیدا کردن موجودیت‌های تغییر کرده
            var changedEntities = dbContext.ChangeTracker
                                  .Entries()
                                  .Where(x => x.State == EntityState.Added || x.State == EntityState.Modified);

            foreach (var item in changedEntities)
            {
                var entity = item.Entity;
                if (item.Entity == null)
                {
                    continue;
                }

                //یافتن خواص قابل تنظیم و رشته‌ای این موجودیت‌ها
                var propertyInfos = entity.GetType().GetProperties(
                    BindingFlags.Public | BindingFlags.Instance
                    ).Where(p => p.CanRead && p.CanWrite && p.PropertyType == typeof(string));

                var propertyReflector = new PropertyReflector();

                //اعمال یکپارچگی نهایی
                foreach (var propertyInfo in propertyInfos)
                {
                    var propName = propertyInfo.Name;
                    var value    = propertyReflector.GetValue(entity, propName);
                    if (value != null)
                    {
                        var strValue = value.ToString();
                        var newVal   = strValue.ApplyCorrectYeKe();
                        if (newVal == strValue)
                        {
                            continue;
                        }
                        propertyReflector.SetValue(entity, propName, newVal);
                    }
                }
            }
        }
        public SystemSettingSaleModel GetSystemSettingSaleModel()
        {
            var systemSettingSaleModel = new SystemSettingSaleModel();
            var pr   = new PropertyReflector();
            var dict = systemSettingSaleModel.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)
                       .ToDictionary(prop => prop.Name, prop => prop?.GetValue(systemSettingSaleModel, null)?.ToString() ?? "");
            var keyValues = _keyValues.Where(x => dict.Keys.Contains(x.Key)).ToList();

            if (keyValues.Any())
            {
                //keyValues.ForEach(x => x.Value = dict[x.Key]);
                foreach (var keyValue in keyValues)
                {
                    pr.SetValue(systemSettingSaleModel, keyValue.Key, keyValue.Value);
                }
            }
            return(systemSettingSaleModel);
        }
Exemplo n.º 10
0
        private void applyCorrectYeKe()
        {
            //پیدا کردن موجودیت‌های تغییر کرده
            var changedEntities = this.ChangeTracker
                                  .Entries()
                                  .Where(x => x.State == EntityState.Added || x.State == EntityState.Modified);

            foreach (var item in changedEntities)
            {
                if (item.Entity == null)
                {
                    continue;
                }

                //یافتن خواص قابل تنظیم و رشته‌ای این موجودیت‌ها
                var propertyInfos = item.Entity.GetType().GetProperties(
                    BindingFlags.Public | BindingFlags.Instance
                    ).Where(p => p.CanRead && p.CanWrite && p.PropertyType == typeof(string));

                var pr = new PropertyReflector();

                //اعمال یکپارچگی نهایی
                foreach (var propertyInfo in propertyInfos)
                {
                    var propName = propertyInfo.Name;
                    var val      = pr.GetValue(item.Entity, propName);
                    if (val != null)
                    {
                        var newVal = val.ToString().Replace("ي", "ی").Replace("ؤ", "و").Replace("ة", "ه");
                        //var newVal = val.ToString().Replace("ی", "ی").Replace("ک", "ک");
                        if (newVal == val.ToString())
                        {
                            continue;
                        }
                        pr.SetValue(item.Entity, propName, newVal);
                    }
                }
            }
        }
 public void AspectCoreSetter()
 {
     _reflector.SetValue(_indexerEntity, "hello word!");
 }
Exemplo n.º 12
0
 public void Resolve(IServiceProvider provider, object implementation)
 {
     _reflector.SetValue(implementation, _propertyFactory(provider));
 }