예제 #1
0
파일: zMongo.cs 프로젝트: 24/source_04
        public static BsonValue zGet(this BsonValue value, string name, bool mandatory = false)
        {
            //Trace.WriteLine("zGet : get value \"{0}\" from {1}", name, value != null ? value.GetType().zGetName() : "null");
            //return value.zGet(name.Split('.'));
            BsonElement element = value.zGetElement(name.Split('.'));

            if (element != null)
            {
                return(element.Value);
            }
            else if (mandatory)
            {
                throw new PBException($"value not found \"{name}\"");
            }
            else
            {
                return(null);
            }
            //foreach (string name2 in name.Split('.'))
            //{
            //    //Trace.WriteLine("zGet : get value \"{0}\" from {1}", name2, value.GetType().zGetName());
            //    if (!(value is BsonDocument))
            //    {
            //        //Trace.WriteLine("zGet : value is not BsonDocument return null");
            //        return null;
            //    }
            //    BsonDocument document = (BsonDocument)value;
            //    if (!document.Contains(name2))
            //    {
            //        //Trace.WriteLine("zGet : value does not contain \"{0}\" return null", name2);
            //        return null;
            //    }
            //    value = document[name2];
            //}
            //return value;
        }
예제 #2
0
파일: zMongo.cs 프로젝트: 24/source_04
 public static BsonElement zGetElement(this BsonValue value, string name)
 {
     return(value.zGetElement(name.Split('.')));
 }