Beispiel #1
0
        /// <summary>
        /// Gets the value.
        /// </summary>
        /// <param name="record">The record.</param>
        /// <param name="property">Name of the prop.</param>
        /// <returns></returns>
        ///
        public virtual object GetValue(object record, string property)
        {
            if (!(View is TreeGridSelfRelationalView))
            {
                return(TreeGridHelper.GetValue(record, property));
            }
            var itemproperties = View.GetItemProperties();

            if (itemproperties == null || record == null)
            {
                return(null);
            }

            if (itemaccessor.ContainsKey(property))
            {
                return(itemaccessor[property].GetValue(record));
            }

            var tempitempproperties = itemproperties;
            var propertyNameList    = property.Split('.');

#if WPF
            return(PropertyDescriptorExtensions.GetComplexPropertyValue(propertyNameList, tempitempproperties, record));
#else
            return(PropertyInfoExtensions.GetComplexPropertyValue(propertyNameList, tempitempproperties, record));
#endif
        }
Beispiel #2
0
        /// <summary>
        /// Sets the value.
        /// </summary>
        /// <param name="record">The record.</param>
        /// <param name="propName">Name of the prop.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public virtual bool SetValue(object record, string propName, object value)
        {
            if (!(View is TreeGridSelfRelationalView))
            {
                return(TreeGridHelper.SetValue(record, propName, value));
            }

            var itemproperties = View.GetItemProperties();

            if (itemproperties == null)
            {
                return(false);
            }

            if (itemaccessor.ContainsKey(propName))
            {
                itemaccessor[propName].SetValue(record, value);
                return(true);
            }

            var tempitempproperties = itemproperties;
            var propertyNameList    = propName.Split('.');

#if WPF
            return(PropertyDescriptorExtensions.SetComplexPropertyValue(propertyNameList, tempitempproperties, record, value));
#else
            return(PropertyInfoExtensions.SetComplexPropertyValue(propertyNameList, tempitempproperties, record, value));
#endif
        }
Beispiel #3
0
        public static IEnumerable <PropertyInfo> GetProperties(Type type)
        {
#if DOTNET35
            var hidingProperties    = type.GetProperties().Where(x => PropertyInfoExtensions.IsHidingMember(x));
            var nonHidingProperties = type.GetProperties().Where(x => hidingProperties.All(y => y.Name != x.Name));
            return(nonHidingProperties.Concat(hidingProperties));
#else
            var hidingProperties    = type.GetRuntimeProperties().Where(x => x.IsHidingMember());
            var nonHidingProperties = type.GetRuntimeProperties().Where(x => hidingProperties.All(y => y.Name != x.Name));
            return(nonHidingProperties.Concat(hidingProperties));
#endif
        }
