/// <summary> /// Reflect global constants in <script> class. /// </summary> /// <param name="scriptType">The type representing single script.</param> /// <param name="constants">Dictionary for constants.</param> private void ReflectScriptTypeConstants(Type scriptType, DualDictionary <string, DConstantDesc> /*!*/ constants) { foreach (var field in scriptType.GetFields(BindingFlags.Public | BindingFlags.Static)) { // TODO: namespaces!! GlobalConstant constant = new GlobalConstant(this, QualifiedName.FromClrNotation(field.Name, true), field); constant.SetValue(Convert.ClrLiteralToPhpLiteral(field.GetValue(null))); constants.Add(field.Name, constant.ConstantDesc, false); } }
static GlobalConstant() { if (UnknownModule.RuntimeModule == null) { UnknownModule.RuntimeModule = new UnknownModule(); } Null = new GlobalConstant(QualifiedName.Null, Fields.PhpVariable_LiteralNull); Null.SetValue(null); False = new GlobalConstant(QualifiedName.False, Fields.PhpVariable_LiteralFalse); False.SetValue(false); True = new GlobalConstant(QualifiedName.True, Fields.PhpVariable_LiteralTrue); True.SetValue(true); PhpIntSize = new GlobalConstant(new QualifiedName(new Name("PHP_INT_SIZE")), typeof(PhpVariable).GetField("LiteralIntSize")); PhpIntSize.SetValue(PhpVariable.LiteralIntSize); PhpIntMax = new GlobalConstant(new QualifiedName(new Name("PHP_INT_MAX")), typeof(int).GetField("MaxValue")); PhpIntMax.SetValue(int.MaxValue); }
private void ReflectConstants(FieldInfo[] /*!!*/ realFields, DualDictionary <string, DConstantDesc> /*!*/ constants) { foreach (FieldInfo field in realFields) { // reflect only fields with [ImplementsConstant] attribute: ImplementsConstantAttribute impl_const = ImplementsConstantAttribute.Reflect(field); if (impl_const != null) { object value; try { // expect the constant have literal value, otherwise crash value = Convert.ClrLiteralToPhpLiteral(field.GetValue(null)); } catch (Exception) { throw new InvalidCastException(); } GlobalConstant constant = new GlobalConstant(this, new QualifiedName(new Name(impl_const.Name)), field); constant.SetValue(value); constants[impl_const.Name, impl_const.CaseInsensitive] = constant.ConstantDesc; } //// accepts literals of PHP/CLR primitive types only: //if (field.IsLiteral && (PhpVariable.IsLiteralPrimitiveType(field.FieldType) || field.FieldType.IsEnum)) //{ // if (impl_const != null) // { // // ... // } //} } }
private void ReflectConstants(FieldInfo[]/*!!*/ realFields, DualDictionary<string, DConstantDesc>/*!*/ constants) { foreach (FieldInfo field in realFields) { // reflect only fields with [ImplementsConstant] attribute: ImplementsConstantAttribute impl_const = ImplementsConstantAttribute.Reflect(field); if (impl_const != null) { object value; try { // expect the constant have literal value, otherwise crash value = Convert.ClrLiteralToPhpLiteral(field.GetValue(null)); } catch(Exception) { throw new InvalidCastException(); } GlobalConstant constant = new GlobalConstant(this ,new QualifiedName(new Name(impl_const.Name)), field); constant.SetValue(value); constants[impl_const.Name, impl_const.CaseInsensitive] = constant.ConstantDesc; } //// accepts literals of PHP/CLR primitive types only: //if (field.IsLiteral && (PhpVariable.IsLiteralPrimitiveType(field.FieldType) || field.FieldType.IsEnum)) //{ // if (impl_const != null) // { // // ... // } //} } }
/// <summary> /// Reflect global constants in <script> class. /// </summary> /// <param name="scriptType">The type representing single script.</param> /// <param name="constants">Dictionary for constants.</param> private void ReflectScriptTypeConstants(Type scriptType, DualDictionary<string, DConstantDesc>/*!*/ constants) { foreach (var field in scriptType.GetFields(BindingFlags.Public | BindingFlags.Static)) { // TODO: namespaces!! GlobalConstant constant = new GlobalConstant(this, ClrNotationUtils.FromClrNotation(field.Name, true), field); constant.SetValue(Convert.ClrLiteralToPhpLiteral(field.GetValue(null))); constants.Add(field.Name, constant.ConstantDesc, false); } }
static GlobalConstant() { if (UnknownModule.RuntimeModule == null) UnknownModule.RuntimeModule = new UnknownModule(); Null = new GlobalConstant(QualifiedName.Null, Fields.PhpVariable_LiteralNull); Null.SetValue(null); False = new GlobalConstant(QualifiedName.False, Fields.PhpVariable_LiteralFalse); False.SetValue(false); True = new GlobalConstant(QualifiedName.True, Fields.PhpVariable_LiteralTrue); True.SetValue(true); PhpIntSize = new GlobalConstant(new QualifiedName(new Name("PHP_INT_SIZE")), typeof(PhpVariable).GetField("LiteralIntSize")); PhpIntSize.SetValue(PhpVariable.LiteralIntSize); PhpIntMax = new GlobalConstant(new QualifiedName(new Name("PHP_INT_MAX")), typeof(int).GetField("MaxValue")); PhpIntMax.SetValue(int.MaxValue); }