public PerspexXamlMember(string name,
     XamlType owner,
     IXamlTypeRepository xamlTypeRepository,
     ITypeFeatureProvider featureProvider)
     : base(name, owner, xamlTypeRepository, featureProvider)
 {
 }
Exemple #2
0
        public XamlMember(string name, XamlType owner, IXamlTypeRepository mother, bool isAttachable)
            : this(name)
        {
            IsAttachable = isAttachable;
            DeclaringType = owner;

            Type = LookupType(name, owner, mother, isAttachable);
        }
        protected MutableXamlMember(string name, XamlType owner, IXamlTypeRepository xamlTypeRepository, ITypeFactory typeFactory)
            : base(name)
        {
            TypeRepository = xamlTypeRepository;
            TypeFactory = typeFactory;

            DeclaringType = owner;
            XamlType = LookupType();
        }
Exemple #4
0
 public PerspexXamlMember(string name,
     XamlType owner,
     IXamlTypeRepository xamlTypeRepository,
     ITypeFeatureProvider featureProvider,
     IPerspexPropertyBinder propertyBinder)
     : base(name, owner, xamlTypeRepository, featureProvider)
 {
     this.propertyBinder = propertyBinder;
 }
 private static MethodInfo GetSetMethodForAttachable(XamlType owner, string name)
 {
     var runtimeMethods = owner.UnderlyingType.GetRuntimeMethods();
     return runtimeMethods.First(info =>
     {
         var nameOfSetMethod = "Set" + name;
         return info.Name == nameOfSetMethod && info.GetParameters().Length == 2;
     });
 }
 public PerspexAttachableXamlMember(string name,
     XamlType owner,
     MethodInfo getter,
     MethodInfo setter,
     IXamlTypeRepository xamlTypeRepository,
     ITypeFeatureProvider featureProvider)
     : base(name, getter, setter, xamlTypeRepository, featureProvider)
 {
 }
        public static bool TryConvert(object value, XamlType targetType, IValueContext valueContext, out object result)
        {
            result = null;
            foreach (var step in ValueConverters)
            {
                if (step.TryConvert(value, targetType, valueContext, out result))
                {
                    return true;
                }
            }

            return false;
        }
 private IValueContext CreateContext(Style style = null)
 {
     var context = new Mock<IValueContext>();
     var topDownValueContext = new Mock<ITopDownValueContext>();
     var typeRepository = new Mock<ITypeRepository>();
     var featureProvider = new Mock<ITypeFeatureProvider>();
     var class1XamlType = new XamlType(typeof(Class1), typeRepository.Object, null, featureProvider.Object);
     var attachedOwnerXamlType = new XamlType(typeof(AttachedOwner), typeRepository.Object, null, featureProvider.Object);
     context.Setup(x => x.TopDownValueContext).Returns(topDownValueContext.Object);
     context.Setup(x => x.TypeRepository).Returns(typeRepository.Object);
     topDownValueContext.Setup(x => x.GetLastInstance(It.IsAny<XamlType>())).Returns(style);
     typeRepository.Setup(x => x.GetByQualifiedName("Class1")).Returns(class1XamlType);
     typeRepository.Setup(x => x.GetByQualifiedName("AttachedOwner")).Returns(attachedOwnerXamlType);
     return context.Object;
 }
            public bool TryConvert(object value, XamlType targetType, IValueContext valueContext, out object result)
            {
                result = null;

                var typeConverter = targetType.TypeConverter;
                if (typeConverter != null)
                {
                    if (typeConverter.CanConvertFrom(valueContext, value.GetType()))
                    {
                        {
                            result = typeConverter.ConvertFrom(valueContext, CultureInfo.InvariantCulture, value);
                            return true;
                        }
                    }
                }

                return false;
            }
