Example #1
0
            public override List <Attribute> GetAttributes(System.Reflection.MemberInfo memberInfo, bool inherit = true)
            {
                var attributes = base.GetAttributes(memberInfo, inherit);

                for (int i = attributes.Count - 1; i >= 0; i--)
                {
                    var attribute = attributes[i] as DataMemberAttribute;
                    if (attribute != null)
                    {
                        attributes[i] = new YamlMemberAttribute(attribute.Name)
                        {
                            Order = attribute.Order
                        };
                    }
                    else if (attributes[i] is DataMemberIgnoreAttribute)
                    {
                        attributes[i] = new YamlIgnoreAttribute();
                    }
                    else if (attributes[i] is DataContractAttribute)
                    {
                        var alias = ((DataContractAttribute)attributes[i]).Alias;
                        if (!string.IsNullOrWhiteSpace(alias))
                        {
                            attributes[i] = new YamlTagAttribute(alias);
                        }
                    }
                    else if (attributes[i] is DataStyleAttribute)
                    {
                        switch (((DataStyleAttribute)attributes[i]).Style)
                        {
                        case DataStyle.Any:
                            attributes[i] = new YamlStyleAttribute(YamlStyle.Any);
                            break;

                        case DataStyle.Compact:
                            attributes[i] = new YamlStyleAttribute(YamlStyle.Flow);
                            break;

                        case DataStyle.Normal:
                            attributes[i] = new YamlStyleAttribute(YamlStyle.Block);
                            break;
                        }
                    }
                }
                return(attributes);
            }
Example #2
0
            private Attribute RemapToYaml(Attribute originalAttribute)
            {
                Attribute attribute       = null;
                var       memberAttribute = originalAttribute as DataMemberAttribute;

                if (memberAttribute != null)
                {
                    SerializeMemberMode mode;
                    switch (memberAttribute.Mode)
                    {
                    case DataMemberMode.Default:
                    case DataMemberMode.ReadOnly:     // ReadOnly is better as default or content?
                        mode = SerializeMemberMode.Default;
                        break;

                    case DataMemberMode.Assign:
                        mode = SerializeMemberMode.Assign;
                        break;

                    case DataMemberMode.Content:
                        mode = SerializeMemberMode.Content;
                        break;

                    case DataMemberMode.Binary:
                        mode = SerializeMemberMode.Binary;
                        break;

                    case DataMemberMode.Never:
                        mode = SerializeMemberMode.Never;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                    attribute = new YamlMemberAttribute(memberAttribute.Name, mode)
                    {
                        Order = memberAttribute.Order, Mask = memberAttribute.Mask
                    };
                    //Trace.WriteLine(string.Format("Attribute remapped {0}", memberAttribute.Name));
                }
                else if (originalAttribute is DataMemberIgnoreAttribute)
                {
                    attribute = new YamlIgnoreAttribute();
                }
                else if (originalAttribute is DataContractAttribute)
                {
                    var alias = ((DataContractAttribute)originalAttribute).Alias;
                    if (!string.IsNullOrWhiteSpace(alias))
                    {
                        attribute = new YamlTagAttribute(alias);
                    }
                }
                else if (originalAttribute is DataStyleAttribute)
                {
                    switch (((DataStyleAttribute)originalAttribute).Style)
                    {
                    case DataStyle.Any:
                        attribute = new YamlStyleAttribute(YamlStyle.Any);
                        break;

                    case DataStyle.Compact:
                        attribute = new YamlStyleAttribute(YamlStyle.Flow);
                        break;

                    case DataStyle.Normal:
                        attribute = new YamlStyleAttribute(YamlStyle.Block);
                        break;
                    }
                }
                else if (originalAttribute is DataAliasAttribute)
                {
                    attribute = new YamlRemapAttribute(((DataAliasAttribute)originalAttribute).Name);
                }

                return(attribute ?? originalAttribute);
            }
Example #3
0
            public override List <Attribute> GetAttributes(System.Reflection.MemberInfo memberInfo, bool inherit = true)
            {
                var attributes = base.GetAttributes(memberInfo, inherit);

                for (int i = attributes.Count - 1; i >= 0; i--)
                {
                    var attribute = attributes[i] as DataMemberAttribute;
                    if (attribute != null)
                    {
                        SerializeMemberMode mode;
                        switch (attribute.Mode)
                        {
                        case DataMemberMode.Default:
                        case DataMemberMode.ReadOnly:     // ReadOnly is better as default or content?
                            mode = SerializeMemberMode.Default;
                            break;

                        case DataMemberMode.Assign:
                            mode = SerializeMemberMode.Assign;
                            break;

                        case DataMemberMode.Content:
                            mode = SerializeMemberMode.Content;
                            break;

                        case DataMemberMode.Binary:
                            mode = SerializeMemberMode.Binary;
                            break;

                        case DataMemberMode.Never:
                            mode = SerializeMemberMode.Never;
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }
                        attributes[i] = new YamlMemberAttribute(attribute.Name, mode)
                        {
                            Order = attribute.Order
                        };
                    }
                    else if (attributes[i] is DataMemberIgnoreAttribute)
                    {
                        attributes[i] = new YamlIgnoreAttribute();
                    }
                    else if (attributes[i] is DataContractAttribute)
                    {
                        var alias = ((DataContractAttribute)attributes[i]).Alias;
                        if (!string.IsNullOrWhiteSpace(alias))
                        {
                            attributes[i] = new YamlTagAttribute(alias);
                        }
                    }
                    else if (attributes[i] is DataStyleAttribute)
                    {
                        switch (((DataStyleAttribute)attributes[i]).Style)
                        {
                        case DataStyle.Any:
                            attributes[i] = new YamlStyleAttribute(YamlStyle.Any);
                            break;

                        case DataStyle.Compact:
                            attributes[i] = new YamlStyleAttribute(YamlStyle.Flow);
                            break;

                        case DataStyle.Normal:
                            attributes[i] = new YamlStyleAttribute(YamlStyle.Block);
                            break;
                        }
                    }
                }
                return(attributes);
            }