Esempio n. 1
0
        private static DependencyProperty RegisterServiceProperty(string name, Type type)
        {
            var defaultValue     = RuntimeUtils.CreateDefaultValue(type);
            var propertyMetadata = new PropertyMetadata(defaultValue, OnServicePropertyValueChanged);

            return(DependencyPropertyManager.RegisterAttached(name, type, typeof(DependencyPropertyManager), propertyMetadata));
        }
Esempio n. 2
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            var targetType = typeof(TTo);

            if (value == null)
            {
                return(RuntimeUtils.CreateDefaultValue(targetType));
            }

            var sourceType = value.GetType();

            return(PrimitiveConverterFactory.GetConverter(sourceType, targetType).Convert(value));
        }
Esempio n. 3
0
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            object target;
            object targetProperty;
            bool   reflected;

            GetTarget(serviceProvider, out target, out targetProperty, out reflected);

            var targetProxy = target as ISkinResourceKey;

            if (targetProxy != null)
            {
                var propertyName = (targetProperty as PropertyInfo)?.Name;

                if (propertyName == null)
                {
                    return(null);
                }

                targetProxy.SetResourceKey(propertyName, Key);
            }

            var propertyInfo = targetProperty as PropertyInfo;

            if (propertyInfo != null)
            {
                return(RuntimeUtils.CreateDefaultValue(propertyInfo.PropertyType));
            }

            var dependencyProperty = targetProperty as DependencyProperty;

            if (dependencyProperty != null)
            {
                return(RuntimeUtils.CreateDefaultValue(dependencyProperty.GetPropertyType()));
            }

            return(null);
        }
Esempio n. 4
0
        protected object DefaultPropertyValue(IServiceProvider serviceProvider)
        {
            object target;
            object targetProperty;
            bool   reflected;

            GetTarget(serviceProvider, out target, out targetProperty, out reflected);

            var propertyInfo = targetProperty as PropertyInfo;

            if (propertyInfo != null)
            {
                return(RuntimeUtils.CreateDefaultValue(propertyInfo.PropertyType));
            }

            var dependencyProperty = targetProperty as DependencyProperty;

            if (dependencyProperty != null)
            {
                return(RuntimeUtils.CreateDefaultValue(dependencyProperty.GetPropertyType()));
            }

            return(null);
        }
Esempio n. 5
0
 protected override object ConvertCore(object value, Type targetType, object parameter, CultureInfo culture)
 {
     return(targetType.IsValueType && (value == null || value.IsDependencyPropertyUnsetValue() || value.IsUnset()) ? RuntimeUtils.CreateDefaultValue(targetType) : value);
 }
Esempio n. 6
0
 public static object CreateDefaultValue(this Type type)
 {
     return(RuntimeUtils.CreateDefaultValue(type));
 }
Esempio n. 7
0
        private object GetDefaultValue(object targetProperty)
        {
            var propertyType = GetPropertyType(targetProperty);

            return(propertyType == null ? null : RuntimeUtils.CreateDefaultValue(propertyType));
        }