コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="YamlSequenceNode"/> class.
        /// </summary>
        /// <param name="events">The events.</param>
        /// <param name="state">The state.</param>
        internal YamlSequenceNode(EventReader events, DocumentLoadingState state)
        {
            SequenceStart sequence = events.Expect <SequenceStart>();

            Load(sequence, state);
            Style = sequence.Style;

            bool hasUnresolvedAliases = false;

            while (!events.Accept <SequenceEnd>())
            {
                YamlNode child = ParseNode(events, state);
                children.Add(child);
                hasUnresolvedAliases |= child is YamlAliasNode;
            }

            if (hasUnresolvedAliases)
            {
                state.AddNodeWithUnresolvedAliases(this);
            }
#if DEBUG
            else
            {
                foreach (var child in children)
                {
                    if (child is YamlAliasNode)
                    {
                        throw new InvalidOperationException("Error in alias resolution.");
                    }
                }
            }
#endif

            events.Expect <SequenceEnd>();
        }
コード例 #2
0
        /// <summary>
        /// Create an latitude by data value and it's style
        /// </summary>
        /// <param name="value">data value</param>
        /// <param name="style">data style</param>
        /// <returns>a new latitude</returns>
        public new static Latitude FromValue(double value, DataStyle style)
        {
            Angle ang = new Angle();

            ang.SetValue(value, style);
            return(new Latitude(ang.Degrees));
        }
コード例 #3
0
 public MakeJson(string str)
 {
     if (str == null)
     {
         style = DataStyle.NULL;
     }
     else
     {
         style    = DataStyle.STR;
         this.str = str;
     }
 }
コード例 #4
0
ファイル: ObjectDescriptor.cs プロジェクト: cg123/xenko
        /// <summary>
        /// Initializes a new instance of the <see cref="ObjectDescriptor" /> class.
        /// </summary>
        /// <param name="factory">The factory.</param>
        /// <param name="type">The type.</param>
        /// <exception cref="System.ArgumentNullException">type</exception>
        /// <exception cref="System.InvalidOperationException">Failed to get ObjectDescriptor for type [{0}]. The member [{1}] cannot be registered as a member with the same name is already registered [{2}].ToFormat(type.FullName, member, existingMember)</exception>
        public ObjectDescriptor(ITypeDescriptorFactory factory, Type type)
        {
            if (factory == null) throw new ArgumentNullException("factory");
            if (type == null) throw new ArgumentNullException("type");

            this.factory = factory;
            Category = DescriptorCategory.Object;
            this.AttributeRegistry = factory.AttributeRegistry;
            this.type = type;
            var styleAttribute = AttributeRegistry.GetAttribute<DataStyleAttribute>(type);
            this.style = styleAttribute != null ? styleAttribute.Style : DataStyle.Any;
            this.IsCompilerGenerated = AttributeRegistry.GetAttribute<CompilerGeneratedAttribute>(type) != null;
        }
コード例 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="YamlMappingNode"/> class.
        /// </summary>
        /// <param name="events">The events.</param>
        /// <param name="state">The state.</param>
        internal YamlMappingNode(EventReader events, DocumentLoadingState state)
        {
            MappingStart mapping = events.Expect <MappingStart>();

            Load(mapping, state);
            Style = mapping.Style;

            bool hasUnresolvedAliases = false;

            while (!events.Accept <MappingEnd>())
            {
                YamlNode key   = ParseNode(events, state);
                YamlNode value = ParseNode(events, state);

                try
                {
                    children.Add(key, value);
                }
                catch (ArgumentException err)
                {
                    throw new YamlException(key.Start, key.End, "Duplicate key", err);
                }

                hasUnresolvedAliases |= key is YamlAliasNode || value is YamlAliasNode;
            }

            if (hasUnresolvedAliases)
            {
                state.AddNodeWithUnresolvedAliases(this);
            }
#if DEBUG
            else
            {
                foreach (var child in children)
                {
                    if (child.Key is YamlAliasNode)
                    {
                        throw new InvalidOperationException("Error in alias resolution.");
                    }
                    if (child.Value is YamlAliasNode)
                    {
                        throw new InvalidOperationException("Error in alias resolution.");
                    }
                }
            }
#endif

            events.Expect <MappingEnd>();
        }
