コード例 #1
0
        public ArchetypeField(string _name_, FieldType _type_)
        {
            if (_name_ == null)                    { Error.BadArg("Got null archetype parse_field name"); }
            if (!Token.is_bare_multi_word(_name_)) { Error.BadArg("Got invalid parse_field name '{0}'", _name_); }
            if (_type_ == null)                    { Error.BadArg("Got null FieldType"); }

            name = _name_;
            type = _type_;

            // Initialize default_value with a suitable IObjField instance
            //
            // Yes, doing an switch on types in an OO system is often a code smell.
            // Does anyone have an aesthetically better means of implementing Duck-Typing in C# prior to C# 4.0 ?
            //
            switch (_type_.semantic_type)
            {
                case SemanticTypes.INT:
                    default_value = new FieldInt();
                    break;
                case SemanticTypes.STRING:
                    default_value = new FieldString();
                    break;
                case SemanticTypes.DECIMAL:
                    default_value = new FieldDecimal();
                    break;
                case SemanticTypes.ID:
                    default_value = new FieldID();
                    break;

                case SemanticTypes.LIST_INT:
                    default_value = new FieldListInt();
                    break;
                case SemanticTypes.LIST_STRING:
                    default_value = new FieldListString();
                    break;
                case SemanticTypes.LIST_DECIMAL:
                    default_value = new FieldListDecimal();
                    break;
                case SemanticTypes.LIST_ID:
                    default_value = new FieldListID();
                    break;

                default:
                    Error.BadArg("Got unknown field type '{0}'", _type_);
                    break;
            }
            // This method sets up an IObjField with the default C# value for the storage type
            // (0, "", 0.0M, or an empty list of one of these).
            // The additional constructors below (with additional args) are called
            // when a default field value (or a non-empty default list) is specified,
            // which is possibly the more common case.
        }
コード例 #2
0
        } // this[field_name]

        public void add_field(string field_name, FieldType type)
        {
            IObjField field = null;  // or perhaps: new FieldTempNull(this, field_name);

            switch (type.semantic_type)
            {
            case SemanticTypes.INT:
                field = new FieldInt();
                break;

            case SemanticTypes.STRING:
                field = new FieldString();
                break;

            case SemanticTypes.DECIMAL:
                field = new FieldDecimal();
                break;

            case SemanticTypes.ID:
                field = new FieldID();
                break;

            case SemanticTypes.LIST_INT:
                field = new FieldListInt();
                break;

            case SemanticTypes.LIST_STRING:
                field = new FieldListString();
                break;

            case SemanticTypes.LIST_DECIMAL:
                field = new FieldListDecimal();
                break;

            case SemanticTypes.LIST_ID:
                field = new FieldListID();
                break;

            default:
                Error.BadArg("Got unknown field type '{0}'", type);
                break;
            }
            fields[field_name] = field;
        } // add_field()
コード例 #3
0
ファイル: Obj.cs プロジェクト: sglasby/HRAOS_Parser
        public void add_field(string field_name, FieldType type)
        {
            IObjField field = null;  // or perhaps: new FieldTempNull(this, field_name);
            switch (type.semantic_type)
            {
                case SemanticTypes.INT:
                    field = new FieldInt();
                    break;
                case SemanticTypes.STRING:
                    field = new FieldString();
                    break;
                case SemanticTypes.DECIMAL:
                    field = new FieldDecimal();
                    break;
                case SemanticTypes.ID:
                    field = new FieldID();
                    break;

                case SemanticTypes.LIST_INT:
                    field = new FieldListInt();
                    break;
                case SemanticTypes.LIST_STRING:
                    field = new FieldListString();
                    break;
                case SemanticTypes.LIST_DECIMAL:
                    field = new FieldListDecimal();
                    break;
                case SemanticTypes.LIST_ID:
                    field = new FieldListID();
                    break;

                default:
                    Error.BadArg("Got unknown field type '{0}'", type);
                    break;
            }
            fields[field_name] = field;
        }