Ejemplo n.º 1
0
 private CodeObjectSource(object target, int[] arrayRanks, CodeObjectSourceType type)
 {
     _target = target;
     _arrayRanks = arrayRanks;
     _type = type;
 }
Ejemplo n.º 2
0
        private static CodeObjectSource InternalCreate(object target, int[] arrayRanks, CodeObjectSourceType type)
        {
            if (target == null)
            {
                return null;
            }

            Debug.Assert(Utils.IsSource(target));

            if (arrayRanks == null)
            {
                arrayRanks = new int[0];
            }

            Type typeTarget = target as Type;

            if (typeTarget != null && typeTarget.IsArray)
            {
                List<int> ranks = new List<int>();

                while (typeTarget.IsArray)
                {
                    ranks.Add(typeTarget.GetArrayRank());
                    typeTarget = typeTarget.GetElementType();
                }

                target = typeTarget;
                arrayRanks = ranks.ToArray();
            }

            CodeObjectSource source = new CodeObjectSource(target, arrayRanks, type);
            //CodeObjectSource cachedSource;

            //if (_cache.TryGetValue(source, out cachedSource))
            //{
            //    source = cachedSource;
            //}
            //else
            //{
            //    _cache.Add(source, source);
            //}

            return source;
        }
Ejemplo n.º 3
0
        public static CodeObjectSource CreateMergeXXX(CodeObjectSource source, int[] ranks, CodeObjectSourceType type)
        {
            if (type == CodeObjectSourceType.Normal && ranks.Length > 0)
            {
                throw new ArgumentException("Invalid type", "type");
            }

            if (ranks.Length == 0)
            {
                return source;
            }
            else
            {
                CodeObjectSource newSource = source;

                if (type == CodeObjectSourceType.Array)
                {
                    for (int i = ranks.Length - 1; i >= 0; i--)
                    {
                        newSource = CreateIndexer(source, ranks[i]);
                    }
                }
                else
                {
                    for (int i = ranks.Length - 1; i >= 0; i--)
                    {
                        newSource = CreateArray(source, ranks[i]);
                    }
                }

                return newSource;
            }
        }