コード例 #6
0
 public void add(string key, string val, DataStyle style)
 {
     if (style == DataStyle.INT)
     {
         add(key, (object)(int.Parse(val)), style);
     }
     else if (style == DataStyle.LONG)
     {
         add(key, (object)(long.Parse(val)), style);
     }
     else if (style == DataStyle.DOUBLE)
     {
         add(key, (object)(double.Parse(val)), style);
     }
     else
     {
         add(key, (object)val, style);
     }
 }
コード例 #7
0
ファイル: ObjectDescriptor.cs プロジェクト: rohitshe/Code
        /// <summary>
        /// Initializes a new instance of the <see cref="ObjectDescriptor" /> class.
        /// </summary>
        /// <param name="factory">The factory.</param>
        /// <param name="type">The type.</param>
        /// <exception cref="System.ArgumentNullException">type</exception>
        /// <exception cref="System.InvalidOperationException">Failed to get ObjectDescriptor for type [{0}]. The member [{1}] cannot be registered as a member with the same name is already registered [{2}].ToFormat(type.FullName, member, existingMember)</exception>
        public ObjectDescriptor(ITypeDescriptorFactory factory, Type type)
        {
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            this.factory           = factory;
            Category               = DescriptorCategory.Object;
            this.AttributeRegistry = factory.AttributeRegistry;
            this.type              = type;
            var styleAttribute = AttributeRegistry.GetAttribute <DataStyleAttribute>(type);

            this.style = styleAttribute != null ? styleAttribute.Style : DataStyle.Any;
            this.IsCompilerGenerated = AttributeRegistry.GetAttribute <CompilerGeneratedAttribute>(type) != null;
        }
コード例 #8
0
ファイル: DataStyleAttribute.cs プロジェクト: cg123/xenko
 /// <summary>
 /// Initializes a new instance of the <see cref="DataStyleAttribute"/> class.
 /// </summary>
 /// <param name="style">The style.</param>
 public DataStyleAttribute(DataStyle style)
 {
     this.style = style;
 }
コード例 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DataStyleAttribute"/> class.
 /// </summary>
 /// <param name="style">The style.</param>
 public DataStyleAttribute(DataStyle style)
 {
     this.style = style;
 }
コード例 #10
0
 public MakeJson(int num)
 {
     style = DataStyle.INT;
     num1  = num;
 }
コード例 #11
0
 public MakeJson(long num)
 {
     style = DataStyle.LONG;
     num3  = num;
 }
コード例 #12
0
ファイル: MappingStart.cs プロジェクト: Aggror/Stride
 /// <summary>
 /// Initializes a new instance of the <see cref="MappingStart"/> class.
 /// </summary>
 /// <param name="anchor">The anchor.</param>
 /// <param name="tag">The tag.</param>
 /// <param name="isImplicit">Indicates whether the event is implicit.</param>
 /// <param name="style">The style of the mapping.</param>
 public MappingStart(string anchor, string tag, bool isImplicit, DataStyle style)
     : this(anchor, tag, isImplicit, style, Mark.Empty, Mark.Empty)
 {
 }
コード例 #13
0
ファイル: MappingStart.cs プロジェクト: Aggror/Stride
 /// <summary>
 /// Initializes a new instance of the <see cref="MappingStart"/> class.
 /// </summary>
 /// <param name="anchor">The anchor.</param>
 /// <param name="tag">The tag.</param>
 /// <param name="isImplicit">Indicates whether the event is implicit.</param>
 /// <param name="style">The style of the mapping.</param>
 /// <param name="start">The start position of the event.</param>
 /// <param name="end">The end position of the event.</param>
 public MappingStart(string anchor, string tag, bool isImplicit, DataStyle style, Mark start, Mark end)
     : base(anchor, tag, start, end)
 {
     this.isImplicit = isImplicit;
     this.style      = style;
 }
