예제 #1
0
        private static Int32 Main(String[] args)
        {
            if (!args.Any())
            {
                var assemblyFileName = Path.GetFileName(
                    Assembly.GetEntryAssembly().Location
                    );

                Console.Error.WriteLine($"Usage: {assemblyFileName} outputDirectory");
                return(2);
            }

            try
            {
                var writer = new SourceFileWriter(args[0]);

                foreach (var command in ShellployMetadata.GetCommands())
                {
                    Console.WriteLine($"Generating {command.ClassName}...");
                    var targetUnit = new CommandCodeGenerator(command)
                                     .GenerateCompileUnit();
                    writer.Write(targetUnit);
                }

                Console.WriteLine("Done.");
                return(0);
            }
            catch (Exception exc)
            {
                Console.Error.WriteLine(exc);
                return(1);
            }
        }
예제 #2
0
        private static Int32 Main(String[] args)
        {
            if (!args.Any())
            {
                var assemblyFileName = Path.GetFileName(
                    Assembly.GetEntryAssembly().Location
                );

                Console.Error.WriteLine($"Usage: {assemblyFileName} outputDirectory");
                return 2;
            }

            try
            {
                var writer = new SourceFileWriter(args[0]);

                foreach (var command in ShellployMetadata.GetCommands())
                {
                    Console.WriteLine($"Generating {command.ClassName}...");
                    var targetUnit = new CommandCodeGenerator(command)
                        .GenerateCompileUnit();
                    writer.Write(targetUnit);
                }

                Console.WriteLine("Done.");
                return 0;
            }
            catch (Exception exc)
            {
                Console.Error.WriteLine(exc);
                return 1;
            }
        }
예제 #3
0
        public static Int32 Add(
            this CodeAttributeDeclarationCollection attributeCollection,
            Type attributeType,
            params Tuple <String, Object>[] parameters
            )
        {
            if (attributeType == null)
            {
                throw Logger.Fatal.ArgumentNull(nameof(attributeType));
            }

            return(attributeCollection.Add(
                       new CodeAttributeDeclaration(
                           new CodeTypeReference(attributeType),
                           parameters.Select(
                               tuple => new CodeAttributeArgument(tuple.Item1, CommandCodeGenerator.CreateLiteralExpression(tuple.Item2))
                               ).ToArray()
                           )
                       ));
        }
예제 #4
0
        public static void GenerateBackingField(
            this CodeMemberProperty property,
            CodeTypeDeclaration containingType,
            Object defaultValue
            )
        {
            if (containingType == null)
            {
                throw Logger.Fatal.ArgumentNull(nameof(containingType));
            }

            if (String.IsNullOrEmpty(property.Name))
            {
                throw Logger.Fatal.Argument(
                          nameof(property),
                          SR.CodeDomExtensions_PropertyNameNotSet
                          );
            }

            if (property.GetStatements.Any())
            {
                throw Logger.Fatal.Argument(
                          nameof(property),
                          SR.CodeDomExtensions_PropertyGetterNotEmpty
                          );
            }

            if (property.SetStatements.Any())
            {
                throw Logger.Fatal.Argument(
                          nameof(property),
                          SR.CodeDomExtensions_PropertySetterNotEmpty
                          );
            }

            var fieldName = "_" + ToCamelCase(property.Name);

            if (containingType.Members
                .Cast <CodeTypeMember>()
                .Any(member => member.Name == fieldName)
                )
            {
                throw Logger.Fatal.InvalidOperation(SR.CodeDomExtensions_FieldExists);
            }

            var isStatic = (property.Attributes & MemberAttributes.Static) == MemberAttributes.Static;

            var codeField = new CodeMemberField()
            {
                Name       = fieldName,
                Type       = property.Type,
                Attributes = MemberAttributes.Private | (isStatic ? MemberAttributes.Static : 0),
            };

            if (defaultValue != null)
            {
                codeField.InitExpression = CommandCodeGenerator.CreateLiteralExpression(defaultValue);
            }

            CreatePropertyGetterAndSetter(property, codeField.Name, CreateThisExpression(containingType, isStatic));

            containingType.Members.Add(codeField);
        }