public static void RunTest() { #region WRAPPED CLASS CONCRETIZATION WITH INHERITANCE FROM ABSTRACT CLASS ITypeConfig typeConfig = Core.FindOrCreateTypeConfig <IMyData, WrapperInterface>("MyType5"); typeConfig.AddStaticUtilsClass ( nameof(StaticMethodsTests.WrapperInterface.TheClass), typeof(MyDataUtils) ); typeConfig.SetAllowNonPublicForAllMembers(nameof(WrapperInterface.TheClass)); //typeConfig.SetPropMap //( // nameof(WrapperInterface.TheClass), // "GetTheFullName", // nameof(IMyData.GetFullName), // true); typeConfig.ConfigurationCompleted(); IMyData myData = Core.GetInstanceOfGeneratedType <IMyData>("MyType5"); myData.FirstName = "Joe"; myData.LastName = "Doe"; Assert.Equal("Joe Doe", myData.GetFullName()); #endregion WRAPPED CLASS CONCRETIZATION WITH INHERITANCE FROM ABSTRACT CLASS }
static void Main(string[] args) { #region WRAPPED CLASS CONCRETIZATION WITH INHERITANCE FROM ABSTRACT CLASS ITypeConfig <IMyData, NoClass, WrapperInterface> typeConfig = Core.FindOrCreateTypeConfig <IMyData, WrapperInterface>("MyType"); typeConfig.AddStaticUtilsClass ( nameof(WrapperInterface.TheClass), typeof(MyDataUtils) ); typeConfig.SetAllowNonPublicForAllMembers(nameof(WrapperInterface.TheClass)); //typeConfig.SetPropMap //( // nameof(WrapperInterface.TheClass), // "GetTheFullName", // nameof(IMyData.GetFullName), // true); typeConfig.ConfigurationCompleted(); IMyData myData = Core.GetInstanceOfGeneratedType <IMyData>("MyType"); myData.FirstName = "Joe"; myData.LastName = "Doe"; Console.WriteLine(myData.GetFullName()); #endregion WRAPPED CLASS CONCRETIZATION WITH INHERITANCE FROM ABSTRACT CLASS }
static void Main(string[] args) { Core.SetSaveOnErrorPath("GeneratedCode"); #region create the generated type configuration object // get the type configuration object. The class that it is going to generate // will be called "MyPersonImplementation" ITypeConfig typeConfig = Core.FindOrCreateTypeConfig <IPerson, PersonImplementationWrapperInterface>("MyPersonImplementation"); // allow access to non-public members of // PersonImplementationWrapperInterface.ThePersonImplementation object. typeConfig.SetAllowNonPublicForAllMembers ( nameof(PersonImplementationWrapperInterface.ThePersonImplementation) ); // map TheProfession property of the wrapped object // into Profession property of the IPerson interface. typeConfig.SetMemberMap ( nameof(PersonImplementationWrapperInterface.ThePersonImplementation), "TheProfession", nameof(IPerson.Profession) ); // Signal that the configuration is completed, // after ConfigurationCompleted() method is called // TypeConfig object for this class cannot be modified. typeConfig.ConfigurationCompleted(); #endregion create the generated type configuration object // get the instance of the generated type "MyPersonImplementation" IPerson person = Core.GetInstanceOfGeneratedType <IPerson>("MyPersonImplementation"); //IPerson person = Core.CreateWrapperWithNonPublicMembers<IPerson, PersonImplementationWrapperInterface>("MyPersonImplementation"); // set the properties person.FirstName = "Joe"; person.LastName = "Doe"; person.Age = 35; person.Profession = "Astronaut"; // test that the wrapped properties and the method work Console.WriteLine($"Name/Profession='{person.GetFullNameAndProfession()}'; Age='{person.Age}'"); Core.Save("GeneratedCode"); }
public TypeToImplement WrapWithNonPublicMembers <TypeToImplement, TWrapper>(string className) { ITypeConfig typeConfig = FindTypeConfig <TypeToImplement, TWrapper>(className); if (typeConfig == null) { typeConfig = this.CreateTypeConf <TypeToImplement, TWrapper>(className); } typeConfig.SetAllowNonPublicForAllMembers(); typeConfig.ConfigurationCompleted(); if (typeConfig.TheGeneratedType == null) { RegenerateAssembly(); } return(GetInstanceOfType <TypeToImplement>(typeConfig)); }
public ITypeConfig FindOrCreateEnumWrapperTypeConfig <T, EnumType>(Type staticEnumExtensionsType, bool allowNonPublic) { string className = typeof(EnumType).GetTypeAdapterClassName(typeof(T)); ITypeConfig enumWrapperTypeConfig = this.FindOrCreateTypeConfByTypeToImpl <T, SingleWrapperInterface <EnumType> >(className); if (!enumWrapperTypeConfig.ConfigurationHasBeenCompleted) { enumWrapperTypeConfig.AddStaticUtilsClass ( nameof(SingleWrapperInterface <EnumType> .TheWrappedType), staticEnumExtensionsType ); if (allowNonPublic) { enumWrapperTypeConfig.SetAllowNonPublicForAllMembers(); } } return(enumWrapperTypeConfig); }