Exemple #10
0
 public Member(string name, XamlType declaringType, ITypeRepository typeRepository, ITypeFeatureProvider featureProvider)
     : base(name, declaringType, typeRepository, featureProvider)
 {
     XamlType = LookupType();
 }
            public bool TryConvert(object value, XamlType targetType, IValueContext valueContext, out object result)
            {
                var type = value.GetType();

                if (type == typeof(string) && targetType.UnderlyingType == typeof(string))
                {
                    result = value;
                    return true;
                }

                if (type == typeof(string) && targetType.UnderlyingType == typeof(object))
                {
                    result = value.ToString();
                    return true;
                }

                result = null;
                return false;
            }
            public bool TryConvert(object value, XamlType targetType, IValueContext valueContext, out object result)
            {
                result = null;

                if (value == null)
                {
                    return true;
                }

                var isAssignable = targetType.UnderlyingType.GetTypeInfo().IsAssignableFrom(value.GetType().GetTypeInfo());

                if (isAssignable)
                {
                    result = value;
                    return true;
                }
                else
                {
                    return false;
                }
            }
Exemple #13
0
 public XamlDirective(string name, XamlType xamlType)
     : base(name)
 {
     XamlType = xamlType;
 }
Exemple #14
0
 public static XamlMember CreateAttached(string name, XamlType parent, IXamlTypeRepository mother)
 {
     return new XamlMember(name, parent, mother, true);
 }
Exemple #15
0
 public static XamlMember Create(string name, XamlType parent, IXamlTypeRepository mother)
 {
     return new XamlMember(name, parent, mother, false);
 }
Exemple #16
0
        private XamlType LookupType(string name, XamlType owner, IXamlTypeRepository mother, bool isAttachable)
        {
            if (!isAttachable)
            {
                var property = owner.UnderlyingType.GetRuntimeProperty(name);
                return XamlType.Builder.Create(property.PropertyType, mother);
            }

            var getMethod = GetGetMethodForAttachable(owner, name);
            return XamlType.Builder.Create(getMethod.ReturnType, mother);
        }
Exemple #17
0
 private static MethodInfo GetGetMethodForAttachable(XamlType owner, string name)
 {
     return owner.UnderlyingType.GetTypeInfo().GetDeclaredMethod("Get" + name);
 }
Exemple #18
0
 protected bool Equals(XamlType other)
 {
     return UnderlyingType == other.UnderlyingType;
 }
Exemple #19
0
 public bool CanAssignTo(XamlType type)
 {
     var otherUnderlyingType = type.UnderlyingType.GetTypeInfo();
     return otherUnderlyingType.IsAssignableFrom(UnderlyingType.GetTypeInfo());
 }
Exemple #20
0
 public XamlMember(string name, XamlType declaringType, IXamlTypeRepository xamlTypeRepository, ITypeFeatureProvider featureProvider)
     : base(name, declaringType, xamlTypeRepository, featureProvider)
 {
     XamlType = LookupType();
 }
Exemple #21
0
        public virtual XamlType GetXamlType(Type type)
        {
            Guard.ThrowIfNull(type, nameof(type));

            return(XamlType.Create(type, this, TypeFactory, featureProvider));
        }
Exemple #22
0
 protected bool Equals(XamlType other)
 {
     return(UnderlyingType == other.UnderlyingType);
 }
 public AttachableXamlMember(string name, XamlType owner, IXamlTypeRepository xamlTypeRepository, ITypeFactory typeFactory)
     : base(name, owner, xamlTypeRepository, typeFactory)
 {
 }
            public bool TryConvert(object value, XamlType xamlType, IValueContext valueContext, out object result)
            {
                var targetType = xamlType.UnderlyingType;

                result = null;
                if (targetType.IsNullable())
                {
                    var typeInfo = Nullable.GetUnderlyingType(targetType);
                    if (typeInfo != null && typeInfo.GetTypeInfo().IsEnum)
                    {
                        if (EnumExtensions.TryParse(typeInfo, value.ToString(), out result))
                        {
                            return true;
                        }
                    }
                }

                if (targetType.GetTypeInfo().IsEnum)
                {
                    if (EnumExtensions.TryParse(targetType, value.ToString(), out result))
                    {
                        return true;
                    }
                }

                return false;
            }
Exemple #25
0
        public bool CanAssignTo(XamlType type)
        {
            var otherUnderlyingType = type.UnderlyingType.GetTypeInfo();

            return(otherUnderlyingType.IsAssignableFrom(UnderlyingType.GetTypeInfo()));
        }