Пример #1
0
        private static bool ConstantsCallback(FieldInfo field, ImplementsConstantAttribute ica, object result)
        {
            PhpArray array = (PhpArray)result;

            ((PhpArray)array["name"]).Add(ica.Name);
            ((PhpArray)array["type"]).Add(field.DeclaringType.FullName);
            ((PhpArray)array["field"]).Add(field.Name);
            ((PhpArray)array["insensitive"]).Add(ica.CaseInsensitive);
            return(true);
        }
Пример #2
0
        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)
                //    {
                //        // ...
                //    }
                //}
            }
        }