コード例 #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SequenceStart"/> class.
 /// </summary>
 public SequenceStart(string anchor, string tag, bool isImplicit, DataStyle style)
     : this(anchor, tag, isImplicit, style, Mark.Empty, Mark.Empty)
 {
 }
コード例 #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SequenceStart"/> class.
 /// </summary>
 /// <param name="anchor">The anchor.</param>
 /// <param name="tag">The tag.</param>
 /// <param name="isImplicit">if set to <c>true</c> [is implicit].</param>
 /// <param name="style">The style.</param>
 /// <param name="start">The start position of the event.</param>
 /// <param name="end">The end position of the event.</param>
 public SequenceStart(string anchor, string tag, bool isImplicit, DataStyle style, Mark start, Mark end)
     : base(anchor, tag, start, end)
 {
     this.isImplicit = isImplicit;
     this.style = style;
 }
コード例 #16
0
 /// <summary>
 /// Create a latitude object with value
 /// </summary>
 /// <param name="value">latitude value</param>
 /// <param name="style">data style</param>
 public Latitude(double value, DataStyle style)
 {
     SetValue(value, style);
 }
コード例 #17
0
 public MakeJson(bool val)
 {
     style  = DataStyle.BOOL;
     bValue = val;
 }
コード例 #18
0
 /// <summary>
 /// Create an angle object with value
 /// </summary>
 /// <param name="value">angle value</param>
 /// <param name="style">data style</param>
 public Angle(double value, DataStyle style)
 {
     SetValue(value, style);
 }
コード例 #19
0
 public MakeJson(double num)
 {
     style = DataStyle.DOUBLE;
     num2  = num;
 }
コード例 #20
0
        public void add(string key, object val, DataStyle style)
        {
            try
            {
                switch (style)
                {
                case DataStyle.BOOL:
                    dic.Add(key, new MakeJson((bool)val));
                    break;

                case DataStyle.STR:
                case DataStyle.DATE:
                {
                    string val2 = val.ToString();
                    if (val2.Contains("\""))
                    {
                        for (int i = val2.Length - 1; i >= 0; i--)
                        {
                            if ((val2[i] == '\"' && i == 0) || (val2[i] == '\"' && i > 0 && val2[i - 1] != '\\'))
                            {
                                error = "添加了不符合要求的值:" + val2;
                            }
                        }
                    }
                    MakeJson j = new MakeJson(val2.ToString());
                    dic.Add(key, j);
                    break;
                }

                case DataStyle.INT:
                    dic.Add(key, new MakeJson((int)val));
                    break;

                case DataStyle.DOUBLE:
                    dic.Add(key, new MakeJson((double)val));
                    break;

                case DataStyle.ARRAY:
                {
                    MakeJson j = new MakeJson();
                    j.array = (MakeJson[])val;
                    j.style = style;
                    dic.Add(key, j);
                    break;
                }

                case DataStyle.DIC:
                    dic.Add(key, (MakeJson)val);
                    break;

                case DataStyle.NULL:
                    dic.Add(key, new MakeJson(null));
                    break;

                case DataStyle.LONG:
                    dic.Add(key, new MakeJson((long)val));
                    break;

                default:
                    break;
                }
            }
            catch (Exception e)
            {
                if (key != null)
                {
                    Log.AddLog("Json", "Key:" + key);
                }
                if (val != null)
                {
                    Log.AddLog("Json", "Val:" + val.ToString());
                }
                Log.AddLog("Json", "josn添加节点异常");
                error = "josn添加节点异常:" + e.ToString();
            }
        }
コード例 #21
0
 public MakeJson()
 {
     style = DataStyle.DIC;
     dic   = new Dictionary <string, MakeJson>();
 }