コード例 #1
0
ファイル: RoxyModelAssembler.cs プロジェクト: npolyak/NP.Roxy
        public static void AssembleSelectableRemovableBusinessGroup()
        {
            ITypeConfig typeConfig =
                Core.FindOrCreateTypeConfig <ISelectableRemovableBusinessGroup, ISelectableRemovableBusinessGroupWrapper>();

            typeConfig.SetInit <SingleSelectionObservableCollection <ISelectableRemovablePerson> >(nameof(IBusinessGroup.People));

            typeConfig.SetEventArgThisIdx(nameof(INotifyPropertyChanged.PropertyChanged), 0);

            typeConfig.SetThisMemberMap
            (
                nameof(ISelectableRemovableBusinessGroupWrapper.TheParentChildSelectionBehavior),
                nameof(ParentChildSelectionBehavior <ISelectableRemovableBusinessGroup, ISelectableRemovablePerson> .Parent)
            );

            typeConfig.SetMemberMap
            (
                nameof(ISelectableRemovableBusinessGroupWrapper.TheParentChildSelectionBehavior),
                nameof(ParentChildSelectionBehavior <ISelectableRemovableBusinessGroup, ISelectableRemovablePerson> .Children),
                nameof(IBusinessGroup.People)
            );

            typeConfig.SetMemberMap
            (
                nameof(ISelectableRemovableBusinessGroupWrapper.TheRemovableCollectionBehavior),
                nameof(RemovableCollectionBehavior.TheCollection),
                nameof(IBusinessGroup.People)
            );

            typeConfig.ConfigurationCompleted();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            ITypeConfig typeConfig =
                Core.FindOrCreateTypeConfig <IMyInterface, WrapperInterface>("MyGeneratedClass");

            typeConfig.SetMemberMap(nameof(WrapperInterface.TheClass), nameof(MyClass.MyInt), nameof(IMyInterface.TheInt));
            typeConfig.SetMemberMap(nameof(WrapperInterface.TheClass), nameof(MyClass.MyStr), nameof(IMyInterface.TheStr));

            typeConfig.ConfigurationCompleted();

            IMyInterface myInterfaceObj = Core.GetInstanceOfGeneratedType <IMyInterface>(typeConfig.ClassName);

            myInterfaceObj.TheInt = 1234;
            myInterfaceObj.TheStr = "Hello";
            myInterfaceObj.MyMethod("blabla", 123);
        }
コード例 #3
0
        static void Main(string[] args)
        {
            #region WRAPPED CLASS CONCRETIZATION WITH INHERITANCE FROM ABSTRACT CLASS
            ITypeConfig <IMyData, NoClass, WrapperInterface> typeConfig =
                Core.FindOrCreateTypeConfig <IMyData, NoClass, WrapperInterface>("MyType");

            typeConfig.SetMemberMap
            (
                nameof(WrapperInterface.TheClass),
                "TheLastName",
                nameof(IMyData.LastName),
                true
            );

            typeConfig.SetPropMapAllowNonPublic(nameof(WrapperInterface.TheClass), nameof(IMyData.GetFullName));

            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
        }
コード例 #4
0
        public static void RunTest()
        {
            #region WRAPPED CLASS CONCRETIZATION WITH INHERITANCE FROM ABSTRACT CLASS
            Core.SetSaveOnErrorPath("GeneratedCode");
            ITypeConfig typeConfig =
                Core.FindOrCreateTypeConfig <IMyData, Implementor>("MyType10");

            typeConfig.SetMemberMap
            (
                nameof(Implementor.TheClass),
                "TheLastName",
                nameof(IMyData.LastName),
                true
            );

            typeConfig.SetMemberMapAllowNonPublic(nameof(Implementor.TheClass), nameof(IMyData.GetFullName));

            typeConfig.ConfigurationCompleted();

            IMyData myData = typeConfig.CreateInstanceOfType <IMyData>();
            myData.FirstName = "Joe";
            myData.LastName  = "Doe";

            Assert.Equal("Joe Doe", myData.GetFullName());
            Core.Save("GeneratedCode");
            #endregion WRAPPED CLASS CONCRETIZATION WITH INHERITANCE FROM ABSTRACT CLASS
        }
コード例 #5
0
        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");
        }
コード例 #6
0
        public static void RunTest()
        {
            Core.SetSaveOnErrorPath("GeneratedCode");

            ITypeConfig typeConfig =
                Core.FindOrCreateTypeConfig <IMyInterface, WrapperInterface>("MyGeneratedClass1");

            typeConfig.SetMemberMap(nameof(WrapperInterface.TheClass), nameof(MyClass.MyInt), nameof(IMyInterface.TheInt));
            typeConfig.SetMemberMap(nameof(WrapperInterface.TheClass), nameof(MyClass.MyStr), nameof(IMyInterface.TheStr));

            typeConfig.ConfigurationCompleted();

            Core.Save("GeneratedCode");

            IMyInterface myInterfaceObj = typeConfig.CreateInstanceOfType <IMyInterface>();

            myInterfaceObj.TheInt = 1234;
            myInterfaceObj.TheStr = "Hello";
            string str = myInterfaceObj.GetResultingStr("blabla", 123);

            Assert.Equal("The resulting string is: blabla_1234", str);
        }
コード例 #7
0
        public static void RunTest()
        {
            Core.SetSaveOnErrorPath("GeneratedCode");
            ITypeConfig typeConfig =
                Core.FindOrCreateTypeConfig <IMyInterface, WrapperInterface>("MyGeneratedClass3");

            typeConfig.SetMemberMap(nameof(WrapperInterface.TheClass), nameof(MyClass.MyInt), nameof(IMyInterface.TheInt));

            //typeConfig.SetPropBuilder(DelegatePropBuilder.TheDelegatePropBuilder, nameof(IMyInterface.TheStr));

            typeConfig.ConfigurationCompleted();

            IMyInterface myObj = typeConfig.CreateInstanceOfType <IMyInterface>();

            myObj.TheInt = 123;

            Core.Save("GeneratedCode");

            Assert.Equal("The resulting string is: blabla_123", myObj.GetResultingStr("blabla", 123));
        }