• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# IValueContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中IValueContext的典型用法代码示例。如果您正苦于以下问题:C# IValueContext类的具体用法?C# IValueContext怎么用?C# IValueContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



IValueContext类属于命名空间,在下文中一共展示了IValueContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: SetValue

        public static void SetValue(
            object instance, 
            MutableMember member, 
            object value,
            IValueContext context)
        {
            var perspexProperty = FindPerspexProperty(instance, member);

            if (value is IBinding)
            {
                SetBinding(instance, member, perspexProperty, (IBinding)value);
            }
            else if (perspexProperty != null)
            {
                ((PerspexObject)instance).SetValue(perspexProperty, value);
            }
            else if (instance is Setter && member.Name == "Value")
            {
                // TODO: Make this more generic somehow.
                var setter = (Setter)instance;
                var targetType = setter.Property.PropertyType;
                var xamlType = member.TypeRepository.GetByType(targetType);
                var convertedValue = default(object);

                if (CommonValueConversion.TryConvert(value, xamlType, context, out convertedValue))
                {
                    SetClrProperty(instance, member, convertedValue);
                }
            }
            else
            {
                SetClrProperty(instance, member, value);
            }
        }
开发者ID:KvanTTT,项目名称:Perspex,代码行数:34,代码来源:PropertyAccessor.cs


示例2: ConvertFrom

 public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
 {
     return new MemberSelector
     {
         MemberName = (string)value,
     };
 }
开发者ID:KvanTTT,项目名称:Perspex,代码行数:7,代码来源:MemberSelectorTypeConverter.cs


示例3: GetValues

 public IEnumerable<string> GetValues(IValueContext currentContext) {
     
         return GetValue(currentContext).Split(new[] {
             ','
         }, StringSplitOptions.RemoveEmptyEntries).Select( each => each.Trim());
     
 }
开发者ID:roomaroo,项目名称:coapp.powershell,代码行数:7,代码来源:Scalar.cs


示例4: ObjectAssembler

 public ObjectAssembler(StackingLinkedList<Level> state,
     IRuntimeTypeSource typeSource,
     IInstanceLifeCycleListener listener,
     IValueContext context)
 {
     StateCommuter = new StateCommuter(state, typeSource, listener, context);
     LifecycleListener = listener;
 }
开发者ID:wieslawsoltes,项目名称:OmniXAML,代码行数:8,代码来源:ObjectAssembler.cs


示例5: ConvertTo

 public object ConvertTo(
     IValueContext context,
     CultureInfo culture,
     object value,
     Type destinationType)
 {
     throw new NotImplementedException();
 }
开发者ID:AvaloniaUI,项目名称:OmniXAML,代码行数:8,代码来源:TypeTypeConverter.cs


示例6: ConvertFrom

        public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
        {
            if (value is string)
            {
                return value;
            }

            return null;
        }
开发者ID:AvaloniaUI,项目名称:OmniXAML,代码行数:9,代码来源:StringTypeConverter.cs


示例7: CanConvertTo

        public bool CanConvertTo(IValueContext context, Type destinationType)
        {
            if (destinationType == typeof(string) || destinationType == typeof(int))
            {
                return true;
            }

            return false;
        }
开发者ID:AvaloniaUI,项目名称:OmniXAML,代码行数:9,代码来源:StringTypeConverter.cs


示例8: SetValue

 public virtual void SetValue(object instance, object value, IValueContext valueContext)
 {
     if (ValueSetter.IsStatic)
     {
         ValueSetter.Invoke(null, new[] { instance, value });
     }
     else
     {
         member.Setter.Invoke(instance, new[] { value });
     }
 }
开发者ID:AvaloniaUI,项目名称:OmniXAML,代码行数:11,代码来源:MemberValuePlugin.cs


