A
Andrus
I need to associate text used in messages with every DLinq entity type.
I need to retrive this text from entity name.
I tried to solve this by creating public static readonly property Text in
every entity and
use EntityManager.GetText() method.
Is this best way or is there any better idea ?
The code below causes compile time erorr shown in comment. How to fix this ?
Andrus.
using System;
using System.Reflection;
class Test {
static void Main() {
// must output: This is customer type
Console.WriteLine(EntityManager.GetText("CustomerBaseClass"));
// must output: This is some supplier entity
Console.WriteLine(EntityManager.GetText("SomeSupplierClass"));
}
}
static class EntityManager {
public static string GetText(string name) {
// error: Cannot convert type 'System.Reflection.PropertyInfo' to
'string' via a reference conversion, boxing
// conversion, unboxing conversion, wrapping conversion, or null type
conversion
return
(Assembly.GetExecutingAssembly().GetType(name).GetProperty("Text")) as
string ;
}
}
class EntityBase { }
class CustomerBaseClass : EntityBase {
public static readonly string Text = "This is customer type";
}
class SomeSupplierClass : EntityBase {
public static readonly string Text = "This is some supplier entity";
}
I need to retrive this text from entity name.
I tried to solve this by creating public static readonly property Text in
every entity and
use EntityManager.GetText() method.
Is this best way or is there any better idea ?
The code below causes compile time erorr shown in comment. How to fix this ?
Andrus.
using System;
using System.Reflection;
class Test {
static void Main() {
// must output: This is customer type
Console.WriteLine(EntityManager.GetText("CustomerBaseClass"));
// must output: This is some supplier entity
Console.WriteLine(EntityManager.GetText("SomeSupplierClass"));
}
}
static class EntityManager {
public static string GetText(string name) {
// error: Cannot convert type 'System.Reflection.PropertyInfo' to
'string' via a reference conversion, boxing
// conversion, unboxing conversion, wrapping conversion, or null type
conversion
return
(Assembly.GetExecutingAssembly().GetType(name).GetProperty("Text")) as
string ;
}
}
class EntityBase { }
class CustomerBaseClass : EntityBase {
public static readonly string Text = "This is customer type";
}
class SomeSupplierClass : EntityBase {
public static readonly string Text = "This is some supplier entity";
}