Click here to Skip to main content
15,888,351 members
Home / Discussions / C#
   

C#

 
AnswerRe: Save Pin
Guffa2-Sep-07 6:52
Guffa2-Sep-07 6:52 
GeneralRe: Save Pin
Assaf822-Sep-07 7:17
Assaf822-Sep-07 7:17 
GeneralRe: Save Pin
Christian Graus2-Sep-07 7:25
protectorChristian Graus2-Sep-07 7:25 
GeneralRe: Save Pin
Guffa2-Sep-07 8:27
Guffa2-Sep-07 8:27 
GeneralRe: Save Pin
Assaf822-Sep-07 8:29
Assaf822-Sep-07 8:29 
GeneralRe: Save Pin
Christian Graus2-Sep-07 8:33
protectorChristian Graus2-Sep-07 8:33 
GeneralRe: Save Pin
Pete O'Hanlon2-Sep-07 9:54
mvePete O'Hanlon2-Sep-07 9:54 
Questioninvoking static method by type name Pin
AndrusM2-Sep-07 1:14
AndrusM2-Sep-07 1:14 
I know entity class name as string ( e.q. "Customer", "Product")
I need to invoke static method in this entity class.

I tried the following code but got compile error shown in comment.
How to invoke static method when type name is known as string ?



using System.Collections.Generic;<br />
using System;<br />
<br />
class TestApplication {<br />
<br />
static void Main() {<br />
FindByTypeName("Customer");<br />
FindByTypeName("Product");<br />
}<br />
<br />
static object[] FindByTypeName(string typename) {<br />
<br />
Type t = Type.GetType(typename);<br />
ActiveRecordBase<object> entity = (ActiveRecordBase<object>)<br />
System.Activator.CreateInstance(t);<br />
<br />
// Error: Static member 'ActiveRecordBase<object>.FindAll()' cannot be<br />
// accessed with an instance reference; qualify it with a type name<br />
//instead<br />
return entity.FindAll();<br />
<br />
}<br />
<br />
}<br />
<br />
class Customer : ActiveRecordBase<Customer> {}<br />
<br />
class Product : ActiveRecordBase<Product> {}<br />
<br />
public class ActiveRecordBase<T> {<br />
  public static T[] FindAll() {<br />
    // method implementation skipped<br />
   return null;<br />
   }<br />
} 



Andrus

AnswerRe: invoking static method by type name Pin
Scott Dorman2-Sep-07 3:09
professionalScott Dorman2-Sep-07 3:09 
GeneralRe: invoking static method by type name Pin
AndrusM2-Sep-07 4:49
AndrusM2-Sep-07 4:49 
GeneralRe: invoking static method by type name Pin
Christian Graus2-Sep-07 5:01
protectorChristian Graus2-Sep-07 5:01 
GeneralRe: invoking static method by type name Pin
AndrusM2-Sep-07 5:28
AndrusM2-Sep-07 5:28 
GeneralRe: invoking static method by type name Pin
Insincere Dave2-Sep-07 7:46
Insincere Dave2-Sep-07 7:46 
Questiondefault accessibility Pin
jon-802-Sep-07 1:11
professionaljon-802-Sep-07 1:11 
AnswerRe: default accessibility Pin
Ahmad Adnan2-Sep-07 3:04
Ahmad Adnan2-Sep-07 3:04 
AnswerRe: default accessibility [modified] Pin
Scott Dorman2-Sep-07 3:05
professionalScott Dorman2-Sep-07 3:05 
GeneralRe: default accessibility Pin
jon-802-Sep-07 4:21
professionaljon-802-Sep-07 4:21 
GeneralRe: default accessibility Pin
Steve Hansen2-Sep-07 7:28
Steve Hansen2-Sep-07 7:28 
GeneralRe: default accessibility Pin
Scott Dorman4-Sep-07 7:28
professionalScott Dorman4-Sep-07 7:28 
AnswerRe: default accessibility for classes can be internal Pin
Arjan Einbu2-Sep-07 4:13
Arjan Einbu2-Sep-07 4:13 
GeneralRe: default accessibility for classes can be internal Pin
jon-802-Sep-07 4:34
professionaljon-802-Sep-07 4:34 
Questionchange defualt priter page size Pin
hamid_m2-Sep-07 0:41
hamid_m2-Sep-07 0:41 
AnswerRe: change defualt priter page size Pin
Vasudevan Deepak Kumar2-Sep-07 0:47
Vasudevan Deepak Kumar2-Sep-07 0:47 
GeneralRe: change defualt priter page size Pin
hamid_m2-Sep-07 1:18
hamid_m2-Sep-07 1:18 
AnswerRe: change defualt priter page size Pin
Rupesh Kumar Swami2-Sep-07 1:06
Rupesh Kumar Swami2-Sep-07 1:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.