示例9: ConvertFrom

 public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
 {
     string strValue = (string)value;
     string[] pointStrs = strValue.Split(new[] { ' ', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
     var result = new List<Point>(pointStrs.Length);
     foreach (var pointStr in pointStrs)
     {
         result.Add(Point.Parse(pointStr, culture));
     }
     return result;
 }
开发者ID:KvanTTT,项目名称:Perspex,代码行数:11,代码来源:PointsListTypeConverter.cs


示例10: StateCommuter

        public StateCommuter(StackingLinkedList<Level> stack,
            IRuntimeTypeSource typeSource,
            IInstanceLifeCycleListener lifecycleListener,
            IValueContext valueContext)
        {
            Guard.ThrowIfNull(stack, nameof(stack));
            Guard.ThrowIfNull(typeSource, nameof(typeSource));

            Stack = stack;
            this.lifecycleListener = lifecycleListener;
            this.valueContext = valueContext;
        }
开发者ID:AvaloniaUI,项目名称:OmniXAML,代码行数:12,代码来源:StateCommuter.cs


示例11: ConvertFrom

        public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
        {
            var valueStr = (string)value;
            if (!valueStr.Contains(":"))
            {
                // shorthand seconds format (ie. "0.25")
                var secs = double.Parse(valueStr, CultureInfo.InvariantCulture);
                return TimeSpan.FromSeconds(secs);
            }

            return TimeSpan.Parse(valueStr);
        }
开发者ID:CarlSosaDev,项目名称:Avalonia,代码行数:12,代码来源:TimeSpanTypeConverter.cs


示例12: ConvertFrom

 public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
 {
     FontWeight result;
     
     if (Enum.TryParse(value as string, out result))
     {
         return result;
     }
     else
     {
         throw new ArgumentException("unable to convert parameter to FontWeight");
     }
 }
开发者ID:jkoritzinsky,项目名称:Avalonia,代码行数:13,代码来源:FontWeightConverter.cs


示例13: TryConvert

        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;
        }
开发者ID:wieslawsoltes,项目名称:OmniXAML,代码行数:13,代码来源:CommonValueConversion.cs


示例14: ConvertFrom

        public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
        {
            var uri = new Uri((string)value, UriKind.RelativeOrAbsolute);
            var scheme = uri.IsAbsoluteUri ? uri.Scheme : "file";

            switch (scheme)
            {
                case "file":
                    return new Bitmap((string)value);
                default:
                    var assets = PerspexLocator.Current.GetService<IAssetLoader>();
                    return new Bitmap(assets.Open(uri));
            }
        }
开发者ID:KvanTTT,项目名称:Perspex,代码行数:14,代码来源:BitmapTypeConverter.cs


示例15: SetBinding

 private static void SetBinding(
     object instance,
     MutableMember member, 
     AvaloniaProperty property, 
     IValueContext context,
     IBinding binding)
 {
     if (!(AssignBinding(instance, member, binding) || 
           ApplyBinding(instance, property, context, binding)))
     {
         throw new InvalidOperationException(
             $"Cannot assign to '{member.Name}' on '{instance.GetType()}");
     }
 }
开发者ID:CarlSosaDev,项目名称:Avalonia,代码行数:14,代码来源:PropertyAccessor.cs


示例16: ConvertFrom

 public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
 {
     var path = value as string;
     if (path != null)
     {
         return CreateIconFromPath(context, path); 
     }
     var bitmap = value as IBitmap;
     if (bitmap != null)
     {
         return new WindowIcon(bitmap);
     }
     throw new NotSupportedException();
 }
开发者ID:jkoritzinsky,项目名称:Avalonia,代码行数:14,代码来源:IconTypeConverter.cs


示例17: CreateIconFromPath

        private WindowIcon CreateIconFromPath(IValueContext context, string path)
        {
            var uri = new Uri(path, UriKind.RelativeOrAbsolute);
            var baseUri = GetBaseUri(context);
            var scheme = uri.IsAbsoluteUri ? uri.Scheme : "file";

            switch (scheme)
            {
                case "file":
                    return new WindowIcon(path);
                default:
                    var assets = AvaloniaLocator.Current.GetService<IAssetLoader>();
                    return new WindowIcon(assets.Open(uri, baseUri));
            }
        }
开发者ID:jkoritzinsky,项目名称:Avalonia,代码行数:15,代码来源:IconTypeConverter.cs


示例18: ConvertFrom

        public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
        {
            if (culture == null)
            {
                throw new ArgumentNullException("culture");
            }

            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            DateTimeFormatInfo dateTimeFormatInfo = (DateTimeFormatInfo)culture.GetFormat(typeof(DateTimeFormatInfo));
            DateTime d = DateTime.ParseExact(value.ToString(), dateTimeFormatInfo.ShortDatePattern, culture);
            return d;
        }
开发者ID:CarlSosaDev,项目名称:Avalonia,代码行数:16,代码来源:DateTimeTypeConverter.cs


示例19: ConvertFrom

        public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
        {
            var s = (string)value;

            string typeName;
            string propertyName;
            Type type;

            ParseProperty(s, out typeName, out propertyName);

            if (typeName == null)
            {
                var styleType = context.TypeRepository.GetByType(typeof(Style));
                var style = (Style)context.TopDownValueContext.GetLastInstance(styleType);
                type = style.Selector.TargetType;

                if (type == null)
                {
                    throw new ParseException(
                        "Could not determine the target type. Please fully qualify the property name.");
                }
            }
            else
            {
                type = context.TypeRepository.GetByQualifiedName(typeName)?.UnderlyingType;

                if (type == null)
                {
                    throw new ParseException($"Could not find type '{typeName}'.");
                }
            }

            // First look for non-attached property on the type and then look for an attached property.
            var property = PerspexPropertyRegistry.Instance.FindRegistered(type, s) ??
                           PerspexPropertyRegistry.Instance.GetAttached(type)
                           .FirstOrDefault(x => x.Name == propertyName);

            if (property == null)
            {
                throw new ParseException(
                    $"Could not find PerspexProperty '{type.Name}.{propertyName}'.");
            }

            return property;
        }
开发者ID:KvanTTT,项目名称:Perspex,代码行数:45,代码来源:PerspexPropertyTypeConverter.cs


示例20: ConvertTo

        public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType == null)
            {
                throw new ArgumentNullException("destinationType");
            }

            if (culture == null)
            {
                throw new ArgumentNullException("culture");
            }

            DateTime? d = value as DateTime?;

            if (!d.HasValue || destinationType != typeof(string))
            {
                throw new NotSupportedException();
            }
            DateTimeFormatInfo dateTimeFormatInfo = (DateTimeFormatInfo)culture.GetFormat(typeof(DateTimeFormatInfo));
            return d.Value.ToString(dateTimeFormatInfo.ShortDatePattern, culture);
        }
开发者ID:CarlSosaDev,项目名称:Avalonia,代码行数:21,代码来源:DateTimeTypeConverter.cs



注:本文中的IValueContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IValueConverter类代码示例发布时间:2022-05-24
下一篇:
C# IValue类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap