示例#1
0
        public static BsonDocument NewDocumentWithId(bool newId, object id, object input)
        {
            if (newId && id != null)
            {
                throw new PSInvalidOperationException("Parameters Id and NewId cannot be used together.");
            }

            if (newId)
            {
                return(new BsonDocument(BsonId.Element(new BsonObjectId(ObjectId.GenerateNewId()))));
            }

            if (id == null)
            {
                return(null);
            }

            id = Actor.BaseObject(id);
            if (!(id is ScriptBlock sb))
            {
                return(new BsonDocument(BsonId.Element(BsonValue.Create(id))));
            }

            var arr = Actor.InvokeScript(sb, input);

            if (arr.Count != 1)
            {
                throw new ArgumentException("-Id script must return a single object.");                 //! use this type
            }
            return(new BsonDocument(BsonId.Element(BsonValue.Create(arr[0].BaseObject))));
        }
示例#2
0
        internal object GetValue(object value)
        {
            var r = Actor.InvokeScript(_ScriptBlock, value);

            switch (r.Count)
            {
            case 1: { return(r[0]); }

            case 0: { return(null); }

            default: { return(r); }
            }
        }
示例#3
0
        public static object ConvertValue(ScriptBlock convert, object value)
        {
            var result = Actor.InvokeScript(convert, value);

            switch (result.Count)
            {
            case 0:
                return(null);

            case 1:
            {
                var ps = result[0];
                return(ps?.BaseObject);
            }

            default:
                //! use this type
                throw new RuntimeException($"Converter script should return one value or none but it returns {result.Count}.");
            }
        }