public Array ToArray()
        {
            ArrayList array = new ArrayList();

            int[] dims = targetArray.GetDimensions();
            if (dims.Length != 1)
            {
                throw new NotSupportedException();
            }
            int[] idx        = new int [1];
            Type  commonType = null;

            for (int n = 0; n < dims[0]; n++)
            {
                idx[0] = n;
                object rv = ctx.Adapter.ToRawValue(ctx, new ArrayObjectSource(targetArray, idx), targetArray.GetElement(idx));
                if (commonType == null)
                {
                    commonType = rv.GetType();
                }
                else if (commonType != rv.GetType())
                {
                    commonType = typeof(void);
                }
                array.Add(rv);
            }
            if (array.Count > 0 && commonType != typeof(void))
            {
                return(array.ToArray(commonType));
            }
            else
            {
                return(array.ToArray());
            }
        }
Exemple #2
0
 public ArrayElementGroup(EvaluationContext ctx, ICollectionAdaptor array, int[] baseIndices, int firstIndex, int lastIndex)
 {
     this.array       = array;
     this.ctx         = ctx;
     this.dimensions  = array.GetDimensions();
     this.baseIndices = baseIndices;
     this.firstIndex  = firstIndex;
     this.lastIndex   = lastIndex;
 }
		public ArrayElementGroup (EvaluationContext ctx, ICollectionAdaptor array, int[] baseIndices, int firstIndex, int lastIndex)
		{
			this.array = array;
			this.ctx = ctx;
			this.bounds = array.GetDimensions ();
			this.baseIndices = baseIndices;
			this.firstIndex = firstIndex;
			this.lastIndex = lastIndex;
		}
Exemple #4
0
 public virtual object TargetObjectToObject(EvaluationContext ctx, object obj)
 {
     if (IsNull(ctx, obj))
     {
         return(null);
     }
     else if (IsArray(ctx, obj))
     {
         ICollectionAdaptor adaptor = CreateArrayAdaptor(ctx, obj);
         string             ename   = GetDisplayTypeName(GetTypeName(ctx, adaptor.ElementType));
         int[]         dims         = adaptor.GetDimensions();
         StringBuilder tn           = new StringBuilder("[");
         for (int n = 0; n < dims.Length; n++)
         {
             if (n > 0)
             {
                 tn.Append(',');
             }
             tn.Append(dims[n]);
         }
         tn.Append("]");
         int i = ename.LastIndexOf('>');
         if (i == -1)
         {
             i = 0;
         }
         i = ename.IndexOf('[', i);
         if (i != -1)
         {
             return(new EvaluationResult("{" + ename.Substring(0, i) + tn + ename.Substring(i) + "}"));
         }
         else
         {
             return(new EvaluationResult("{" + ename + tn + "}"));
         }
     }
     else if (IsEnum(ctx, obj))
     {
         object type            = GetValueType(ctx, obj);
         object longType        = GetType(ctx, "System.Int64");
         object c               = Cast(ctx, obj, longType);
         long   val             = (long)TargetObjectToObject(ctx, c);
         long   rest            = val;
         string typeName        = GetTypeName(ctx, type);
         string composed        = string.Empty;
         string composedDisplay = string.Empty;
         foreach (EnumMember em in GetEnumMembers(ctx, type))
         {
             if (em.Value == val)
             {
                 return(new EvaluationResult(typeName + "." + em.Name, em.Name));
             }
             else
             {
                 if (em.Value != 0 && (rest & em.Value) == em.Value)
                 {
                     rest &= ~em.Value;
                     if (composed.Length > 0)
                     {
                         composed        += "|";
                         composedDisplay += "|";
                     }
                     composed        += typeName + "." + em.Name;
                     composedDisplay += em.Name;
                 }
             }
         }
         if (IsFlagsEnumType(ctx, type) && rest == 0 && composed.Length > 0)
         {
             return(new EvaluationResult(composed, composedDisplay));
         }
         else
         {
             return(new EvaluationResult(val.ToString()));
         }
     }
     else if (GetValueTypeName(ctx, obj) == "System.Decimal")
     {
         string res = CallToString(ctx, obj);
         // This returns the decimal formatted using the current culture. It has to be converted to invariant culture.
         decimal dec = decimal.Parse(res);
         res = dec.ToString(System.Globalization.CultureInfo.InvariantCulture);
         return(new EvaluationResult(res));
     }
     else if (IsClassInstance(ctx, obj))
     {
         TypeDisplayData tdata = GetTypeDisplayData(ctx, GetValueType(ctx, obj));
         if (!string.IsNullOrEmpty(tdata.ValueDisplayString) && ctx.Options.AllowDisplayStringEvaluation)
         {
             return(new EvaluationResult(EvaluateDisplayString(ctx, obj, tdata.ValueDisplayString)));
         }
         // Return the type name
         if (ctx.Options.AllowToStringCalls)
         {
             return(new EvaluationResult("{" + CallToString(ctx, obj) + "}"));
         }
         if (!string.IsNullOrEmpty(tdata.TypeDisplayString) && ctx.Options.AllowDisplayStringEvaluation)
         {
             return(new EvaluationResult("{" + EvaluateDisplayString(ctx, obj, tdata.TypeDisplayString) + "}"));
         }
         return(new EvaluationResult("{" + GetDisplayTypeName(GetValueTypeName(ctx, obj)) + "}"));
     }
     return(new EvaluationResult("{" + CallToString(ctx, obj) + "}"));
 }