static OperatorCache() { Add = GetOperator <T, T>(Operators.Add); Subtract = GetOperator <T, T>(Operators.Subtract); Divide = GetOperator <T, T>(Operators.Divide); Multiply = GetOperator <T, T>(Operators.Multiply); }
protected OperatorImplementation AddBinary(ExpressionType op, Type commonType, BinaryOperatorMethod binaryMethod, UnaryOperatorMethod resultConverter) { var key = new OperatorDispatchKey(op, commonType, commonType); var impl = new OperatorImplementation(key, commonType, binaryMethod, null, null, resultConverter); OperatorImplementations[key] = impl; return impl; }
protected void AddImplementation(string op, Type baseType, BinaryOperatorMethod baseMethod, TypeConverter resultConverter) { var key = OperatorDispatchKey.CreateFromTypes(op, baseType, baseType); var imp = new OperatorImplementation(key, baseType, baseMethod, null, null, resultConverter); _baseOperatorImplementations.Add(key, imp); }
public LiftedBinaryOperatorMethod(CSharpOperators operators, BinaryOperatorMethod baseMethod) : base(operators.compilation) { this.baseMethod = baseMethod; this.ReturnType = NullableType.Create(operators.compilation, baseMethod.ReturnType); this.Parameters.Add(operators.MakeNullableParameter(baseMethod.Parameters[0])); this.Parameters.Add(operators.MakeNullableParameter(baseMethod.Parameters[1])); }
protected OperatorImplementation AddBinary(ExpressionType op, Type commonType, BinaryOperatorMethod binaryMethod, UnaryOperatorMethod resultConverter) { var key = new OperatorDispatchKey(op, commonType, commonType); var impl = new OperatorImplementation(key, commonType, binaryMethod, null, null, resultConverter); OperatorImplementations[key] = impl; return(impl); }
public OperatorImplementation(OperatorDispatchKey key, Type type, UnaryOperatorMethod method) { Key = key; CommonType = type; Arg1Converter = method; Arg2Converter = null; ResultConverter = null; BaseBinaryMethod = null; }
public OperatorImplementation(OperatorDispatchKey key, Type baseType, BinaryOperatorMethod baseMethod, TypeConverter arg1Converter, TypeConverter arg2Converter, TypeConverter resultConverter) { Key = key; BaseType = baseType; Arg1Converter = arg1Converter; Arg2Converter = arg2Converter; ResultConverter = resultConverter; BaseMethod = baseMethod; SetupEvaluationMethod(); }
public OperatorImplementation(OperatorDispatchKey key, Type resultType, BinaryOperatorMethod baseBinaryMethod, UnaryOperatorMethod arg1Converter, UnaryOperatorMethod arg2Converter, UnaryOperatorMethod resultConverter) { Key = key; CommonType = resultType; Arg1Converter = arg1Converter; Arg2Converter = arg2Converter; ResultConverter = resultConverter; BaseBinaryMethod = baseBinaryMethod; SetupEvaluationMethod(); }
protected OperatorImplementation AddBinaryBoxed(ExpressionType op, Type baseType, BinaryOperatorMethod boxedBinaryMethod, BinaryOperatorMethod noBoxMethod) { // first create implementation without boxing var noBoxImpl = AddBinary(op, baseType, noBoxMethod); if (!SmartBoxingEnabled) return noBoxImpl; //The boxedImpl will overwrite noBoxImpl in the dictionary var boxedImpl = AddBinary(op, baseType, boxedBinaryMethod); boxedImpl.NoBoxImplementation = noBoxImpl; return boxedImpl; }
public void SetupEvaluationMethod() { if (BaseBinaryMethod == null) { //special case - it is unary method, the method itself in Arg1Converter; LanguageRuntime.ExecuteUnaryOperator will handle this properly return; } // Binary operator if (ResultConverter == null) { //without ResultConverter if (Arg1Converter == null && Arg2Converter == null) { EvaluateBinary = EvaluateConvNone; } else if (Arg1Converter != null && Arg2Converter == null) { EvaluateBinary = EvaluateConvLeft; } else if (Arg1Converter == null && Arg2Converter != null) { EvaluateBinary = EvaluateConvRight; } else // if (Arg1Converter != null && arg2Converter != null) { EvaluateBinary = EvaluateConvBoth; } } else { //with result converter if (Arg1Converter == null && Arg2Converter == null) { EvaluateBinary = EvaluateConvNoneConvResult; } else if (Arg1Converter != null && Arg2Converter == null) { EvaluateBinary = EvaluateConvLeftConvResult; } else if (Arg1Converter == null && Arg2Converter != null) { EvaluateBinary = EvaluateConvRightConvResult; } else // if (Arg1Converter != null && Arg2Converter != null) { EvaluateBinary = EvaluateConvBothConvResult; } } }
public void SetupEvaluationMethod() { if (BaseBinaryMethod == null) { return; } // Binary operator if (ResultConverter == null) { //without ResultConverter if (Arg1Converter == null && Arg2Converter == null) { EvaluateBinary = EvaluateConvNone; } else if (Arg1Converter != null && Arg2Converter == null) { EvaluateBinary = EvaluateConvLeft; } else if (Arg1Converter == null && Arg2Converter != null) { EvaluateBinary = EvaluateConvRight; } else // if (Arg1Converter != null && arg2Converter != null) { EvaluateBinary = EvaluateConvBoth; } } else { //with result converter if (Arg1Converter == null && Arg2Converter == null) { EvaluateBinary = EvaluateConvNoneConvResult; } else if (Arg1Converter != null && Arg2Converter == null) { EvaluateBinary = EvaluateConvLeftConvResult; } else if (Arg1Converter == null && Arg2Converter != null) { EvaluateBinary = EvaluateConvRightConvResult; } else // if (Arg1Converter != null && Arg2Converter != null) { EvaluateBinary = EvaluateConvBothConvResult; } } }
protected OperatorImplementation AddBinaryBoxed(ExpressionType op, Type baseType, BinaryOperatorMethod boxedBinaryMethod, BinaryOperatorMethod noBoxMethod) { // first create implementation without boxing var noBoxImpl = AddBinary(op, baseType, noBoxMethod); if (!SmartBoxingEnabled) { return(noBoxImpl); } //The boxedImpl will overwrite noBoxImpl in the dictionary var boxedImpl = AddBinary(op, baseType, boxedBinaryMethod); boxedImpl.NoBoxImplementation = noBoxImpl; return(boxedImpl); }
public void SetupEvaluationMethod() { if (ResultConverter == null) { //without ResultConverter if (Arg1Converter == null && Arg2Converter == null) { Evaluate = EvaluateConvNone; } else if (Arg1Converter != null && Arg2Converter == null) { Evaluate = EvaluateConvLeft; } else if (Arg1Converter == null && Arg2Converter != null) { Evaluate = EvaluateConvRight; } else // if (Arg1Converter != null && arg2Converter != null) { Evaluate = EvaluateConvBoth; } } else { //with result converter if (Arg1Converter == null && Arg2Converter == null) { Evaluate = EvaluateConvNoneConvResult; } else if (Arg1Converter != null && Arg2Converter == null) { Evaluate = EvaluateConvLeftConvResult; } else if (Arg1Converter == null && Arg2Converter != null) { Evaluate = EvaluateConvRightConvResult; } else // if (Arg1Converter != null && Arg2Converter != null) { Evaluate = EvaluateConvBothConvResult; } } }
protected virtual OperatorImplementation CreateBinaryOperatorImplementation(ExpressionType op, Type arg1Type, Type arg2Type, Type commonType, BinaryOperatorMethod method, UnaryOperatorMethod resultConverter) { var key = new OperatorDispatchKey(op, arg1Type, arg2Type); var arg1Converter = arg1Type == commonType ? null : GetConverter(arg1Type, commonType); var arg2Converter = arg2Type == commonType ? null : GetConverter(arg2Type, commonType); var impl = new OperatorImplementation(key, commonType, method, arg1Converter, arg2Converter, resultConverter); return(impl); }
}//method protected void AddImplementation(string op, Type baseType, BinaryOperatorMethod baseMethod) { AddImplementation(op, baseType, baseMethod, null); }
protected OperatorImplementation AddBinary(ExpressionType op, Type baseType, BinaryOperatorMethod binaryMethod) { return(AddBinary(op, baseType, binaryMethod, null)); }
public Operator(BinaryOperatorMethod binaryOperator, char symbolOperator) { this.binaryOperator = binaryOperator; this.symbolOperator = symbolOperator; }
protected OperatorImplementation AddBinary(ExpressionType op, Type baseType, BinaryOperatorMethod binaryMethod) { return AddBinary(op, baseType, binaryMethod, null); }
protected virtual OperatorImplementation CreateBinaryOperatorImplementation(ExpressionType op, Type arg1Type, Type arg2Type, Type commonType, BinaryOperatorMethod method, UnaryOperatorMethod resultConverter) { OperatorDispatchKey key = new OperatorDispatchKey(op, arg1Type, arg2Type); UnaryOperatorMethod arg1Converter = arg1Type == commonType ? null : GetConverter(arg1Type, commonType); UnaryOperatorMethod arg2Converter = arg2Type == commonType ? null : GetConverter(arg2Type, commonType); var impl = new OperatorImplementation( key, commonType, method, arg1Converter, arg2Converter, resultConverter); return impl; }