标签: code-generation

免费的NHibernate助手工具?

是否有任何免费工具可帮助简化在.NET 3.5中使用NHibernate项目的工作?首先,我正在寻找某种代码和配置文件生成器来自动化使用NHibernate的一些更繁琐的部分.

.net nhibernate code-generation .net-3.5

12
推荐指数
1
解决办法
9450
查看次数

在PHP和JavaScript之间共享常量

可能重复:
将PHP字符串传递给Javascript变量(并转义换行符)

我正在开发的PHP应用程序中有几个常量.我已经定义了一个Constants类,并将常量定义为const VAR_NAME = value; 在这堂课上.我想在JavaScript和PHP代码之间共享这些常量.是否有干(不要重复自己)机制来分享它们?

class Constants {
    const RESOURCE_TYPE_REGSITER = 2;
    const RESOURCE_TYPE_INFO = 1;
}
Run Code Online (Sandbox Code Playgroud)

javascript php code-generation dry

12
推荐指数
1
解决办法
6742
查看次数

避免gcc功能序幕开销?

我最近遇到了很多函数,其中gcc在x86上生成了非常糟糕的代码.他们都符合以下模式:

if (some_condition) {
    /* do something really simple and return */
} else {
    /* something complex that needs lots of registers */
}
Run Code Online (Sandbox Code Playgroud)

将简单的情况看作是一个非常小的东西,一半或更多的工作花在推动和弹出不会被修改的寄存器上.如果我手动编写asm,我会在复杂的情况下保存并恢复已保存的跨调用寄存器,并且在简单的情况下完全避免触及堆栈指针.

有没有什么方法可以让gcc变得更聪明并且自己做到这一点?最好使用命令行选项,而不是源代码中的丑陋黑客...

编辑:为了使它具体化,这里有一些非常接近我正在处理的一些函数:

if (buf->pos < buf->end) {
    return *buf->pos++;
} else {
    /* fill buffer */
}
Run Code Online (Sandbox Code Playgroud)

另一个:

if (!initialized) {
    /* complex initialization procedure */
}
return &initialized_object;
Run Code Online (Sandbox Code Playgroud)

另一个:

if (mutex->type == SIMPLE) {
    return atomic_swap(&mutex->lock, 1);
} else {
    /* deal with ownership, etc. */
}
Run Code Online (Sandbox Code Playgroud)

编辑2:我应该首先提到:这些函数不能内联.他们有外部联系,他们是图书馆代码.允许它们在应用程序中内联将导致各种问题.

c x86 gcc code-generation

12
推荐指数
1
解决办法
2157
查看次数

Delphi 2010 - 属性向导或类似的东西,以避免手动编码getter/setter

是否有内置或外部工具(向导)可以轻松添加具有getter/setter的类成员(已发布字段)?

添加每个字段需要我编写很多代码.我们假设我需要添加Foo: Bar;属性.

我需要写

FFoo: TBar;
procedure SetFoo(const AValue: TBar);
function GetFoo: TBar;

...

property Foo: TBar read GetFoo write SetFoo
Run Code Online (Sandbox Code Playgroud)

任何使它快速简便的工具?

delphi code-generation delphi-2010

12
推荐指数
3
解决办法
693
查看次数

T4将输出附加到现有文件

是否可以将T4模板输出与现有文件合并?

例如,如果T4模板生成本地化资源XML文件,是否可以将它们合并到一些现有资源文件中?

.net t4 code-generation t4-toolbox

12
推荐指数
1
解决办法
2224
查看次数

如何在Android应用程序中获取ISO国家代码?

我是android应用程序的新开发人员.当我通过国家代码传递手机号码时,我想获得ISO国家代码.如果我将手机号码传递给1-319-491-6338,我可以在Android中获得美国/美国的国家ISO代码吗?

我编写的代码如下:

      TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
      String countryCode = tm.getSimCountryIso();
      String mobileno="1-319-491-6338";
Run Code Online (Sandbox Code Playgroud)

在这里,我可以在哪里通过手机号码?

有人可以帮帮我吗?

提前致谢

country mobile android code-generation

12
推荐指数
1
解决办法
2万
查看次数

使用Roslyn将自定义属性添加到C#类

考虑文件"MyClass.cs"中的以下类

using System;

public class MyClass : Entity<long>
{
    public long Id
    {
        get;
        set;
    }

    [Required]
    public string Name
    {
        get;
        set;
    }

    public string Slug
    {
        get;
        set;
    }

    public DateTime CreatedOn
    {
        get;
        private set;
    }

    public DateTime UpdatedOn
    {
        get;
        private set;
    }

    /* ... */
}
Run Code Online (Sandbox Code Playgroud)

目前我手动创建数据合同类,如下所示:

