反射 屬性 介面的使用

2021-05-23 06:34:48 字數 2445 閱讀 4685

using system;

using system.collections.generic;

using system.linq;

using system.text;

namespace entitytosqlns

public inte***ce ientity

[attributeusage(attributetargets.class, allowmultiple = false, inherited = true)]

public class dtableattribute : attribute

}[attributeusage(attributetargets.property, allowmultiple = false, inherited = true)]

public class dfiledattribute : attribute

public type fieldtype

public bool key}}

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.reflection;

using entitytosqlns;

namespace sqlcreate

class program

}class getsql

return sql;

}string insertsql(ientity entity)

values = values.trimend(',');

return string.format("insert into values()", tablename, values);

}string selectsql(ientity entity)

values = values.trimend(',');

return string.format("select from ", values, tablename);

}string deletesql(ientity entity)

}return string.format("delete ", tablename, condition);

}string updatesql(ientity entity)

values = values.trimend(',');

return string.format("update set ", tablename, values);}}

class getsql

return sql;

}string insertsql(t entity)

values = values.trimend(',');

return string.format("insert into values()", tablename, values);

}string selectsql(t entity)

values = values.trimend(',');

return string.format("select from ", values, tablename);

}string deletesql(t entity)

}return string.format("delete ", tablename, condition);

}string updatesql(t entity)

values = values.trimend(',');

return string.format("update set ", tablename, values);}}

inte***ce ientity

[dtable(name = "stuusers")]

class user : ientity

[dfiled(name = "stunum", fieldtype = typeof(string), key = false)]

public string stunumber

[dfiled(name = "passwd", fieldtype = typeof(string), key = false)]

public string password

}[dtable(name = "announcement")]

class ann : ientity

[dfiled(name = "pubtitle", fieldtype = typeof(string), key = false)]

public string title

[dfiled(name = "pubcon", fieldtype = typeof(string), key = false)]

public string content}}

反射與介面的合併

做整合對接的介面比較多樣。介面設計者經常是定義乙個入口,要求呼叫者傳入actionname來進行導向。比如actionname為method1,便呼叫method1方法,並給出相應的返回資訊。我們自然可以寫死,去switch方法名,然後寫呼叫方法,但這種方式非常冗餘,且後續你得一直維護。這裡介紹反射...

通過反射呼叫介面的方法

之前使用公司的框架,業務使用到的一般就是action serviceimpl business模式,其中業務邏輯主要寫在businsess中,這個裡面有一段和常用但是一直不知道原理是什麼,就是下面這段 user user this.getdao getbean userdao.class selec...

介面的使用

由於c 類不能多重繼承。但現實有許多多重繼承的情況。為了避免傳統多重繼承帶來的複雜性問題和滿足多重繼承的需要,就提出了介面的概念。介面提出了一種規範,讓使用介面的程式設計人員要遵守其提出的約定。c 中申明介面時,使用關鍵字inte ce。using system using system.colle...