Ejemplo n.º 1
0
        // Private Methods 

        static string DotNetNameToPhpName(string fullName)
        {
            if (fullName == null)
            {
                throw new ArgumentNullException("fullName");
            }
            fullName = fullName.Replace("`", "__");

            return(string.Join("",
                               from i in fullName.Replace("+", ".").Split('.')
                               select PhpQualifiedName.TokenNsSeparator + PhpQualifiedName.SanitizePhpName(i)));
        }
Ejemplo n.º 2
0
        void Update()
        {
            if (_initialized)
            {
                return;
            }
            _initialized = true;


            var ati = _info.GetOrMakeTranslationInfo(_type.Assembly);


            var declaringTypeTranslationInfo = (object)_type.DeclaringType == null
                ? null
                : _info.GetOrMakeTranslationInfo(_type.DeclaringType);
            var ats = _type.GetCustomAttributes(false);

            _ignoreNamespace = ats.OfType <IgnoreNamespaceAttribute>().Any();

            #region ScriptName
            {
                if (_ignoreNamespace)
                {
                    _scriptName = (PhpQualifiedName)PhpQualifiedName.SanitizePhpName(_type.Name); // only short name without namespace
                }
                else if (_type.IsGenericType)
                {
                    _scriptName = (PhpQualifiedName)DotNetNameToPhpName(_type.FullName ?? _type.Name); // beware of generic types
                }
                else
                {
                    _scriptName = (PhpQualifiedName)DotNetNameToPhpName(_type.FullName ?? _type.Name);
                }

                var scriptNameAttribute = ats.OfType <ScriptNameAttribute>().FirstOrDefault();
                if (scriptNameAttribute != null)
                {
                    if (scriptNameAttribute.Name.StartsWith(PhpQualifiedName.TokenNsSeparator.ToString(CultureInfo.InvariantCulture)))
                    {
                        _scriptName = (PhpQualifiedName)scriptNameAttribute.Name;
                    }
                    else if (IgnoreNamespace)
                    {
                        _scriptName = (PhpQualifiedName)(PhpQualifiedName.TokenNsSeparator + scriptNameAttribute.Name);
                    }
                    else
                    {
                        _scriptName =
                            (PhpQualifiedName)
                            (DotNetNameToPhpName(_type.FullName) + PhpQualifiedName.TokenNsSeparator +
                             scriptNameAttribute.Name);
                    }
                }
                if (declaringTypeTranslationInfo != null)
                {
                    _scriptName = (PhpQualifiedName)(declaringTypeTranslationInfo.ScriptName + "__" + _type.Name); // parent clas followed by __ and short name
                }
            }
            #endregion
            #region Module name
            {
                //if (declaringTypeTranslationInfo != null && declaringTypeTranslationInfo.ModuleName != null)
                _moduleName = new PhpCodeModuleName(_type, ati, declaringTypeTranslationInfo);
            }
            #endregion
            #region PageAttribute
            {
                var pageAttribute = ats.OfType <PageAttribute>().FirstOrDefault();
                _isPage     = pageAttribute != null;
                _pageMethod = _isPage ? FindPhpMainMethod(_type) : null;
            }
            #endregion
            #region AsArrayAttribute
            {
                var asArrayAttribute = ats.OfType <AsArrayAttribute>().FirstOrDefault();
                _isArray = asArrayAttribute != null;
            }
            #endregion
            #region SkipAttribute
            {
                var skipAttribute = ats.OfType <SkipAttribute>().FirstOrDefault();
                if (skipAttribute != null)
                {
                    _skip = true;
                }
            }
            #endregion
            #region BuiltInAttribute
            {
                var builtInAttribute = ats.OfType <BuiltInAttribute>().FirstOrDefault();
                if (builtInAttribute != null)
                {
                    _buildIn = true;
                }
            }
            #endregion

            if (_skip && _buildIn)
            {
                throw new Exception("Don't mix SkipAttribute and BuiltInAttribute for type " + _type.ExcName());
            }
            if (_buildIn)
            {
                _skip = true;
            }
            if (_type.IsGenericParameter)
            {
                _skip = true;
            }
            if (_isArray)
            {
                _skip = true;
            }
        }