コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DynamicTable"/> class.
 /// </summary>
 /// <param name="tableName">Name of the table.</param>
 /// <param name="dataStrategy">The database which owns the table.</param>
 /// <param name="schema">The schema to which the table belongs.</param>
 internal DynamicTable(string tableName, DataStrategy dataStrategy, DynamicSchema schema)
 {
     _delegates             = new Dictionary <string, Func <object[], object> >();
     _delegatesAsCollection = _delegates;
     _tableName             = tableName;
     _schema       = schema;
     _dataStrategy = dataStrategy;
 }
コード例 #2
0
ファイル: DynamicTable.cs プロジェクト: remcok/Simple.Data
 /// <summary>
 /// Initializes a new instance of the <see cref="DynamicTable"/> class.
 /// </summary>
 /// <param name="tableName">Name of the table.</param>
 /// <param name="dataStrategy">The database which owns the table.</param>
 /// <param name="schema">The schema to which the table belongs.</param>
 internal DynamicTable(string tableName, DataStrategy dataStrategy, DynamicSchema schema)
 {
     _delegates = new Dictionary<string, Func<object[], object>>();
     _delegatesAsCollection = _delegates;
     _tableName = tableName;
     _schema = schema;
     _dataStrategy = dataStrategy;
 }
コード例 #3
0
ファイル: DataStrategy.cs プロジェクト: moacap/Simple.Data
 internal DynamicSchema SetMemberAsSchema(ObjectReference reference, DynamicSchema schema)
 {
     if (reference == null)
     {
         throw new ArgumentNullException("reference");
     }
     _members.TryUpdate(reference.GetName(), schema, reference);
     return((DynamicSchema)_members[reference.GetName()]);
 }
コード例 #4
0
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            if (base.TryInvokeMember(binder, args, out result))
            {
                return(true);
            }

            if (_dataStrategy != null)
            {
                // Probably a table...
                var table = new DynamicTable(_name, _dataStrategy);
                if (table.TryInvokeMember(binder, args, out result))
                {
                    _dataStrategy.SetMemberAsTable(this, table);
                    return(true);
                }

                // Or it could be a schema reference...
                var schema = new DynamicSchema(_name, _dataStrategy);
                if (schema.TryInvokeMember(binder, args, out result))
                {
                    _dataStrategy.SetMemberAsSchema(this);
                    return(true);
                }
            }

            var dataStrategy = FindDataStrategyInHierarchy();

            if (dataStrategy != null)
            {
                var command = CommandFactory.GetCommandFor(binder.Name);
                if (command != null)
                {
                    var schema = dataStrategy.SetMemberAsSchema(_owner);
                    var table  = schema.GetTable(_name);
                    result = command.Execute(dataStrategy, table, binder, args);
                }
                else
                {
                    if (dataStrategy.IsExpressionFunction(binder.Name, args))
                    {
                        result = new SimpleExpression(this, new SimpleFunction(binder.Name, args), SimpleExpressionType.Function);
                    }
                    else
                    {
                        result = new FunctionReference(binder.Name, this, args);
                    }
                }
                return(true);
            }
            throw new InvalidOperationException();
        }
コード例 #5
0
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            if (base.TryInvokeMember(binder, args, out result))
            {
                return(true);
            }

            if (_dataStrategy != null)
            {
                var table = new DynamicTable(_name, _dataStrategy);
                try
                {
                    if (table.TryInvokeMember(binder, args, out result))
                    {
                        _dataStrategy.SetMemberAsTable(this, table);
                        return(true);
                    }
                }
                catch (InvalidOperationException ex)
                {
                    if (!ex.Message.StartsWith("Method"))
                    {
                        throw;
                    }
                }

                // Or it could be a schema reference...
                var schema = new DynamicSchema(_name, _dataStrategy);
                try
                {
                    if (schema.TryInvokeMember(binder, args, out result))
                    {
                        _dataStrategy.SetMemberAsSchema(this);
                        return(true);
                    }
                }
                catch (KeyNotFoundException)
                {
                    throw new InvalidOperationException(string.Format("Method {0} not recognised", binder.Name));
                }
            }

            var dataStrategy = FindDataStrategyInHierarchy();

            if (dataStrategy != null)
            {
                var command = CommandFactory.GetCommandFor(binder.Name);
                if (command != null)
                {
                    if (!ReferenceEquals(_owner, null))
                    {
                        var schema = dataStrategy.SetMemberAsSchema(_owner);
                        var table  = schema.GetTable(_name);
                        table.TryInvokeMember(binder, args, out result);
                    }
                    else
                    {
                        throw new InvalidOperationException(string.Format("Method {0} not recognised", binder.Name));
                    }
                    //result = command.Execute(dataStrategy, table, binder, args);
                }
                else
                {
                    if (dataStrategy.IsExpressionFunction(binder.Name, args))
                    {
                        result = new SimpleExpression(this, new SimpleFunction(binder.Name, args), SimpleExpressionType.Function);
                    }
                    else
                    {
                        result = new FunctionReference(binder.Name, this, args);
                    }
                }
                return(true);
            }
            throw new InvalidOperationException(string.Format("Method {0} not recognised", binder.Name));
        }
コード例 #6
0
ファイル: DynamicTable.cs プロジェクト: vansha/Simple.Data
 /// <summary>
 /// Initializes a new instance of the <see cref="DynamicTable"/> class.
 /// </summary>
 /// <param name="tableName">Name of the table.</param>
 /// <param name="dataStrategy">The database which owns the table.</param>
 /// <param name="schema">The schema to which the table belongs.</param>
 internal DynamicTable(string tableName, DataStrategy dataStrategy, DynamicSchema schema)
 {
     _tableName = tableName;
     _schema = schema;
     _dataStrategy = dataStrategy;
 }
コード例 #7
0
ファイル: DataStrategy.cs プロジェクト: remcok/Simple.Data
 internal DynamicSchema SetMemberAsSchema(ObjectReference reference, DynamicSchema schema)
 {
     if (reference == null) throw new ArgumentNullException("reference");
     _members.TryUpdate(reference.GetName(), schema, reference);
     return (DynamicSchema) _members[reference.GetName()];
 }
コード例 #8
0
ファイル: DynamicTable.cs プロジェクト: ToJans/Simple.Data
 /// <summary>
 /// Initializes a new instance of the <see cref="DynamicTable"/> class.
 /// </summary>
 /// <param name="tableName">Name of the table.</param>
 /// <param name="dataStrategy">The database which owns the table.</param>
 /// <param name="schema">The schema to which the table belongs.</param>
 internal DynamicTable(string tableName, DataStrategy dataStrategy, DynamicSchema schema)
 {
     _tableName    = tableName;
     _schema       = schema;
     _dataStrategy = dataStrategy;
 }