// Private Methods private static string DotNetNameToPyName(string fullName) { if (fullName == null) { throw new ArgumentNullException(nameof(fullName)); } fullName = fullName.Replace("`", "__"); return(string.Join("", from i in fullName.Replace("+", ".").Split('.') select PyQualifiedName.TokenNsSeparator + PyQualifiedName.SanitizePyName(i))); }
public PyClassDefinition FindOrCreateClass(PyQualifiedName pyClassName, PyQualifiedName baseClass) { var c = Classes.FirstOrDefault(i => pyClassName == i.Name); if (c != null) { return(c); } c = new PyClassDefinition(pyClassName, baseClass); Classes.Add(c); return(c); }
/// <summary> /// Tworzy instancję obiektu /// <param name="className"></param> /// </summary> public ClassCodeRequest(PyQualifiedName className) { ClassName = className; }
private 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(); { // ScriptName if (_ignoreNamespace) { _pyName = (PyQualifiedName)PyQualifiedName .SanitizePyName(Type.Name); // only short name without namespace } else if (Type.IsGenericType) { _pyName = (PyQualifiedName)DotNetNameToPyName(Type.FullName ?? Type.Name); // beware of generic types } else { _pyName = (PyQualifiedName)DotNetNameToPyName(Type.FullName ?? Type.Name); } var scriptNameAttribute = ats.OfType <PyNameAttribute>().FirstOrDefault(); if (scriptNameAttribute != null) { if (scriptNameAttribute.Name.StartsWith( PyQualifiedName.TokenNsSeparator.ToString(CultureInfo.InvariantCulture))) { _pyName = (PyQualifiedName)scriptNameAttribute.Name; } else if (IgnoreNamespace) { _pyName = (PyQualifiedName)(PyQualifiedName.TokenNsSeparator + scriptNameAttribute.Name); } else { _pyName = (PyQualifiedName) (DotNetNameToPyName(Type.FullName) + PyQualifiedName.TokenNsSeparator + scriptNameAttribute.Name); } } if (declaringTypeTranslationInfo != null) { _pyName = (PyQualifiedName)(declaringTypeTranslationInfo.PyName + "__" + Type.Name); // parent clas followed by __ and short name } } { // Module name _moduleName = new PyCodeModuleName(Type, true, declaringTypeTranslationInfo); } { // PageAttribute var pageAttribute = ats.OfType <PageAttribute>().FirstOrDefault(); _isPage = pageAttribute != null; _pageMethod = _isPage ? FindPyMainMethod(Type) : null; } { // export as Module var pageAttribute = ats.OfType <ExportAsPyModuleAttribute>().FirstOrDefault(); _exportAsModule = pageAttribute != null; } { // AsArrayAttribute var asArrayAttribute = ats.OfType <AsArrayAttribute>().FirstOrDefault(); _isArray = asArrayAttribute != null; } { // SkipAttribute var skipAttribute = ats.OfType <SkipAttribute>().FirstOrDefault(); if (skipAttribute != null) { _skip = true; } } { // BuiltInAttribute var builtInAttribute = ats.OfType <BuiltInAttribute>().FirstOrDefault(); if (builtInAttribute != null) { _buildIn = true; } } 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; } }