当前位置: 首页>>代码示例>>C#>>正文


C# IValueSerializerContext.GetValueSerializerFor方法代码示例

本文整理汇总了C#中IValueSerializerContext.GetValueSerializerFor方法的典型用法代码示例。如果您正苦于以下问题:C# IValueSerializerContext.GetValueSerializerFor方法的具体用法?C# IValueSerializerContext.GetValueSerializerFor怎么用?C# IValueSerializerContext.GetValueSerializerFor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IValueSerializerContext的用法示例。


在下文中一共展示了IValueSerializerContext.GetValueSerializerFor方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetSerializerFor

 public static ValueSerializer GetSerializerFor(Type type, IValueSerializerContext context)
 {
     ValueSerializer s = context.GetValueSerializerFor (type);
     if (s == null) {
         DefaultValueSerializerContext defaultContext = new DefaultValueSerializerContext();
         s = defaultContext.GetValueSerializerFor (type);
     }
     return s;
 }
开发者ID:shahid-pk,项目名称:MonoPresentationFoundation,代码行数:9,代码来源:ValueSerializer.cs

示例2: GetSerializerFor

		// untested
		public static ValueSerializer GetSerializerFor (PropertyDescriptor descriptor, IValueSerializerContext context)
		{
			if (descriptor == null)
				throw new ArgumentNullException ("descriptor");
			if (context != null)
				return context.GetValueSerializerFor (descriptor);

			var tc = descriptor.Converter;
			if (tc != null && tc.GetType () != typeof (TypeConverter))
				return new TypeConverterValueSerializer (tc);
			return null;
		}
开发者ID:carrie901,项目名称:mono,代码行数:13,代码来源:ValueSerializer.cs

示例3: GetSerializerFor

		// untested
		public static ValueSerializer GetSerializerFor (PropertyInfo descriptor, IValueSerializerContext context)
		{
			if (descriptor == null)
				throw new ArgumentNullException ("descriptor");
			if (context != null)
				return context.GetValueSerializerFor (descriptor);

			var typeConverterInfo = descriptor.GetCustomAttribute<TypeConverterAttribute> ();
			var typeConverterName = typeConverterInfo?.ConverterTypeName;
			if (string.IsNullOrEmpty (typeConverterName))
				return null;
			var tcType = Type.GetType(typeConverterName);
			var tc = Activator.CreateInstance (tcType) as TypeConverter;
			if (tc != null && tc.GetType () != typeof (TypeConverter))
				return new TypeConverterValueSerializer (tc);
			return null;
		}
开发者ID:wieslawsoltes,项目名称:Portable.Xaml,代码行数:18,代码来源:ValueSerializer.cs

