Exemplo n.º 1
0
 public DelegateExpr(IHasValue <P1> p1, Func <P1, T> dlg, string shortName)
 {
     mP1 = p1;
     if (p1 != null)
     {
         p1.Subscribe(this, "p1");
     }
     System.Diagnostics.Debug.Assert(dlg != null);
     mDelegate  = dlg;
     mShortName = shortName;
 }
Exemplo n.º 2
0
        public GetArrayEntryExpr(IHasValue array, List <IHasValue> @params)
        {
            array.Subscribe(this, "Array");
            Subscribe("index", @params);
            IHasValue[] newParams = @params.ToArray();
            int[]       newValues = new int[@params.Count];

            mArray            = array;
            mParams           = newParams;
            mValues           = newValues;
            mResultSystemType = array.ValueType.GetElementType();
        }
Exemplo n.º 3
0
 public OperatorIfExpr(IHasValue ifExpr, IHasValue thenExpr, IHasValue elseExpr)
 {
     this.ifExpr = ifExpr;
     if (ifExpr != null)
     {
         ifExpr.Subscribe(this, "if");
     }
     this.thenExpr = thenExpr;
     if (thenExpr != null)
     {
         thenExpr.Subscribe(this, "then");
     }
     this.elseExpr = elseExpr;
     if (elseExpr != null)
     {
         elseExpr.Subscribe(this, "else");
     }
     mSystemType = thenExpr.ValueType;
 }
Exemplo n.º 4
0
 public static IDisposable Subscribe(this IHasValue source, string role, Action action)
 {
     return(source.Subscribe(new SimpleObserver(source, action), role));
 }
Exemplo n.º 5
0
        public CallMethodExpr(IHasValue baseObject, MemberInfo method, List <IHasValue> @params, object[] casts, string shortName)
        {
            if (baseObject != null)
            {
                baseObject.Subscribe(this, "baseObject");
            }
            Subscribe("parameter", @params);

            if (@params == null)
            {
                @params = new List <IHasValue>();
            }

            var preparedParams = new List <IHasValue>();

            mBaseObject = baseObject;
            mMethod     = method;
            mShortName  = shortName;

            ParameterInfo[] paramInfo = null;
            if (method is PropertyInfo)
            {
                mResultSystemType = ((PropertyInfo)method).PropertyType;
                paramInfo         = ((PropertyInfo)method).GetIndexParameters();
            }
            else if (method is MethodInfo)
            {
                var mi = (MethodInfo)method;
                mResultSystemType = mi.ReturnType;
                paramInfo         = mi.GetParameters();
            }
            else if (method is FieldInfo)
            {
                mResultSystemType = ((FieldInfo)method).FieldType;
                paramInfo         = new ParameterInfo[] { };
            }

            for (int i = 0; i < @params.Count; i++)
            {
                if (i < paramInfo.Length)
                {
                    var sourceType = @params[i].ValueType;
                    var targetType = paramInfo[i].ParameterType;
                    if (casts[i] == null)
                    {
                        preparedParams.Add(@params[i]);
                    }
                    else
                    {
                        if (casts[i].GetType().IsArray)
                        {
                            var c2 = typeof(ArrayBuilder <>).MakeGenericType(targetType.GetElementType());
                            preparedParams.Add((IHasValue)Activator.CreateInstance(c2, new object[] { @params.Skip(i).ToArray(), casts[i] }));
                            // we have consumed all parameters
                            break;
                        }
                        var c3 = typeof(DelegateExpr <,>).MakeGenericType(sourceType, targetType);
                        preparedParams.Add((IHasValue)Activator.CreateInstance(c3, @params[i], casts[i], @params[i].ShortName));
                    }
                }
            }

            mPreparedParams = preparedParams.ToArray();
            mParamValues    = new object[mPreparedParams.Length];

            if (method is PropertyInfo)
            {
                mValueDelegate = EmitGetMethod(baseObject, ((PropertyInfo)method).GetGetMethod());
            }
            else if (method is MethodInfo)
            {
                mValueDelegate = EmitGetMethod(baseObject, (MethodInfo)method);
            }
            else if (method is FieldInfo)
            {
                EmitGetField(baseObject, method);
            }
        }