internal NespResolvedExpression[] ResolveById(string id, NespIdExpression untypedExpression) { // TODO: Reexamination priority of members and symbols. var fieldInfos = fields[id]; if (fieldInfos.Length >= 1) { return(fieldInfos .Select(field => ConstructExpressionFromField(field, untypedExpression)) .ToArray()); } var propertyInfos = properties[id]; if (propertyInfos.Length >= 1) { return(propertyInfos .Select(property => (NespResolvedExpression) new NespPropertyExpression(property, untypedExpression.Source)) .ToArray()); } // TODO: Events var methodInfos = methods[id]; if (methodInfos.Length >= 1) { return(methodInfos .Select(method => (NespResolvedExpression) new NespApplyFunctionExpression( method, emptyExpressions, untypedExpression.Source)) .ToArray()); } // TODO: Handle type annotation var symbolExpression = new NespReferenceSymbolExpression(id, untypedExpression.Source); var sexprs = symbols[id]; if (sexprs.Length >= 1) { // Set related (original) expression. // This works will effect at lambda expression. symbolExpression.SetRelated(sexprs[0]); } else { // New symbol created. // It's maybe parameter expression. symbols.AddCandidate(id, symbolExpression); } return(new NespResolvedExpression[] { symbolExpression }); }
/// <summary> /// Construct expression from field information. /// </summary> /// <param name="field">Field information.</param> /// <param name="untypedExpression">Target untyped expression reference.</param> /// <returns>Expression (resolved)</returns> /// <remarks>This method construct expression from field. /// If field gives concrete value (Literal or marked initonly), /// get real value at this point and construct constant expression.</remarks> private static NespResolvedExpression ConstructExpressionFromField( FieldInfo field, NespIdExpression untypedExpression) { // Field is literal or marked initonly. if (field.IsStatic && (field.IsLiteral || field.IsInitOnly)) { // Get real value. var value = field.GetValue(null); var type = field.FieldType; if (type == typeof(bool)) { return(new NespBoolExpression((bool)value, untypedExpression.Source)); } if (type == typeof(string)) { return(new NespStringExpression((string)value, untypedExpression.Source)); } if (type == typeof(char)) { return(new NespCharExpression((char)value, untypedExpression.Source)); } if ((type == typeof(byte)) || (type == typeof(sbyte)) || (type == typeof(short)) || (type == typeof(ushort)) || (type == typeof(int)) || (type == typeof(uint)) || (type == typeof(long)) || (type == typeof(ulong)) || (type == typeof(float)) || (type == typeof(double)) || (type == typeof(decimal))) { return(new NespNumericExpression(value, untypedExpression.Source)); } if (type.GetTypeInfo().IsEnum) { return(new NespEnumExpression((Enum)value, untypedExpression.Source)); } return(new NespConstantExpression(value, untypedExpression.Source)); } // Field reference resolved at runtime. return(new NespFieldExpression(field, untypedExpression.Source)); }