Esempio n. 1
0
        /// <summary>
        /// Gets or sets the field value with the specified name.
        /// </summary>
        /// <value>
        /// The field value.
        /// </value>
        /// <param name="name">The name.</param>
        /// <returns>Field value.</returns>
        /// <exception cref="ArgumentException">Thrown when field value is invalid.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when field value is out of range.</exception>
        internal object this[string name]
        {
            get
            {
                if (string.IsNullOrEmpty(name))
                {
                    throw new ArgumentException("Value cannot be null or empty");
                }

                RecordFieldSchema field = GetField(name);
                if (field == null)
                {
                    throw new ArgumentOutOfRangeException(string.Format(CultureInfo.InvariantCulture, "Field with name '{0}' cannot be found.", name));
                }

                return(values[field.Position]);
            }

            set
            {
                RecordFieldSchema field = GetField(name);
                if (field == null)
                {
                    throw new ArgumentOutOfRangeException(string.Format(CultureInfo.InvariantCulture, "Field with name '{0}' cannot be found.", name));
                }

                values[field.Position] = value;
            }
        }
Esempio n. 2
0
        private void AddRecordFields(
            IEnumerable <MemberSerializationInfo> members,
            Dictionary <string, NamedSchema> schemas,
            uint currentDepth,
            RecordSchema record)
        {
            int index = 0;

            foreach (MemberSerializationInfo info in members)
            {
                var property = info.MemberInfo as PropertyInfo;
                var field    = info.MemberInfo as FieldInfo;

                Type memberType;
                if (property != null)
                {
                    memberType = property.PropertyType;
                }
                else if (field != null)
                {
                    memberType = field.FieldType;
                }
                else
                {
                    throw new SerializationException(
                              string.Format(
                                  CultureInfo.InvariantCulture,
                                  "Type member '{0}' is not supported.",
                                  info.MemberInfo.GetType().Name));
                }

                TypeSchema fieldSchema = this.TryBuildUnionSchema(memberType, info.MemberInfo, schemas, currentDepth)
                                         ?? this.TryBuildFixedSchema(memberType, info.MemberInfo, record)
                                         ?? this.CreateSchema(info.Nullable, memberType, schemas, currentDepth + 1, info.DefaultValue?.GetType(), info.MemberInfo);



                var aliases = info
                              .Aliases
                              .ToList();
                var recordField = new RecordFieldSchema(
                    new NamedEntityAttributes(new SchemaName(info.Name), aliases, info.Doc),
                    fieldSchema,
                    SortOrder.Ascending,
                    info.HasDefaultValue,
                    info.DefaultValue,
                    info.MemberInfo,
                    index++);
                record.AddField(recordField);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Provides the implementation for operations that set member values. Classes derived from the <see cref="T:System.Dynamic.DynamicObject" /> class can override this method to specify dynamic behavior for operations such as setting a value for a property.
        /// </summary>
        /// <param name="binder">Provides information about the object that called the dynamic operation. The binder.Name property provides the name of the member to which the value is being assigned. For example, for the statement sampleObject.SampleProperty = "Test", where sampleObject is an instance of the class derived from the <see cref="T:System.Dynamic.DynamicObject" /> class, binder.Name returns "SampleProperty". The binder.IgnoreCase property specifies whether the member name is case-sensitive.</param>
        /// <param name="value">The value to set to the member. For example, for sampleObject.SampleProperty = "Test", where sampleObject is an instance of the class derived from the <see cref="T:System.Dynamic.DynamicObject" /> class, the <paramref name="value" /> is "Test".</param>
        /// <returns>
        /// True if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language determines the behavior. (In most cases, a language-specific run-time exception is thrown.).
        /// </returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="binder"/> is null.</exception>
        public override bool TrySetMember(SetMemberBinder binder, object value)
        {
            if (binder == null)
            {
                throw new ArgumentNullException("binder");
            }

            RecordFieldSchema field = GetField(binder.Name);

            if (field == null)
            {
                return(false);
            }
            values[field.Position] = value;
            return(true);
        }
Esempio n. 4
0
        /// <summary>
        /// Provides the implementation for operations that get member values. Classes derived from the <see cref="T:System.Dynamic.DynamicObject" /> class can override this method to specify dynamic behavior for operations such as getting a value for a property.
        /// </summary>
        /// <param name="binder">Provides information about the object that called the dynamic operation. The binder.Name property provides the name of the member on which the dynamic operation is performed. For example, for the Console.WriteLine(sampleObject.SampleProperty) statement, where sampleObject is an instance of the class derived from the <see cref="T:System.Dynamic.DynamicObject" /> class, binder.Name returns "SampleProperty". The binder.IgnoreCase property specifies whether the member name is case-sensitive.</param>
        /// <param name="result">The result of the get operation. For example, if the method is called for a property, you can assign the property value to <paramref name="result" />.</param>
        /// <returns>
        /// True if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language determines the behavior. (In most cases, a run-time exception is thrown.).
        /// </returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="binder"/> is null.</exception>
        public override bool TryGetMember(
            GetMemberBinder binder,
            out object result)
        {
            if (binder == null)
            {
                throw new ArgumentNullException("binder");
            }

            result = null;

            RecordFieldSchema field = GetField(binder.Name);

            if (field == null)
            {
                return(false);
            }
            result = values[field.Position];
            return(true);
        }