[DataContract(Namespace = "http://example.com/", Name = "MyClass")]
public sealed class MyClass
{
    [DataMember(EmitDefaultValue = false, Name = "Id")]
    public long Id
    {
        get;
        set;
    }

    [DataMember(EmitDefaultValue = false, Name …
Run Code Online (Sandbox Code Playgroud)

c# code-generation roslyn

12
推荐指数
1
解决办法
5738
查看次数

生成C#代码时,XSD工具将"Specified"附加到某些属性/字段

我对XSD生成器有一种奇怪的行为,我无法解释.我得到了这样的XSD:

<xs:complexType name="StageSequenceElement" mixed="false">
    <xs:complexContent>
        <xs:extension base="CoreObject">
            <xs:sequence>
                <xs:element name="Description" type="xs:string" minOccurs="0">
                    <xs:annotation>
                        <xs:documentation>Some Doc</xs:documentation>
                    </xs:annotation>
                </xs:element>
                <xs:element name="StageRef" type="ObjectReference">
                    <xs:annotation>
                        <xs:documentation>...</xs:documentation>
                    </xs:annotation>
                </xs:element>
                <xs:element name="MinDuration_100ms" type="xs:int" nillable="true" minOccurs="0">
                    <xs:annotation>
                        <xs:documentation>...</xs:documentation>
                    </xs:annotation>
                </xs:element>
                <xs:element name="MaxDuration_100ms" type="xs:int" nillable="true">
                    <xs:annotation>
                        <xs:documentation>...</xs:documentation>
                    </xs:annotation>
                </xs:element>
                <xs:element name="StageOnDemand" type="xs:boolean" nillable="true" minOccurs="0">
                    <xs:annotation>
                        <xs:documentation>...</xs:documentation>
                    </xs:annotation>
                </xs:element>
            </xs:sequence>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>
Run Code Online (Sandbox Code Playgroud)

它源自CoreObject:

<xs:complexType name="CoreObject">
    <xs:sequence>
        <xs:element name="No" type="xs:int">
            <xs:annotation>
                <xs:documentation>...</xs:documentation>
            </xs:annotation>
        </xs:element>
    </xs:sequence>
</xs:complexType>
Run Code Online (Sandbox Code Playgroud)

这只是XSD的一小部分,还有更复杂的类型.

因此,当我生成类似于此的类时,我得到一个生成的类,它有两个属性(除了我期望的5):

public bool MinDuration_100msSpecified
Run Code Online (Sandbox Code Playgroud)

和

public bool StageOnDemandSpecified
Run Code Online (Sandbox Code Playgroud)

所以对于"原始"属性,附加了"Specified",类型现在是bool.任何人都可以解释为什么会这样吗?

c# code-generation xsd.exe

12
推荐指数
1
解决办法
6098
查看次数

使git跟踪自动生成的文件但忽略diff

我有源代码(大部分的存储库*.php,*.js)和文档文件(主要是*.md,*.html,*.svg)自动从注释生成.所有文档都位于./doc存储库中的单独子目录()中.

一方面,我希望通过跟踪文档,git如果它发生变化,我希望它被提交/推送到服务器,因为它有一个很好的可浏览和最新文档很不方便由github显示.

另一方面,在输出git diff命令期间看到自动生成的文件是非常烦人的.例如,如果在两次提交之间更改了一行源代码,则git diff不仅会输出此单行,而且还会输出所有自动生成的文档,因为整个自动生成的文档已更改.

有没有办法告诉git跟踪文档但diff默认情况下将其排除?如果git将所有文档文件视为blob,我也会对我好.然后,至少diff只会声称文件已更改,但不会显示所有文档行每行.

git code-generation auto-generate gitignore

12
推荐指数
2
解决办法
2258
查看次数

从string和int创建哈希

我记得eclipse和idea有这个模板根据其属性自动创建一个对象的hashCode.

如果使用数字和字符串,其中一种策略是这样的.

  return stringValue.hashCode() + intValue * 32;
Run Code Online (Sandbox Code Playgroud)

这样的东西.

我手头没有也没有eclipse或想法,我想创建这样的功能.

编辑

根据答案,我创建了这个迷你课程

    class StringInt {
        private final String s;
        private final int i;

        static StringInt valueOf( String string , int value ) {
            return new StringInt( string, value );
        }
        private StringInt( String string, int value ) {
            this.s = string;
            this.i = value;
        }
        public boolean equals( Object o ) {
            if( o != null && o instanceof StringInt ){
                StringInt other = ( StringInt ) o;
                return this.s …
Run Code Online (Sandbox Code Playgroud)

java eclipse hash code-generation intellij-idea

11
推荐指数
1
解决办法
2万
查看次数