Ejemplo n.º 1
0
        protected override void DefineCompiledCode()
        {
            var methods = decorated.methods.custom;
            var fields  = decorated.variables.variables;

            for (int i = 0; i < fields.Count; i++)
            {
                var variable = decorated.variables.variables[i];
                var field    = FieldGenerator.Field(AccessModifier.Public, FieldModifier.None, variable.declaration.type, variable.name);
                field.Default(variable.declaration.defaultValue);
                @class.AddField(field);
            }

            for (int i = 0; i < methods.Count; i++)
            {
                var nest = decorated.methods.custom[i];
                if (CanAddMethod(nest))
                {
                    var controlData = new ControlGenerationData();
                    controlData.returns = nest.entry.declaration.type;
                    var body   = nest.entry.invoke.hasAnyConnection ? (nest.entry.invoke.connection.destination?.unit as Unit).GenerateControl(nest.entry.invoke.connection.destination, controlData, 0) : string.Empty;
                    var method = Method(nest.name, nest.entry.declaration.scope, nest.entry.declaration.modifier, nest.entry.declaration.type, body: body);
                    AddParameters(method, nest);
                    @class.AddMethod(method);
                }
            }

            var keys = decorated.methods.overrides.Keys().ToArray();

            for (int i = 0; i < keys.Length; i++)
            {
                var nest = decorated.methods.overrides.current[keys[i]];
                if (CanAddMethod(nest))
                {
                    var controlData = new ControlGenerationData();
                    controlData.returns = nest.entry.declaration.type;
                    var body = nest.entry.invoke.hasAnyConnection? (nest.entry.invoke.connection.destination?.unit as Unit).GenerateControl(nest.entry.invoke.connection.destination, controlData, 0) : string.Empty;

                    var method = nest.entry.declaration.type.Is().Void() ?
                                 Method(
                        nest.name.Replace(" ", string.Empty),
                        nest.entry.declaration.scope,
                        MustOverride(nest) ? MethodModifier.Override : nest.entry.declaration.modifier,
                        nest.entry.declaration.type,
                        body: body
                        )
                        : Method(
                        nest.name.Replace(" ", string.Empty),
                        nest.entry.declaration.scope,
                        MustOverride(nest) ? MethodModifier.Override : nest.entry.declaration.modifier,
                        nest.entry.declaration.type,
                        body: body
                        );
                    AddParameters(method, nest);
                    @class.AddMethod(method);
                }
            }
            ;
        }
Ejemplo n.º 2
0
        protected override void AfterLiveGeneration()
        {
            var uaClass          = FieldGenerator.Field(AccessModifier.Private, FieldModifier.None, typeof(UAClass), "data").CustomDefault("new UAClass(" + guid.As().Code(false) + ");");
            var interfaceUAClass = PropertyGenerator.Property(AccessModifier.Public, PropertyModifier.None, typeof(UAClass), "Class", false).SingleStatementGetter(AccessModifier.Public, "data");

            @class.AddField(uaClass);
            @class.AddProperty(interfaceUAClass);

            @namespace?.AddClass(@class);
            var usings = CodeBuilder.Using(@class.Usings()) + "\n\n";
            var output = (string.IsNullOrEmpty(decorated.@namespace) || string.IsNullOrWhiteSpace(decorated.@namespace)) ? usings + @class.Generate(0) : usings + @namespace.Generate(0);

            ClassExtensions.Save(guid, decorated, output);
        }