コード例 #1
0
ファイル: XmlUtil.cs プロジェクト: Gabo1988/Playground
        public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
        {
            if (indexes.Count() != 1)
            {
                result = null;
                return false;
            }

            if (indexes[0] is int)
            {
                var elementIdx = (int)indexes[0];
                if (Elements.Count() > elementIdx)
                {
                    result = new FxElement(Elements[elementIdx]);
                    return true;
                }

                result = new FxElement(null);
                return true;
            }

            if (Elements == null || !Elements.Any())
            {
                result = new string[0];
                return true;
            }

            var attributeName = indexes[0] as string;

            var attributes = from element in Elements
                             let fxElement = new FxElement(element)
                             let value = fxElement.GetAttribute(attributeName)
                             where value != null
                             select value;

            result = attributes.ToArray();
            return true;
        }
コード例 #2
0
        public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
        {
            if (indexes.Count() != 1)
            {
                result = null;
                return(false);
            }

            if (indexes[0] is int)
            {
                var elementIdx = (int)indexes[0];
                if (Elements.Count() > elementIdx)
                {
                    result = new FxElement(Elements[elementIdx]);
                    return(true);
                }

                result = new FxElement(null);
                return(true);
            }

            if (Elements == null || !Elements.Any())
            {
                result = new string[0];
                return(true);
            }

            var attributeName = indexes[0] as string;

            var attributes = from element in Elements
                             let fxElement                         = new FxElement(element)
                                                         let value = fxElement.GetAttribute(attributeName)
                                                                     where value != null
                                                                     select value;

            result = attributes.ToArray();
            return(true);
        }