Beispiel #4
0
        public void Save(PropertyInfo propertyInfo, PlayerDataModel playerDataModel)
        {
            if (IsSavingBlocked)
            {
                return;
            }

            Debug.Log($"Saving of key({propertyInfo.Name}) with value({propertyInfo.GetValue(playerDataModel)}) started");

            PropertyInfoExtensions.SaveToPlayerPrefs(propertyInfo, playerDataModel);

            Debug.Log($"Saving of key({propertyInfo.Name}) with value({propertyInfo.GetValue(playerDataModel)}) finished");
        }
 private static DbSetProperty[] FindSets(Type contextType)
 {
     return(contextType.GetRuntimeProperties()
            .Where(
                p => !PropertyInfoExtensions.IsStatic(p) &&
                !p.GetIndexParameters().Any() &&
                p.DeclaringType != typeof(DbContext) &&
                p.PropertyType.GetTypeInfo().IsGenericType &&
                p.PropertyType.GetGenericTypeDefinition() == typeof(DbSet <>))
            .OrderBy(p => p.Name)
            .Select(p => new DbSetProperty(
                        p.DeclaringType, p.Name,
                        p.PropertyType.GetTypeInfo().GenericTypeArguments.Single(), p.SetMethod != null))
            .ToArray());
 }
        public static string GetPropertyName(PropertyInfo propertyInfo)
        {
            ArgumentUtility.CheckNotNull("propertyInfo", propertyInfo);

            Type originalDeclaringType = PropertyInfoExtensions.GetOriginalDeclaringType(propertyInfo);

            if (originalDeclaringType.IsGenericType)
            {
                return(GetPropertyName(originalDeclaringType.GetGenericTypeDefinition(), propertyInfo.Name));
            }
            else
            {
                return(GetPropertyName(originalDeclaringType, propertyInfo.Name));
            }
        }
        /// <summary>
        /// Validates the value of current cell.
        /// </summary>
        /// <param name="currentCell">
        /// The current cell that is to validated.
        /// </param>
        /// <param name="propertyName">
        /// The propertyName.
        /// </param>
        /// <param name="dataModel">
        /// The dataModel.
        /// </param>
        /// <returns>
        /// <b>true</b> if the validation is successful; otherwise, <b>false</b>.
        /// </returns>
        internal static bool Validate(TreeGridCell currentCell, string propertyName, object dataModel)
        {
            bool hasError       = false;
            var  itemproperties = currentCell.ColumnBase.TreeGridColumn.TreeGrid.View.GetItemProperties();

            // WPF-25016 Using PropertyDescriptorExtensions for WPF and PropertyInfoExtensions for WinRT, the codes are cleaned up
            if (propertyName.Contains('.'))
            {
                var propNames = propertyName.Split('.');
                propertyName = propNames[propNames.Length - 1];
                Array.Resize(ref propNames, propNames.Length - 1);
                var pName = string.Join(".", propNames);
#if WPF
                dataModel = PropertyDescriptorExtensions.GetValue(itemproperties, dataModel, pName);
#else
                dataModel = PropertyInfoExtensions.GetValue(itemproperties, dataModel, pName);
#endif
            }

            if (dataModel == null)
            {
                return(hasError);
            }

#if WPF
            var dataValidation = dataModel as IDataErrorInfo;
            if (dataValidation != null)
            {
                string errormessage = dataValidation[propertyName];
                hasError = !String.IsNullOrEmpty(errormessage);
                if (hasError)
                {
                    currentCell.bindingErrorMessage = errormessage;
                }

                currentCell.ApplyValidationVisualState();
                return(!hasError);
            }
#endif
#if !SyncfusionFramework4_0 || UWP
            hasError = !ValidateINotifyDataErrorInfo(currentCell, propertyName, dataModel);
#endif
            return(!hasError);
        }
        public void Load()
        {
            Debug.Log($"Loading of PlayerData from PlayerPrefs started");

            // While you are reading data from the source - do not save data to the source
            _playerDataSavingService.IsSavingBlocked = true;
            var playerDataModel = new PlayerDataModel(_playerDataSavingService);
            var propertyInfos   = playerDataModel.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);

            foreach (var propertyInfo in propertyInfos)
            {
                PropertyInfoExtensions.LoadFromPlayerPrefs(propertyInfo, playerDataModel);
            }
            _playerDataSavingService.IsSavingBlocked = false;

            Debug.Log($"Loading of PlayerData from PlayerPrefs finished");

            _playerDataService.PlayerDataModel.Value = playerDataModel;
        }
        public void CreateStaticSetter1Works()
        {
            var property = typeof(Corge).GetProperty(nameof(Corge.Bar));

            Action <int> setter;
            var          queued = (Callback : (WaitCallback)null, PropertySetter : (StaticPropertySetter <int>)null);

            void queueUserWorkItem(WaitCallback callback, object state) => queued = (callback, (StaticPropertySetter <int>)state);

            PropertyInfoExtensions.SetQueueUserWorkItemAction(queueUserWorkItem);

            try
            {
                setter = property.CreateStaticSetter <int>();
            }
            finally
            {
                PropertyInfoExtensions.SetQueueUserWorkItemAction(null);
            }

            // Verify that a work item was queued
            queued.PropertySetter.Should().NotBeNull();
            queued.Callback.Should().NotBeNull();

            // Verify that the return delegate is correct
            setter.Target.Should().BeSameAs(queued.PropertySetter);
            setter.Method.Name.Should().Be(nameof(StaticPropertySetter <int> .SetValue));
            setter.Method.DeclaringType.Should().Be(typeof(StaticPropertySetter <int>));

            // Verify that the queued Callback calls the SetOptimizedFunc
            // method of the queued PropertySetter.
            var beforeAction = queued.PropertySetter.Action;

            queued.Callback.Invoke(queued.PropertySetter);
            var afterAction = queued.PropertySetter.Action;

            beforeAction.Should().NotBeSameAs(afterAction);
        }
    public static T ParseTo <T>(this JObject jsonObject) where T : new()
    {
        var configModel   = new T();
        var propertyInfos = configModel.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);

        foreach (var propertyInfo in propertyInfos)
        {
            var           jsonToken = jsonObject[propertyInfo.Name];
            System.Object value     = null;
            if (jsonToken is JArray)
            {
                var jArray = jsonToken.Value <JArray>();
                value = jArray.ToObject <List <string> >();
            }
            else
            {
                value = jsonToken.ToObject <string>();
            }

            PropertyInfoExtensions.SetValue(propertyInfo, configModel, value);
        }

        return(configModel);
    }
        public void CreateGetter2Works()
        {
            Func <Foo, int> getter;
            var             queued = (Callback : (WaitCallback)null, PropertyGetter : (PropertyGetter <Foo, int>)null);

            void queueUserWorkItem(WaitCallback callback, object state) => queued = (callback, (PropertyGetter <Foo, int>)state);

            PropertyInfoExtensions.SetQueueUserWorkItemAction(queueUserWorkItem);

            try
            {
                getter = _property.CreateGetter <Foo, int>();
            }
            finally
            {
                PropertyInfoExtensions.SetQueueUserWorkItemAction(null);
            }

            // Verify that a work item was queued
            queued.PropertyGetter.Should().NotBeNull();
            queued.Callback.Should().NotBeNull();

            // Verify that the return delegate is correct
            getter.Target.Should().BeSameAs(queued.PropertyGetter);
            getter.Method.Name.Should().Be(nameof(PropertyGetter <Foo, int> .GetValue));
            getter.Method.DeclaringType.Should().Be(typeof(PropertyGetter <Foo, int>));

            // Verify that the queued Callback calls the SetOptimizedFunc
            // method of the queued PropertyGetter.
            var beforeFunc = queued.PropertyGetter.Func;

            queued.Callback.Invoke(queued.PropertyGetter);
            var afterFunc = queued.PropertyGetter.Func;

            beforeFunc.Should().NotBeSameAs(afterFunc);
        }
 private static string GetTextFromType(PropertyInfo pi, object value)
 {
     return(PropertyInfoExtensions.GetTextFromType(pi, value));
 }
 private void InputFieldOnEndEdit(string value)
 {
     PropertyInfoExtensions.SetValue(propertyInfoComponent.PropertyInfo, propertyInfoComponent.Object, value);
 }
 public void GetValueNullTest()
 {
     Assert.IsNotNull(PropertyInfoExtensions.GetValue(null, 0));
     Assert.Fail();
 }
        public void CreateGetter2ThrowsIfPropertyParameterIsNull()
        {
            var exception = Assert.Throws <ArgumentNullException>(() => PropertyInfoExtensions.CreateGetter <Foo, int>(null));

            exception.ParamName.Should().Be("property");
        }