Print Page | Close Window

Detect DomainModel Entities Type at runtime

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1171
Printed Date: 15-Mar-2025 at 12:37pm


Topic: Detect DomainModel Entities Type at runtime
Posted By: dmaya
Subject: Detect DomainModel Entities Type at runtime
Date 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



Replies:
Posted By: GregD
Date 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();
    }




Print Page | Close Window