<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />

RuntimeBinder

using Microsoft.CSharp.RuntimeBinder.Semantics; using Microsoft.CSharp.RuntimeBinder.Syntax; using System; using System.Collections.Generic; using System.Diagnostics; using System.Dynamic; using System.Linq; using System.Linq.Expressions; using System.Reflection; namespace Microsoft.CSharp.RuntimeBinder { internal class RuntimeBinder { private class ArgumentObject { internal Type Type; internal object Value; internal CSharpArgumentInfo Info; } private static readonly object s_singletonLock = new object(); private static volatile RuntimeBinder s_instance; private SymbolTable _symbolTable; private CSemanticChecker _semanticChecker; private ExprFactory _exprFactory; private OutputContext _outputContext; private NameGenerator _nameGenerator; private BindingContext _bindingContext; private ExpressionBinder _binder; private RuntimeBinderController _controller; private readonly object _bindLock = new object(); private SymbolLoader SymbolLoader => _semanticChecker.GetSymbolLoader(); public static RuntimeBinder GetInstance() { if (s_instance == null) { lock (s_singletonLock) { if (s_instance == null) s_instance = new RuntimeBinder(); } } return s_instance; } public RuntimeBinder() { Reset(); } private void Reset() { _controller = new RuntimeBinderController(); _semanticChecker = new LangCompiler(_controller, new NameManager()); BSYMMGR bSymmgr = _semanticChecker.getBSymmgr(); NameManager nameManager = _semanticChecker.GetNameManager(); InputFile inputFile = bSymmgr.GetMiscSymFactory().CreateMDInfile(nameManager.Lookup(""), mdToken.mdtModule); inputFile.SetAssemblyID(bSymmgr.AidAlloc(inputFile)); inputFile.AddToAlias(KAID.kaidThisAssembly); inputFile.AddToAlias(KAID.kaidGlobal); _symbolTable = new SymbolTable(bSymmgr.GetSymbolTable(), bSymmgr.GetSymFactory(), nameManager, _semanticChecker.GetTypeManager(), bSymmgr, _semanticChecker, inputFile); _semanticChecker.getPredefTypes().Init(_semanticChecker.GetErrorContext(), _symbolTable); _semanticChecker.GetTypeManager().InitTypeFactory(_symbolTable); SymbolLoader.getPredefinedMembers().RuntimeBinderSymbolTable = _symbolTable; SymbolLoader.SetSymbolTable(_symbolTable); _exprFactory = new ExprFactory(_semanticChecker.GetSymbolLoader().GetGlobalSymbolContext()); _outputContext = new OutputContext(); _nameGenerator = new NameGenerator(); _bindingContext = BindingContext.CreateInstance(_semanticChecker, _exprFactory, _outputContext, _nameGenerator, false, true, false, false, false, false, KAID.kaidGlobal); _binder = new ExpressionBinder(_bindingContext); } public Expression Bind(DynamicMetaObjectBinder payload, IEnumerable<Expression> parameters, DynamicMetaObject[] args, out DynamicMetaObject deferredBinding) { lock (_bindLock) { try { return BindCore(payload, parameters, args, out deferredBinding); } catch (ResetBindException) { Reset(); try { return BindCore(payload, parameters, args, out deferredBinding); } catch (ResetBindException) { Reset(); throw Error.InternalCompilerError(); } } } } private Expression BindCore(DynamicMetaObjectBinder payload, IEnumerable<Expression> parameters, DynamicMetaObject[] args, out DynamicMetaObject deferredBinding) { if (args.Length < 1) throw Error.BindRequireArguments(); InitializeCallingContext(payload); ArgumentObject[] array = CreateArgumentArray(payload, parameters, args); ICSharpInvokeOrInvokeMemberBinder iCSharpInvokeOrInvokeMemberBinder = payload as ICSharpInvokeOrInvokeMemberBinder; PopulateSymbolTableWithPayloadInformation(payload, array[0].Type, array); AddConversionsForArguments(array); Dictionary<int, LocalVariableSymbol> dictionary = new Dictionary<int, LocalVariableSymbol>(); Scope pScope = _semanticChecker.GetGlobalMiscSymFactory().CreateScope(null); PopulateLocalScope(payload, pScope, array, parameters, dictionary); DynamicMetaObject deferredBinding2 = null; if (DeferBinding(payload, array, args, dictionary, out deferredBinding2)) { deferredBinding = deferredBinding2; return null; } EXPR pResult = DispatchPayload(payload, array, dictionary); deferredBinding = null; return CreateExpressionTreeFromResult(parameters, array, pScope, pResult); } private bool DeferBinding(DynamicMetaObjectBinder payload, ArgumentObject[] arguments, DynamicMetaObject[] args, Dictionary<int, LocalVariableSymbol> dictionary, out DynamicMetaObject deferredBinding) { if (payload is CSharpInvokeMemberBinder) { ICSharpInvokeOrInvokeMemberBinder iCSharpInvokeOrInvokeMemberBinder = payload as ICSharpInvokeOrInvokeMemberBinder; int arity = (iCSharpInvokeOrInvokeMemberBinder.TypeArguments != null) ? iCSharpInvokeOrInvokeMemberBinder.TypeArguments.Count : 0; MemberLookup mem = new MemberLookup(); EXPR callingObject = CreateCallingObjectForCall(iCSharpInvokeOrInvokeMemberBinder, arguments, dictionary); SymWithType symWithType = _symbolTable.LookupMember(iCSharpInvokeOrInvokeMemberBinder.Name, callingObject, _bindingContext.ContextForMemberLookup(), arity, mem, (iCSharpInvokeOrInvokeMemberBinder.Flags & CSharpCallFlags.EventHookup) != CSharpCallFlags.None, true); if (symWithType != (SymWithType)null && symWithType.Sym.getKind() != SYMKIND.SK_MethodSymbol) { CSharpGetMemberBinder cSharpGetMemberBinder = new CSharpGetMemberBinder(iCSharpInvokeOrInvokeMemberBinder.Name, false, iCSharpInvokeOrInvokeMemberBinder.CallingContext, new CSharpArgumentInfo[1] { iCSharpInvokeOrInvokeMemberBinder.ArgumentInfo[0] }); CSharpArgumentInfo[] array = new CSharpArgumentInfo[iCSharpInvokeOrInvokeMemberBinder.ArgumentInfo.Count]; iCSharpInvokeOrInvokeMemberBinder.ArgumentInfo.CopyTo(array, 0); array[0] = CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null); CSharpInvokeBinder cSharpInvokeBinder = new CSharpInvokeBinder(iCSharpInvokeOrInvokeMemberBinder.Flags, iCSharpInvokeOrInvokeMemberBinder.CallingContext, array); DynamicMetaObject[] array2 = new DynamicMetaObject[args.Length - 1]; Array.Copy(args, 1, array2, 0, args.Length - 1); deferredBinding = cSharpInvokeBinder.Defer(cSharpGetMemberBinder.Defer(args[0], Array.Empty<DynamicMetaObject>()), array2); return true; } } deferredBinding = null; return false; } private void InitializeCallingContext(DynamicMetaObjectBinder payload) { Type type = null; bool flag = false; if (payload is ICSharpInvokeOrInvokeMemberBinder) type = (payload as ICSharpInvokeOrInvokeMemberBinder).CallingContext; else if (payload is CSharpGetMemberBinder) { type = (payload as CSharpGetMemberBinder).CallingContext; } else if (payload is CSharpSetMemberBinder) { CSharpSetMemberBinder cSharpSetMemberBinder = (CSharpSetMemberBinder)payload; type = cSharpSetMemberBinder.CallingContext; flag = cSharpSetMemberBinder.IsChecked; } else if (payload is CSharpGetIndexBinder) { type = (payload as CSharpGetIndexBinder).CallingContext; } else if (payload is CSharpSetIndexBinder) { CSharpSetIndexBinder cSharpSetIndexBinder = (CSharpSetIndexBinder)payload; type = cSharpSetIndexBinder.CallingContext; flag = cSharpSetIndexBinder.IsChecked; } else if (payload is CSharpUnaryOperationBinder) { CSharpUnaryOperationBinder cSharpUnaryOperationBinder = (CSharpUnaryOperationBinder)payload; type = cSharpUnaryOperationBinder.CallingContext; flag = cSharpUnaryOperationBinder.IsChecked; } else if (payload is CSharpBinaryOperationBinder) { CSharpBinaryOperationBinder cSharpBinaryOperationBinder = (CSharpBinaryOperationBinder)payload; type = cSharpBinaryOperationBinder.CallingContext; flag = cSharpBinaryOperationBinder.IsChecked; } else if (payload is CSharpConvertBinder) { CSharpConvertBinder cSharpConvertBinder = (CSharpConvertBinder)payload; type = cSharpConvertBinder.CallingContext; flag = cSharpConvertBinder.IsChecked; } else if (payload is CSharpIsEventBinder) { type = (payload as CSharpIsEventBinder).CallingContext; } if ((object)type != null) { AggregateSymbol owningAggregate = _symbolTable.GetCTypeFromType(type).AsAggregateType().GetOwningAggregate(); _bindingContext.m_pParentDecl = _semanticChecker.GetGlobalSymbolFactory().CreateAggregateDecl(owningAggregate, null); } else _bindingContext.m_pParentDecl = null; _bindingContext.CheckedConstant = flag; _bindingContext.CheckedNormal = flag; } private Expression CreateExpressionTreeFromResult(IEnumerable<Expression> parameters, ArgumentObject[] arguments, Scope pScope, EXPR pResult) { EXPRBOUNDLAMBDA expr = GenerateBoundLambda(arguments, pScope, pResult); EXPR pExpr = ExpressionTreeRewriter.Rewrite(expr, _exprFactory, SymbolLoader); return ExpressionTreeCallRewriter.Rewrite(SymbolLoader.GetTypeManager(), pExpr, parameters); } private ArgumentObject[] CreateArgumentArray(DynamicMetaObjectBinder payload, IEnumerable<Expression> parameters, DynamicMetaObject[] args) { List<ArgumentObject> list = new List<ArgumentObject>(); Func<DynamicMetaObjectBinder, CSharpArgumentInfo, Expression, DynamicMetaObject, int, Type> func = null; Func<DynamicMetaObjectBinder, int, CSharpArgumentInfo> func2 = null; if (payload is ICSharpInvokeOrInvokeMemberBinder) func2 = ((DynamicMetaObjectBinder p, int index) => (p as ICSharpInvokeOrInvokeMemberBinder).ArgumentInfo[index]); else if (payload is CSharpBinaryOperationBinder) { func2 = ((DynamicMetaObjectBinder p, int index) => (p as CSharpBinaryOperationBinder).ArgumentInfo[index]); } else if (payload is CSharpUnaryOperationBinder) { func2 = ((DynamicMetaObjectBinder p, int index) => (p as CSharpUnaryOperationBinder).ArgumentInfo[index]); } else if (payload is CSharpGetMemberBinder) { func2 = ((DynamicMetaObjectBinder p, int index) => (p as CSharpGetMemberBinder).ArgumentInfo[index]); } else if (payload is CSharpSetMemberBinder) { func2 = ((DynamicMetaObjectBinder p, int index) => (p as CSharpSetMemberBinder).ArgumentInfo[index]); } else if (payload is CSharpGetIndexBinder) { func2 = ((DynamicMetaObjectBinder p, int index) => (p as CSharpGetIndexBinder).ArgumentInfo[index]); } else if (payload is CSharpSetIndexBinder) { func2 = ((DynamicMetaObjectBinder p, int index) => (p as CSharpSetIndexBinder).ArgumentInfo[index]); } else { if (!(payload is CSharpConvertBinder) && !(payload is CSharpIsEventBinder)) throw Error.InternalCompilerError(); func2 = ((DynamicMetaObjectBinder p, int index) => CSharpArgumentInfo.None); } func = delegate(DynamicMetaObjectBinder p, CSharpArgumentInfo argInfo, Expression param, DynamicMetaObject arg, int index) { Type type = argInfo.UseCompileTimeType ? param.Type : arg.LimitType; if ((argInfo.Flags & (CSharpArgumentInfoFlags.IsRef | CSharpArgumentInfoFlags.IsOut)) != 0) { if (index != 0 || !IsBinderThatCanHaveRefReceiver(p)) type = type.MakeByRefType(); } else if (!argInfo.UseCompileTimeType) { CType cTypeFromType = _symbolTable.GetCTypeFromType(type); if (!_semanticChecker.GetTypeManager().GetBestAccessibleType(_semanticChecker, _bindingContext, cTypeFromType, out CType typeDst)) type = typeof(object); type = typeDst.AssociatedSystemType; } return type; }; int num = 0; foreach (Expression parameter in parameters) { ArgumentObject argumentObject = new ArgumentObject(); argumentObject.Value = args[num].Value; argumentObject.Info = func2(payload, num); argumentObject.Type = func(payload, argumentObject.Info, parameter, args[num], num); list.Add(argumentObject); num++; } return list.ToArray(); } private bool IsBinderThatCanHaveRefReceiver(DynamicMetaObjectBinder binder) { if (!(binder is ICSharpInvokeOrInvokeMemberBinder) && !(binder is CSharpSetIndexBinder)) return binder is CSharpGetIndexBinder; return true; } private void PopulateSymbolTableWithPayloadInformation(DynamicMetaObjectBinder payload, Type callingType, ArgumentObject[] arguments) { ICSharpInvokeOrInvokeMemberBinder iCSharpInvokeOrInvokeMemberBinder; CSharpGetMemberBinder cSharpGetMemberBinder; CSharpSetMemberBinder cSharpSetMemberBinder; if ((iCSharpInvokeOrInvokeMemberBinder = (payload as ICSharpInvokeOrInvokeMemberBinder)) != null) { Type callingType2; if (iCSharpInvokeOrInvokeMemberBinder.StaticCall) { if (arguments[0].Value == null || !(arguments[0].Value is Type)) throw Error.InternalCompilerError(); callingType2 = (arguments[0].Value as Type); } else callingType2 = callingType; _symbolTable.PopulateSymbolTableWithName(iCSharpInvokeOrInvokeMemberBinder.Name, iCSharpInvokeOrInvokeMemberBinder.TypeArguments, callingType2); if (iCSharpInvokeOrInvokeMemberBinder.Name.StartsWith("set_", StringComparison.Ordinal) || iCSharpInvokeOrInvokeMemberBinder.Name.StartsWith("get_", StringComparison.Ordinal)) _symbolTable.PopulateSymbolTableWithName(iCSharpInvokeOrInvokeMemberBinder.Name.Substring(4), iCSharpInvokeOrInvokeMemberBinder.TypeArguments, callingType2); } else if ((cSharpGetMemberBinder = (payload as CSharpGetMemberBinder)) != null) { _symbolTable.PopulateSymbolTableWithName(cSharpGetMemberBinder.Name, null, arguments[0].Type); } else if ((cSharpSetMemberBinder = (payload as CSharpSetMemberBinder)) != null) { _symbolTable.PopulateSymbolTableWithName(cSharpSetMemberBinder.Name, null, arguments[0].Type); } else if (payload is CSharpGetIndexBinder || payload is CSharpSetIndexBinder) { _symbolTable.PopulateSymbolTableWithName("$Item$", null, arguments[0].Type); } else if (payload is CSharpBinaryOperationBinder) { CSharpBinaryOperationBinder cSharpBinaryOperationBinder = payload as CSharpBinaryOperationBinder; if (GetCLROperatorName(cSharpBinaryOperationBinder.Operation) == null) throw Error.InternalCompilerError(); _symbolTable.PopulateSymbolTableWithName(GetCLROperatorName(cSharpBinaryOperationBinder.Operation), null, arguments[0].Type); _symbolTable.PopulateSymbolTableWithName(GetCLROperatorName(cSharpBinaryOperationBinder.Operation), null, arguments[1].Type); } else if (payload is CSharpUnaryOperationBinder) { CSharpUnaryOperationBinder cSharpUnaryOperationBinder = payload as CSharpUnaryOperationBinder; _symbolTable.PopulateSymbolTableWithName(GetCLROperatorName(cSharpUnaryOperationBinder.Operation), null, arguments[0].Type); } else if (payload is CSharpIsEventBinder) { CSharpIsEventBinder cSharpIsEventBinder = payload as CSharpIsEventBinder; _symbolTable.PopulateSymbolTableWithName(cSharpIsEventBinder.Name, null, arguments[0].Info.IsStaticType ? (arguments[0].Value as Type) : arguments[0].Type); } else if (!(payload is CSharpConvertBinder)) { throw Error.InternalCompilerError(); } } private void AddConversionsForArguments(ArgumentObject[] arguments) { foreach (ArgumentObject argumentObject in arguments) { _symbolTable.AddConversionsForType(argumentObject.Type); } } private EXPR DispatchPayload(DynamicMetaObjectBinder payload, ArgumentObject[] arguments, Dictionary<int, LocalVariableSymbol> dictionary) { EXPR eXPR = null; if (!(payload is CSharpBinaryOperationBinder)) { if (!(payload is CSharpUnaryOperationBinder)) { if (!(payload is CSharpSetMemberBinder)) { if (payload is CSharpConvertBinder) { CSharpConvertBinder cSharpConvertBinder = payload as CSharpConvertBinder; switch (cSharpConvertBinder.ConversionKind) { case CSharpConversionKind.ImplicitConversion: return BindImplicitConversion(arguments, cSharpConvertBinder.Type, dictionary, false); case CSharpConversionKind.ExplicitConversion: return BindExplicitConversion(arguments, cSharpConvertBinder.Type, dictionary); case CSharpConversionKind.ArrayCreationConversion: return BindImplicitConversion(arguments, cSharpConvertBinder.Type, dictionary, true); default: throw Error.InternalCompilerError(); } } if (!(payload is ICSharpInvokeOrInvokeMemberBinder)) { if (!(payload is CSharpGetMemberBinder)) { if (!(payload is CSharpGetIndexBinder)) { if (!(payload is CSharpSetIndexBinder)) { if (!(payload is CSharpIsEventBinder)) throw Error.InternalCompilerError(); return BindIsEvent(payload as CSharpIsEventBinder, arguments, dictionary); } return BindAssignment(payload as CSharpSetIndexBinder, arguments, dictionary); } EXPR optionalIndexerArguments = CreateArgumentListEXPR(arguments, dictionary, 1, arguments.Length); return BindProperty(payload, arguments[0], dictionary[0], optionalIndexerArguments, false); } return BindProperty(payload, arguments[0], dictionary[0], null, false); } EXPR callingObject = CreateCallingObjectForCall(payload as ICSharpInvokeOrInvokeMemberBinder, arguments, dictionary); return BindCall(payload as ICSharpInvokeOrInvokeMemberBinder, callingObject, arguments, dictionary); } return BindAssignment(payload as CSharpSetMemberBinder, arguments, dictionary); } return BindUnaryOperation(payload as CSharpUnaryOperationBinder, arguments, dictionary); } return BindBinaryOperation(payload as CSharpBinaryOperationBinder, arguments, dictionary); } private void PopulateLocalScope(DynamicMetaObjectBinder payload, Scope pScope, ArgumentObject[] arguments, IEnumerable<Expression> parameterExpressions, Dictionary<int, LocalVariableSymbol> dictionary) { int num = 0; foreach (Expression parameterExpression in parameterExpressions) { CType cType = _symbolTable.GetCTypeFromType(parameterExpression.Type); bool flag = false; if (num == 0 && IsBinderThatCanHaveRefReceiver(payload)) flag = true; if (parameterExpression is ParameterExpression && (parameterExpression as ParameterExpression).IsByRef && (arguments[num].Info.IsByRef || arguments[num].Info.IsOut) && !flag) cType = _semanticChecker.GetTypeManager().GetParameterModifier(cType, arguments[num].Info.IsOut); LocalVariableSymbol localVariableSymbol = _semanticChecker.GetGlobalSymbolFactory().CreateLocalVar(_semanticChecker.GetNameManager().Add("p" + num), pScope, cType); localVariableSymbol.fUsedInAnonMeth = true; dictionary.Add(num++, localVariableSymbol); flag = false; } } private EXPRBOUNDLAMBDA GenerateBoundLambda(ArgumentObject[] arguments, Scope pScope, EXPR call) { AggregateType delegateType = _symbolTable.GetCTypeFromType(typeof(Func<>)).AsAggregateType(); LocalVariableSymbol localVariableSymbol = _semanticChecker.GetGlobalSymbolFactory().CreateLocalVar(_semanticChecker.GetNameManager().Add("this"), pScope, _symbolTable.GetCTypeFromType(typeof(object))); localVariableSymbol.isThis = true; EXPRBOUNDLAMBDA eXPRBOUNDLAMBDA = _exprFactory.CreateAnonymousMethod(delegateType); EXPRUNBOUNDLAMBDA eXPRUNBOUNDLAMBDA = _exprFactory.CreateLambda(); List<Type> list = new List<Type>(); foreach (ArgumentObject argumentObject in arguments) { list.Add(argumentObject.Type); } eXPRBOUNDLAMBDA.Initialize(pScope); EXPRRETURN pOptionalStatements = _exprFactory.CreateReturn((EXPRFLAG)0, pScope, call); EXPRBLOCK eXPRBLOCK = eXPRBOUNDLAMBDA.OptionalBody = _exprFactory.CreateBlock(null, pOptionalStatements, pScope); return eXPRBOUNDLAMBDA; } private EXPR CreateLocal(Type type, bool bIsOut, LocalVariableSymbol local) { CType cType = _symbolTable.GetCTypeFromType(type); if (bIsOut) cType = _semanticChecker.GetTypeManager().GetParameterModifier(cType.AsParameterModifierType().GetParameterType(), true); EXPRLOCAL expr = _exprFactory.CreateLocal(EXPRFLAG.EXF_LVALUE, local); EXPR eXPR = _binder.tryConvert(expr, cType); if (eXPR == null) eXPR = _binder.mustCast(expr, cType); eXPR.flags |= EXPRFLAG.EXF_LVALUE; return eXPR; } private EXPR CreateArgumentListEXPR(ArgumentObject[] arguments, Dictionary<int, LocalVariableSymbol> dictionary, int startIndex, int endIndex) { EXPR first = null; EXPR last = null; if (arguments != null) { for (int i = startIndex; i < endIndex; i++) { ArgumentObject argument = arguments[i]; EXPR eXPR = CreateArgumentEXPR(argument, dictionary[i]); if (first == null) { first = eXPR; last = first; } else _exprFactory.AppendItemToList(eXPR, ref first, ref last); } } return first; } private EXPR CreateArgumentEXPR(ArgumentObject argument, LocalVariableSymbol local) { EXPR eXPR = argument.Info.LiteralConstant ? ((argument.Value != null) ? _exprFactory.CreateConstant(_symbolTable.GetCTypeFromType(argument.Type), new CONSTVAL(argument.Value)) : ((!argument.Info.UseCompileTimeType) ? _exprFactory.CreateNull() : _exprFactory.CreateConstant(_symbolTable.GetCTypeFromType(argument.Type), new CONSTVAL()))) : ((argument.Info.UseCompileTimeType || argument.Value != null) ? CreateLocal(argument.Type, argument.Info.IsOut, local) : _exprFactory.CreateNull()); if (argument.Info.NamedArgument) eXPR = _exprFactory.CreateNamedArgumentSpecification(SymbolTable.GetName(argument.Info.Name, _semanticChecker.GetNameManager()), eXPR); if (!argument.Info.UseCompileTimeType && argument.Value != null) { eXPR.RuntimeObject = argument.Value; eXPR.RuntimeObjectActualType = _symbolTable.GetCTypeFromType(argument.Value.GetType()); } return eXPR; } private EXPRMEMGRP CreateMemberGroupEXPR(string Name, IList<Type> typeArguments, EXPR callingObject, SYMKIND kind) { Name name = SymbolTable.GetName(Name, _semanticChecker.GetNameManager()); AggregateType aggregateType = callingObject.type.IsArrayType() ? _semanticChecker.GetSymbolLoader().GetReqPredefType(PredefinedType.PT_ARRAY) : (callingObject.type.IsNullableType() ? callingObject.type.AsNullableType().GetAts(_semanticChecker.GetSymbolLoader().GetErrorContext()) : ((!callingObject.type.IsAggregateType()) ? null : callingObject.type.AsAggregateType())); List<CType> list = new List<CType>(); symbmask_t mask = symbmask_t.MASK_MethodSymbol; switch (kind) { case SYMKIND.SK_PropertySymbol: case SYMKIND.SK_IndexerSymbol: mask = symbmask_t.MASK_PropertySymbol; break; case SYMKIND.SK_MethodSymbol: mask = symbmask_t.MASK_MethodSymbol; break; } bool flag = name == SymbolLoader.GetNameManager().GetPredefinedName(PredefinedName.PN_CTOR); for (AggregateType aggregateType2 = aggregateType; aggregateType2 != null; aggregateType2 = aggregateType2.GetBaseClass()) { if (_symbolTable.AggregateContainsMethod(aggregateType2.GetOwningAggregate(), Name, mask)) list.Add(aggregateType2); if (flag) break; } if (aggregateType.IsWindowsRuntimeType()) { TypeArray winRTCollectionIfacesAll = aggregateType.GetWinRTCollectionIfacesAll(SymbolLoader); for (int i = 0; i < winRTCollectionIfacesAll.size; i++) { CType cType = winRTCollectionIfacesAll.Item(i); if (_symbolTable.AggregateContainsMethod(cType.AsAggregateType().GetOwningAggregate(), Name, mask)) list.Add(cType); } } EXPRFLAG eXPRFLAG = EXPRFLAG.EXF_USERCALLABLE; if (Name == "Invoke" && callingObject.type.isDelegateType()) eXPRFLAG |= EXPRFLAG.EXF_GOTONOTBLOCKED; if (Name == ".ctor") eXPRFLAG |= EXPRFLAG.EXF_CTOR; if (Name == "$Item$") eXPRFLAG |= EXPRFLAG.EXF_INDEXER; TypeArray pTypeArgs = BSYMMGR.EmptyTypeArray(); if (typeArguments != null && typeArguments.Count > 0) pTypeArgs = _semanticChecker.getBSymmgr().AllocParams(_symbolTable.GetCTypeArrayFromTypes(typeArguments)); EXPRMEMGRP eXPRMEMGRP = _exprFactory.CreateMemGroup(eXPRFLAG, name, pTypeArgs, kind, aggregateType, null, null, new CMemberLookupResults(_semanticChecker.getBSymmgr().AllocParams(list.Count, list.ToArray()), name)); if (callingObject.isCLASS()) eXPRMEMGRP.SetOptionalLHS(callingObject); else eXPRMEMGRP.SetOptionalObject(callingObject); return eXPRMEMGRP; } private EXPR CreateProperty(SymWithType swt, EXPR callingObject, BindingFlag flags) { PropertySymbol propertySymbol = swt.Prop(); AggregateType type = swt.GetType(); PropWithType pwt = new PropWithType(propertySymbol, type); EXPRMEMGRP pMemGroup = CreateMemberGroupEXPR(propertySymbol.name.Text, null, callingObject, SYMKIND.SK_PropertySymbol); return _binder.BindToProperty(callingObject.isCLASS() ? null : callingObject, pwt, flags, null, null, pMemGroup); } private EXPR CreateIndexer(SymWithType swt, EXPR callingObject, EXPR arguments, BindingFlag bindFlags) { IndexerSymbol indexerSymbol = swt.Sym as IndexerSymbol; AggregateType type = swt.GetType(); EXPRMEMGRP grp = CreateMemberGroupEXPR(indexerSymbol.name.Text, null, callingObject, SYMKIND.SK_PropertySymbol); EXPR pResult = _binder.BindMethodGroupToArguments(bindFlags, grp, arguments); return ReorderArgumentsForNamedAndOptional(callingObject, pResult); } private EXPR CreateArray(EXPR callingObject, EXPR optionalIndexerArguments) { return _binder.BindArrayIndexCore((BindingFlag)0, callingObject, optionalIndexerArguments); } private EXPR CreateField(SymWithType swt, EXPR callingObject) { FieldSymbol fieldSymbol = swt.Field(); CType type = fieldSymbol.GetType(); AggregateType type2 = swt.GetType(); FieldWithType fwt = new FieldWithType(fieldSymbol, type2); return _binder.BindToField(callingObject.isCLASS() ? null : callingObject, fwt, (BindingFlag)0); } private EXPREVENT CreateEvent(SymWithType swt, EXPR callingObject) { EventSymbol eventSymbol = swt.Event(); return _exprFactory.CreateEvent(eventSymbol.type, callingObject, new EventWithType(eventSymbol, swt.GetType())); } private EXPR CreateCallingObjectForCall(ICSharpInvokeOrInvokeMemberBinder payload, ArgumentObject[] arguments, Dictionary<int, LocalVariableSymbol> dictionary) { EXPR eXPR; if (payload.StaticCall) { if (arguments[0].Value == null || !(arguments[0].Value is Type)) throw Error.InternalCompilerError(); Type type = arguments[0].Value as Type; eXPR = _exprFactory.CreateClass(_symbolTable.GetCTypeFromType(type), null, type.GetTypeInfo().get_ContainsGenericParameters() ? _exprFactory.CreateTypeArguments(SymbolLoader.getBSymmgr().AllocParams(_symbolTable.GetCTypeArrayFromTypes(TypeExtensions.GetGenericArguments(type))), null) : null); } else { if (!arguments[0].Info.UseCompileTimeType && arguments[0].Value == null) throw Error.NullReferenceOnMemberException(); eXPR = _binder.mustConvert(CreateArgumentEXPR(arguments[0], dictionary[0]), _symbolTable.GetCTypeFromType(arguments[0].Type)); if (arguments[0].Type.GetTypeInfo().get_IsValueType() && eXPR.isCAST()) eXPR.flags |= EXPRFLAG.EXF_USERCALLABLE; } return eXPR; } private EXPR BindCall(ICSharpInvokeOrInvokeMemberBinder payload, EXPR callingObject, ArgumentObject[] arguments, Dictionary<int, LocalVariableSymbol> dictionary) { if (payload is InvokeBinder && !callingObject.type.isDelegateType()) throw Error.BindInvokeFailedNonDelegate(); EXPR eXPR = null; int arity = (payload.TypeArguments != null) ? payload.TypeArguments.Count : 0; MemberLookup memberLookup = new MemberLookup(); SymWithType symWithType = _symbolTable.LookupMember(payload.Name, callingObject, _bindingContext.ContextForMemberLookup(), arity, memberLookup, (payload.Flags & CSharpCallFlags.EventHookup) != CSharpCallFlags.None, true); if (symWithType == (SymWithType)null) memberLookup.ReportErrors(); if (symWithType.Sym.getKind() != SYMKIND.SK_MethodSymbol) throw Error.InternalCompilerError(); EXPRMEMGRP eXPRMEMGRP = CreateMemberGroupEXPR(payload.Name, payload.TypeArguments, callingObject, symWithType.Sym.getKind()); if ((payload.Flags & CSharpCallFlags.SimpleNameCall) != 0) callingObject.flags |= EXPRFLAG.EXF_UNREALIZEDGOTO; if ((payload.Flags & CSharpCallFlags.EventHookup) != 0) { memberLookup = new MemberLookup(); SymWithType symWithType2 = _symbolTable.LookupMember(payload.Name.Split(new char[1] { '_' })[1], callingObject, _bindingContext.ContextForMemberLookup(), arity, memberLookup, (payload.Flags & CSharpCallFlags.EventHookup) != CSharpCallFlags.None, true); if (symWithType2 == (SymWithType)null) memberLookup.ReportErrors(); CType typeSrc = null; if (symWithType2.Sym.getKind() == SYMKIND.SK_FieldSymbol) typeSrc = symWithType2.Field().GetType(); else if (symWithType2.Sym.getKind() == SYMKIND.SK_EventSymbol) { typeSrc = symWithType2.Event().type; } Type associatedSystemType = SymbolLoader.GetTypeManager().SubstType(typeSrc, symWithType2.Ats).AssociatedSystemType; if ((object)associatedSystemType != null) BindImplicitConversion(new ArgumentObject[1] { arguments[1] }, associatedSystemType, dictionary, false); eXPRMEMGRP.flags &= (EXPRFLAG)(-257); if (symWithType2.Sym.getKind() == SYMKIND.SK_EventSymbol && symWithType2.Event().IsWindowsRuntimeEvent) return BindWinRTEventAccessor(new EventWithType(symWithType2.Event(), symWithType2.Ats), callingObject, arguments, dictionary, payload.Name.StartsWith("add_", StringComparison.Ordinal)); } if ((payload.Name.StartsWith("set_", StringComparison.Ordinal) && symWithType.Sym.AsMethodSymbol().Params.Size > 1) || (payload.Name.StartsWith("get_", StringComparison.Ordinal) && symWithType.Sym.AsMethodSymbol().Params.Size > 0)) eXPRMEMGRP.flags &= (EXPRFLAG)(-257); eXPR = _binder.BindMethodGroupToArguments((BindingFlag)257, eXPRMEMGRP, CreateArgumentListEXPR(arguments, dictionary, 1, arguments.Length)); if (eXPR == null || !eXPR.isOK()) throw Error.BindCallFailedOverloadResolution(); CheckForConditionalMethodError(eXPR); return ReorderArgumentsForNamedAndOptional(callingObject, eXPR); } private EXPR BindWinRTEventAccessor(EventWithType ewt, EXPR callingObject, ArgumentObject[] arguments, Dictionary<int, LocalVariableSymbol> dictionary, bool isAddAccessor) { Type associatedSystemType = ewt.Event().type.AssociatedSystemType; MethPropWithInst mwi = new MethPropWithInst(ewt.Event().methRemove, ewt.Ats); EXPRMEMGRP eXPRMEMGRP = _exprFactory.CreateMemGroup(callingObject, mwi); eXPRMEMGRP.flags &= (EXPRFLAG)(-257); Type eventRegistrationTokenType = SymbolTable.EventRegistrationTokenType; Type actionType = Expression.GetActionType(eventRegistrationTokenType); EXPR eXPR = _binder.mustConvert(eXPRMEMGRP, _symbolTable.GetCTypeFromType(actionType)); EXPR eXPR2 = CreateArgumentEXPR(arguments[1], dictionary[1]); EXPRLIST args; string text; if (isAddAccessor) { MethPropWithInst mwi2 = new MethPropWithInst(ewt.Event().methAdd, ewt.Ats); EXPRMEMGRP eXPRMEMGRP2 = _exprFactory.CreateMemGroup(callingObject, mwi2); eXPRMEMGRP2.flags &= (EXPRFLAG)(-257); Type funcType = Expression.GetFuncType(associatedSystemType, eventRegistrationTokenType); EXPR op = _binder.mustConvert(eXPRMEMGRP2, _symbolTable.GetCTypeFromType(funcType)); args = _exprFactory.CreateList(op, eXPR, eXPR2); text = SymbolLoader.GetNameManager().GetPredefName(PredefinedName.PN_ADDEVENTHANDLER).Text; } else { args = _exprFactory.CreateList(eXPR, eXPR2); text = SymbolLoader.GetNameManager().GetPredefName(PredefinedName.PN_REMOVEEVENTHANDLER).Text; } Type windowsRuntimeMarshalType = SymbolTable.WindowsRuntimeMarshalType; _symbolTable.PopulateSymbolTableWithName(text, new List<Type> { associatedSystemType }, windowsRuntimeMarshalType); EXPRCLASS callingObject2 = _exprFactory.CreateClass(_symbolTable.GetCTypeFromType(windowsRuntimeMarshalType), null, null); EXPRMEMGRP grp = CreateMemberGroupEXPR(text, new List<Type> { associatedSystemType }, callingObject2, SYMKIND.SK_MethodSymbol); return _binder.BindMethodGroupToArguments((BindingFlag)257, grp, args); } private void CheckForConditionalMethodError(EXPR pExpr) { if (pExpr.isCALL()) { EXPRCALL eXPRCALL = pExpr.asCALL(); MethodSymbol methodSymbol = eXPRCALL.mwi.Meth(); if (methodSymbol.isOverride) methodSymbol = methodSymbol.swtSlot.Meth(); object[] array = CustomAttributeExtensions.GetCustomAttributes(methodSymbol.AssociatedMemberInfo, typeof(ConditionalAttribute), false).ToArray(); if (array.Length != 0) throw Error.BindCallToConditionalMethod(methodSymbol.name); } } private EXPR ReorderArgumentsForNamedAndOptional(EXPR callingObject, EXPR pResult) { EXPR optionalArguments; AggregateType ats; EXPRMEMGRP memberGroup; TypeArray typeArgsMeth; MethodOrPropertySymbol methodOrPropertySymbol; if (pResult.isCALL()) { EXPRCALL eXPRCALL = pResult.asCALL(); optionalArguments = eXPRCALL.GetOptionalArguments(); ats = eXPRCALL.mwi.Ats; methodOrPropertySymbol = eXPRCALL.mwi.Meth(); memberGroup = eXPRCALL.GetMemberGroup(); typeArgsMeth = eXPRCALL.mwi.TypeArgs; } else { EXPRPROP eXPRPROP = pResult.asPROP(); optionalArguments = eXPRPROP.GetOptionalArguments(); ats = eXPRPROP.pwtSlot.Ats; methodOrPropertySymbol = eXPRPROP.pwtSlot.Prop(); memberGroup = eXPRPROP.GetMemberGroup(); typeArgsMeth = null; } ArgInfos argInfos = new ArgInfos(); argInfos.carg = ExpressionBinder.CountArguments(optionalArguments, out bool _); _binder.FillInArgInfoFromArgList(argInfos, optionalArguments); TypeArray typeArray = SymbolLoader.GetTypeManager().SubstTypeArray(methodOrPropertySymbol.Params, ats, typeArgsMeth); methodOrPropertySymbol = ExpressionBinder.GroupToArgsBinder.FindMostDerivedMethod(SymbolLoader, methodOrPropertySymbol, callingObject.type); ExpressionBinder.GroupToArgsBinder.ReOrderArgsForNamedArguments(methodOrPropertySymbol, typeArray, ats, memberGroup, argInfos, _semanticChecker.GetTypeManager(), _exprFactory, SymbolLoader); EXPR eXPR = null; for (int num = argInfos.carg - 1; num >= 0; num--) { EXPR pArg = argInfos.prgexpr[num]; pArg = StripNamedArgument(pArg); pArg = _binder.tryConvert(pArg, typeArray[num]); eXPR = ((eXPR != null) ? _exprFactory.CreateList(pArg, eXPR) : pArg); } if (pResult.isCALL()) pResult.asCALL().SetOptionalArguments(eXPR); else pResult.asPROP().SetOptionalArguments(eXPR); return pResult; } private EXPR StripNamedArgument(EXPR pArg) { if (pArg.isNamedArgumentSpecification()) pArg = pArg.asNamedArgumentSpecification().Value; else if (pArg.isARRINIT()) { pArg.asARRINIT().SetOptionalArguments(StripNamedArguments(pArg.asARRINIT().GetOptionalArguments())); } return pArg; } private EXPR StripNamedArguments(EXPR pArg) { if (pArg.isLIST()) { for (EXPRLIST eXPRLIST = pArg.asLIST(); eXPRLIST != null; eXPRLIST = eXPRLIST.GetOptionalNextListNode().asLIST()) { eXPRLIST.SetOptionalElement(StripNamedArgument(eXPRLIST.GetOptionalElement())); if (!eXPRLIST.GetOptionalNextListNode().isLIST()) { eXPRLIST.SetOptionalNextListNode(StripNamedArgument(eXPRLIST.GetOptionalNextListNode())); break; } } } return StripNamedArgument(pArg); } private EXPR BindUnaryOperation(CSharpUnaryOperationBinder payload, ArgumentObject[] arguments, Dictionary<int, LocalVariableSymbol> dictionary) { if (arguments.Length != 1) throw Error.BindUnaryOperatorRequireOneArgument(); OperatorKind operatorKind = GetOperatorKind(payload.Operation); EXPR eXPR = CreateArgumentEXPR(arguments[0], dictionary[0]); eXPR.errorString = Operators.GetDisplayName(GetOperatorKind(payload.Operation)); if (operatorKind == OperatorKind.OP_TRUE || operatorKind == OperatorKind.OP_FALSE) { EXPR eXPR2 = _binder.tryConvert(eXPR, SymbolLoader.GetReqPredefType(PredefinedType.PT_BOOL)); if (eXPR2 != null && operatorKind == OperatorKind.OP_FALSE) eXPR2 = _binder.BindStandardUnaryOperator(OperatorKind.OP_LOGNOT, eXPR2); if (eXPR2 == null) eXPR2 = _binder.bindUDUnop((operatorKind == OperatorKind.OP_TRUE) ? ExpressionKind.EK_TRUE : ExpressionKind.EK_FALSE, eXPR); if (eXPR2 == null) eXPR2 = _binder.mustConvert(eXPR, SymbolLoader.GetReqPredefType(PredefinedType.PT_BOOL)); return eXPR2; } return _binder.BindStandardUnaryOperator(operatorKind, eXPR); } private EXPR BindBinaryOperation(CSharpBinaryOperationBinder payload, ArgumentObject[] arguments, Dictionary<int, LocalVariableSymbol> dictionary) { if (arguments.Length != 2) throw Error.BindBinaryOperatorRequireTwoArguments(); ExpressionKind expressionKind = Operators.GetExpressionKind(GetOperatorKind(payload.Operation, payload.IsLogicalOperation)); EXPR eXPR = CreateArgumentEXPR(arguments[0], dictionary[0]); EXPR eXPR2 = CreateArgumentEXPR(arguments[1], dictionary[1]); eXPR.errorString = Operators.GetDisplayName(GetOperatorKind(payload.Operation, payload.IsLogicalOperation)); eXPR2.errorString = Operators.GetDisplayName(GetOperatorKind(payload.Operation, payload.IsLogicalOperation)); if (expressionKind > ExpressionKind.EK_MULTIOFFSET) expressionKind -= 85; return _binder.BindStandardBinop(expressionKind, eXPR, eXPR2); } private static OperatorKind GetOperatorKind(ExpressionType p) { return GetOperatorKind(p, false); } private static OperatorKind GetOperatorKind(ExpressionType p, bool bIsLogical) { switch (p) { default: throw Error.InternalCompilerError(); case ExpressionType.Add: return OperatorKind.OP_ADD; case ExpressionType.Subtract: return OperatorKind.OP_SUB; case ExpressionType.Multiply: return OperatorKind.OP_MUL; case ExpressionType.Divide: return OperatorKind.OP_DIV; case ExpressionType.Modulo: return OperatorKind.OP_MOD; case ExpressionType.LeftShift: return OperatorKind.OP_LSHIFT; case ExpressionType.RightShift: return OperatorKind.OP_RSHIFT; case ExpressionType.LessThan: return OperatorKind.OP_LT; case ExpressionType.GreaterThan: return OperatorKind.OP_GT; case ExpressionType.LessThanOrEqual: return OperatorKind.OP_LE; case ExpressionType.GreaterThanOrEqual: return OperatorKind.OP_GE; case ExpressionType.Equal: return OperatorKind.OP_EQ; case ExpressionType.NotEqual: return OperatorKind.OP_NEQ; case ExpressionType.And: if (!bIsLogical) return OperatorKind.OP_BITAND; return OperatorKind.OP_LOGAND; case ExpressionType.ExclusiveOr: return OperatorKind.OP_BITXOR; case ExpressionType.Or: if (!bIsLogical) return OperatorKind.OP_BITOR; return OperatorKind.OP_LOGOR; case ExpressionType.AddAssign: return OperatorKind.OP_ADDEQ; case ExpressionType.SubtractAssign: return OperatorKind.OP_SUBEQ; case ExpressionType.MultiplyAssign: return OperatorKind.OP_MULEQ; case ExpressionType.DivideAssign: return OperatorKind.OP_DIVEQ; case ExpressionType.ModuloAssign: return OperatorKind.OP_MODEQ; case ExpressionType.AndAssign: return OperatorKind.OP_ANDEQ; case ExpressionType.ExclusiveOrAssign: return OperatorKind.OP_XOREQ; case ExpressionType.OrAssign: return OperatorKind.OP_OREQ; case ExpressionType.LeftShiftAssign: return OperatorKind.OP_LSHIFTEQ; case ExpressionType.RightShiftAssign: return OperatorKind.OP_RSHIFTEQ; case ExpressionType.Negate: return OperatorKind.OP_NEG; case ExpressionType.UnaryPlus: return OperatorKind.OP_UPLUS; case ExpressionType.Not: return OperatorKind.OP_LOGNOT; case ExpressionType.OnesComplement: return OperatorKind.OP_BITNOT; case ExpressionType.IsTrue: return OperatorKind.OP_TRUE; case ExpressionType.IsFalse: return OperatorKind.OP_FALSE; case ExpressionType.Increment: return OperatorKind.OP_PREINC; case ExpressionType.Decrement: return OperatorKind.OP_PREDEC; } } private static string GetCLROperatorName(ExpressionType p) { switch (p) { default: return null; case ExpressionType.Add: return "op_Addition"; case ExpressionType.Subtract: return "op_Subtraction"; case ExpressionType.Multiply: return "op_Multiply"; case ExpressionType.Divide: return "op_Division"; case ExpressionType.Modulo: return "op_Modulus"; case ExpressionType.LeftShift: return "op_LeftShift"; case ExpressionType.RightShift: return "op_RightShift"; case ExpressionType.LessThan: return "op_LessThan"; case ExpressionType.GreaterThan: return "op_GreaterThan"; case ExpressionType.LessThanOrEqual: return "op_LessThanOrEqual"; case ExpressionType.GreaterThanOrEqual: return "op_GreaterThanOrEqual"; case ExpressionType.Equal: return "op_Equality"; case ExpressionType.NotEqual: return "op_Inequality"; case ExpressionType.And: return "op_BitwiseAnd"; case ExpressionType.ExclusiveOr: return "op_ExclusiveOr"; case ExpressionType.Or: return "op_BitwiseOr"; case ExpressionType.AddAssign: return "op_Addition"; case ExpressionType.SubtractAssign: return "op_Subtraction"; case ExpressionType.MultiplyAssign: return "op_Multiply"; case ExpressionType.DivideAssign: return "op_Division"; case ExpressionType.ModuloAssign: return "op_Modulus"; case ExpressionType.AndAssign: return "op_BitwiseAnd"; case ExpressionType.ExclusiveOrAssign: return "op_ExclusiveOr"; case ExpressionType.OrAssign: return "op_BitwiseOr"; case ExpressionType.LeftShiftAssign: return "op_LeftShift"; case ExpressionType.RightShiftAssign: return "op_RightShift"; case ExpressionType.Negate: return "op_UnaryNegation"; case ExpressionType.UnaryPlus: return "op_UnaryPlus"; case ExpressionType.Not: return "op_LogicalNot"; case ExpressionType.OnesComplement: return "op_OnesComplement"; case ExpressionType.IsTrue: return "op_True"; case ExpressionType.IsFalse: return "op_False"; case ExpressionType.Increment: return "op_Increment"; case ExpressionType.Decrement: return "op_Decrement"; } } private EXPR BindProperty(DynamicMetaObjectBinder payload, ArgumentObject argument, LocalVariableSymbol local, EXPR optionalIndexerArguments, bool fEventsPermitted) { EXPR eXPR = argument.Info.IsStaticType ? _exprFactory.CreateClass(_symbolTable.GetCTypeFromType(argument.Value as Type), null, null) : CreateLocal(argument.Type, argument.Info.IsOut, local); if (argument.Info.UseCompileTimeType || argument.Value != null) { if (argument.Type.GetTypeInfo().get_IsValueType() && eXPR.isCAST()) eXPR.flags |= EXPRFLAG.EXF_USERCALLABLE; string name = GetName(payload); BindingFlag bindingFlags = GetBindingFlags(payload); MemberLookup memberLookup = new MemberLookup(); SymWithType symWithType = _symbolTable.LookupMember(name, eXPR, _bindingContext.ContextForMemberLookup(), 0, memberLookup, false, false); if (symWithType == (SymWithType)null) { if (optionalIndexerArguments != null) { int num = ExpressionIterator.Count(optionalIndexerArguments); if ((argument.Type.IsArray && argument.Type.GetArrayRank() == num) || (object)argument.Type == typeof(string)) return CreateArray(eXPR, optionalIndexerArguments); } memberLookup.ReportErrors(); } switch (symWithType.Sym.getKind()) { case SYMKIND.SK_MethodSymbol: throw Error.BindPropertyFailedMethodGroup(name); case SYMKIND.SK_PropertySymbol: { if (symWithType.Sym is IndexerSymbol) return CreateIndexer(symWithType, eXPR, optionalIndexerArguments, bindingFlags); BindingFlag flags = (BindingFlag)0; if (payload is CSharpGetMemberBinder || payload is CSharpGetIndexBinder) flags = BindingFlag.BIND_RVALUEREQUIRED; eXPR.flags |= EXPRFLAG.EXF_LVALUE; return CreateProperty(symWithType, eXPR, flags); } case SYMKIND.SK_FieldSymbol: return CreateField(symWithType, eXPR); case SYMKIND.SK_EventSymbol: if (fEventsPermitted) return CreateEvent(symWithType, eXPR); throw Error.BindPropertyFailedEvent(name); default: throw Error.InternalCompilerError(); } } throw Error.NullReferenceOnMemberException(); } private EXPR BindImplicitConversion(ArgumentObject[] arguments, Type returnType, Dictionary<int, LocalVariableSymbol> dictionary, bool bIsArrayCreationConversion) { if (arguments.Length != 1) throw Error.BindImplicitConversionRequireOneArgument(); _symbolTable.AddConversionsForType(returnType); EXPR eXPR = CreateArgumentEXPR(arguments[0], dictionary[0]); CType cTypeFromType = _symbolTable.GetCTypeFromType(returnType); if (bIsArrayCreationConversion) { CType cType = _binder.chooseArrayIndexType(eXPR); if (cType == null) cType = SymbolLoader.GetReqPredefType(PredefinedType.PT_INT, true); return _binder.mustCast(_binder.mustConvert(eXPR, cType), cTypeFromType, (CONVERTTYPE)9); } return _binder.mustConvert(eXPR, cTypeFromType); } private EXPR BindExplicitConversion(ArgumentObject[] arguments, Type returnType, Dictionary<int, LocalVariableSymbol> dictionary) { if (arguments.Length != 1) throw Error.BindExplicitConversionRequireOneArgument(); _symbolTable.AddConversionsForType(returnType); EXPR expr = CreateArgumentEXPR(arguments[0], dictionary[0]); CType cTypeFromType = _symbolTable.GetCTypeFromType(returnType); return _binder.mustCast(expr, cTypeFromType); } private EXPR BindAssignment(DynamicMetaObjectBinder payload, ArgumentObject[] arguments, Dictionary<int, LocalVariableSymbol> dictionary) { if (arguments.Length < 2) throw Error.BindBinaryAssignmentRequireTwoArguments(); string name = GetName(payload); EXPR optionalIndexerArguments = null; bool flag = false; if (payload is CSharpSetIndexBinder) { optionalIndexerArguments = CreateArgumentListEXPR(arguments, dictionary, 1, arguments.Length - 1); flag = (payload as CSharpSetIndexBinder).IsCompoundAssignment; } else flag = (payload as CSharpSetMemberBinder).IsCompoundAssignment; _symbolTable.PopulateSymbolTableWithName(name, null, arguments[0].Type); EXPR op = BindProperty(payload, arguments[0], dictionary[0], optionalIndexerArguments, false); int num = arguments.Length - 1; EXPR op2 = CreateArgumentEXPR(arguments[num], dictionary[num]); if (arguments[0] == null) throw Error.BindBinaryAssignmentFailedNullReference(); return _binder.bindAssignment(op, op2, flag); } private EXPR BindIsEvent(CSharpIsEventBinder binder, ArgumentObject[] arguments, Dictionary<int, LocalVariableSymbol> dictionary) { EXPR callingObject = CreateLocal(arguments[0].Type, false, dictionary[0]); MemberLookup mem = new MemberLookup(); CType reqPredefType = SymbolLoader.GetReqPredefType(PredefinedType.PT_BOOL); bool value = false; if (arguments[0].Value == null) throw Error.NullReferenceOnMemberException(); SymWithType symWithType = _symbolTable.LookupMember(binder.Name, callingObject, _bindingContext.ContextForMemberLookup(), 0, mem, false, false); if (symWithType != (SymWithType)null && symWithType.Sym.getKind() == SYMKIND.SK_EventSymbol) value = true; if (symWithType != (SymWithType)null && symWithType.Sym.getKind() == SYMKIND.SK_FieldSymbol && symWithType.Sym.AsFieldSymbol().isEvent) value = true; return _exprFactory.CreateConstant(reqPredefType, ConstValFactory.GetBool(value)); } private string GetName(DynamicMetaObjectBinder payload) { string result = null; if (payload is CSharpGetMemberBinder) result = ((CSharpGetMemberBinder)payload).Name; else if (payload is CSharpSetMemberBinder) { result = ((CSharpSetMemberBinder)payload).Name; } else if (payload is CSharpGetIndexBinder || payload is CSharpSetIndexBinder) { result = "$Item$"; } return result; } private BindingFlag GetBindingFlags(DynamicMetaObjectBinder payload) { if (payload is CSharpGetMemberBinder || payload is CSharpGetIndexBinder) return BindingFlag.BIND_RVALUEREQUIRED; return (BindingFlag)0; } } }