New Posts New Posts RSS Feed: Detect DomainModel Entities Type at runtime
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Detect DomainModel Entities Type at runtime

 Post Reply Post Reply
Author
dmaya View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Mar-2009
Location: Hostalets de Ba
Posts: 3
Post Options Post Options   Quote dmaya Quote  Post ReplyReply Direct Link To This Post Topic: Detect DomainModel Entities Type at runtime
    Posted: 26-Mar-2009 at 9:15am
Hello :

Is there any way to detect which are the Type's defined in a DomainModel at runtime?

Thank you

David
Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Posted: 27-Mar-2009 at 9:47am
The following code snippet shows how you can

(a) discover the types that inherit from Entity in a specific assembly or set of assemblies (I'm only searching one assembly, DomainModel, in this snippet); and
(b) discover the EntityProperties on each type.

You can try this out in the Program.cs of a Console project in any DevForce application.


    private void DoIt() {
      Type[] typesInModel = IdeaBlade.Util.v4.ReflectionFns.GetTypesImplementing(
        typeof(Entity), new string[] { "DomainModel" });
      foreach (Type aType in typesInModel) {
        Console.WriteLine(aType.Name);
        IdeaBlade.EntityModel.v4.EntityMetadata anEntityMetadata =
          IdeaBlade.EntityModel.v4.EntityMetadataStore.Instance.GetEntityMetadata(aType);
        foreach (EntityProperty anEntityProperty in anEntityMetadata.EntityProperties) {
          Console.WriteLine("    {0} [{1}]",
            anEntityProperty.Name,
            anEntityProperty.DataType.ToString());
        }

      }
      PromptToContinue();
    }

    void PromptToContinue() {
      Console.WriteLine("Press ENTER to continue...");
      Console.WriteLine();
      Console.ReadLine();
    }

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down