コード例 #1
0
        private void ValidateBaseClass(ClassDeclaration originalDecl, ClassDefinition classDef)
        {
            var extensionFactory = new ExtensionFactory();
            var extensions = extensionFactory.GetExtensions(classDef.Symbol);

            if (!extensions.Any(e => e.GetType() == typeof(ScriptObjectLiteralExtension)) &&
                (classDef.Constructors.Any(c => !c.Symbol.IsImplicitlyDeclared) ||
                classDef.Methods.Any(m => !m.Symbol.IsImplicitlyDeclared) ||
                classDef.Properties.Any(p => p.MemberKind != MemberDefinitionKind.Field) ||
                classDef.Fields.Any(f => f.MemberKind != MemberDefinitionKind.Field)))
            {
                throw new CompilationException("A class using the [ScriptObjectLiteral] attribute cannot inherit from class " + classDef.Symbol.GetFullName() +
                    ", because it contains one or more declarations that are not compatible with object literal notations.", originalDecl);
            }

            if (classDef.BaseClass != null && classDef.BaseClass.Symbol.SpecialType != Roslyn.Compilers.SpecialType.System_Object)
                ValidateBaseClass(originalDecl, classDef.BaseClass);
        }
コード例 #2
0
        private void ValidateBaseClass(ClassDeclaration originalDecl, ClassDefinition classDef)
        {
            var extensionFactory = new ExtensionFactory();
            var extensions       = extensionFactory.GetExtensions(classDef.Symbol);

            if (!extensions.Any(e => e.GetType() == typeof(ScriptObjectLiteralExtension)) &&
                (classDef.Constructors.Any(c => !c.Symbol.IsImplicitlyDeclared) ||
                 classDef.Methods.Any(m => !m.Symbol.IsImplicitlyDeclared) ||
                 classDef.Properties.Any(p => p.MemberKind != MemberDefinitionKind.Field) ||
                 classDef.Fields.Any(f => f.MemberKind != MemberDefinitionKind.Field)))
            {
                throw new CompilationException("A class using the [ScriptObjectLiteral] attribute cannot inherit from class " + classDef.Symbol.GetFullName() +
                                               ", because it contains one or more declarations that are not compatible with object literal notations.", originalDecl);
            }

            if (classDef.BaseClass != null && classDef.BaseClass.Symbol.SpecialType != Roslyn.Compilers.SpecialType.System_Object)
            {
                ValidateBaseClass(originalDecl, classDef.BaseClass);
            }
        }