示例4: CanConvertToString

        public override bool CanConvertToString(object value, IValueSerializerContext context)
        {
            if (context == null || context.GetValueSerializerFor(typeof(Type)) == null)
                return false;

            // Can only convert routed commands
            RoutedCommand command = value as RoutedCommand;

            if (command == null || command.OwnerType == null)
            {
                return false;
            }
            
            if (CommandConverter.IsKnownType(command.OwnerType))
            {
                return true;
            }
            else
            {
                string localName = command.Name + "Command";
                Type ownerType = command.OwnerType;
                string typeName = ownerType.Name;

                // Get them from Properties
                PropertyInfo propertyInfo = ownerType.GetProperty(localName, BindingFlags.Public | BindingFlags.Static);
                if (propertyInfo != null)
                    return true;

                // Get them from Fields (ScrollViewer.PageDownCommand is a static readonly field
                FieldInfo fieldInfo = ownerType.GetField(localName, BindingFlags.Static | BindingFlags.Public);
                if (fieldInfo != null)
                    return true;
            }

            return false; 
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:36,代码来源:CommandValueSerializer.cs

示例5: ConvertToString

        public override string ConvertToString(object value, IValueSerializerContext context)
        {
            if (value != null)
            {
                RoutedCommand command = value as RoutedCommand;
                if (null != command && null != command.OwnerType)
                {
                    // Known Commands, so write shorter version
                    if (CommandConverter.IsKnownType(command.OwnerType))
                    {
                        return command.Name;
                    }
                    else
                    {
                        ValueSerializer typeSerializer = null;

                        if (context == null)
                        {
                            throw new InvalidOperationException(SR.Get(SRID.ValueSerializerContextUnavailable, this.GetType().Name ));
                        }

                        // Get the ValueSerializer for the System.Type type
                        typeSerializer = context.GetValueSerializerFor(typeof(Type));
                        if (typeSerializer == null)
                        {
                            throw new InvalidOperationException(SR.Get(SRID.TypeValueSerializerUnavailable, this.GetType().Name ));
                        }

                        return typeSerializer.ConvertToString(command.OwnerType, context) + "." + command.Name + "Command";
                    }
                }
            }
            else
                return string.Empty;
            
            throw GetConvertToException(value, typeof(string));
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:37,代码来源:CommandValueSerializer.cs

示例6: ConvertFromString

        public override object ConvertFromString(string value, IValueSerializerContext context)
        {
            if (value != null)
            {
                if (value != String.Empty)
                {
                    Type declaringType = null;
                    String commandName;

                    // Check for "ns:Class.Command" syntax.
                    
                    int dotIndex = value.IndexOf('.');
                    if (dotIndex >= 0)
                    {
                        // We have "ns:Class.Command" syntax.

                        // Find the type name in the form of "ns:Class".
                        string typeName = value.Substring(0, dotIndex);

                        if (context == null)
                        {
                            throw new InvalidOperationException(SR.Get(SRID.ValueSerializerContextUnavailable, this.GetType().Name ));
                        }

                        // Get the ValueSerializer for the System.Type type
                        ValueSerializer typeSerializer = context.GetValueSerializerFor(typeof(Type));
                        if (typeSerializer == null)
                        {
                            throw new InvalidOperationException(SR.Get(SRID.TypeValueSerializerUnavailable, this.GetType().Name ));
                        }


                        // Use the TypeValueSerializer to parse the "ns:Class" into a System.Type.
                        declaringType = typeSerializer.ConvertFromString(typeName, context) as Type;

                        // Strip out the "Command" part of "ns:Class.Command".
                        commandName = value.Substring(dotIndex + 1).Trim();
                    }
                    else
                    {
                        // Assume the known commands
                        commandName = value.Trim();
                    }

                    // Find the command given the declaring type & name (this is shared with CommandConverter)
                    ICommand command = CommandConverter.ConvertFromHelper( declaringType, commandName );

                    if (command != null)
                    {
                        return command;
                    }
                }
                else
                {
                    return null; // String.Empty <==> null , (for roundtrip cases where Command property values are null)
                }
            }

            return base.ConvertFromString(value, context);
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:60,代码来源:CommandValueSerializer.cs

示例7: GetSerializerFor

 public static ValueSerializer GetSerializerFor(Type type, IValueSerializerContext context)
 {
     if (context != null)
     {
         ValueSerializer valueSerializerFor = context.GetValueSerializerFor(type);
         if (valueSerializerFor != null)
         {
             return valueSerializerFor;
         }
     }
     return GetSerializerFor(type);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:12,代码来源:ValueSerializer.cs

示例8: CheckForMarkupExtension

        // 
        //  Check for values that can be converted into markup extensions, either because
        //  they are a well known type ((null, arrays, enums, and types), or because they 
        //  can be type converted into an ME. 
        //
 
        internal static object CheckForMarkupExtension(
                                    Type propertyType,
                                    object value,
                                    IValueSerializerContext context, 
                                    bool convertEnums)
        { 
            // null => NullExtension 

            if (value == null) 
            {
                return new NullExtension();
            }
 
            // See if the type has a type converter that can create a MarkupExtension
            // (Have to do this after the null check so that GetConverter doesn't get 
            // an invalid argument.) 

            TypeConverter converter = TypeDescriptor.GetConverter(value); 
            if (converter.CanConvertTo(context, typeof(MarkupExtension)))
            {
                // The type provides a converter that creates a MarkupExtension.
                return converter.ConvertTo(context, TypeConverterHelper.InvariantEnglishUS, value, typeof(MarkupExtension)); 
            }
 
            // System.Type => TypeExtension 

            Type type = value as Type; 
            if (type != null)
            {
                // If the property is declared to be a type already, we don't need to convert it
                // into {x:Type} syntax. 

                if( propertyType == typeof(Type) ) 
                { 
                    return value;
                } 

                return new TypeExtension(type);
            }
 
            // Enums => StaticExtension
 
            if (convertEnums) 
            {
                Enum enumValue = value as Enum; 
                if (enumValue != null)
                {
                    ValueSerializer typeSerializer = context.GetValueSerializerFor(typeof(Type));
                    Debug.Assert(typeSerializer != null, "typeSerializer for Enum was null"); 
                    string typeName = typeSerializer.ConvertToString(enumValue.GetType(), context);
                    return new StaticExtension(typeName + "." + enumValue.ToString()); 
                } 
            }
 
            // Arrays => ArrayExtension

            Array array = value as Array;
            if (array != null) 
            {
                return new ArrayExtension(array); 
            } 

            // Otherwise, value is unchanged. 

            return value;
        }
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:72,代码来源:ElementMarkupObject.cs


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