コード例 #1
0
        static void Main(string[] args)
        {
            ReflectionExample.ReflectionPrivateMethods();

            ReflectionExample.ReflectionMembers();

            var classRoom = new ClassRoom
            {
                Number = 1,
                Name   = "Классная комната",
                Owner  = "Иванов Иван Иванович"
            };

            SerializeExample.Serialize(classRoom, "classroom.json");

            var loadedClassRoom = SerializeExample.Deserialize <ClassRoom>("classroom.json");

            loadedClassRoom.PrintData();

            var assembly = Assembly.GetAssembly(typeof(_1.Classes.ClassRoom));

            Console.WriteLine(assembly?.GetName());

            var type = assembly?.GetTypes().FirstOrDefault(type => type.Name == "ClassRoom");

            var assemblyClassRoom = (ClassRoom)Activator.CreateInstance(type !);

            assemblyClassRoom?.PrintData();
        }
            public static void Example9_SetValue()
            {
                var reflectionExample     = new ReflectionExample();
                var reflectionExampleType = typeof(ReflectionExample);

                reflectionExampleType.GetField("privateField", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(reflectionExample, "My New Value");
                Console.WriteLine("Private Field Value: {0}", reflectionExample.PrivateField);
            }
            public static void Example10_GetMethod()
            {
                var reflectionExample     = new ReflectionExample();
                var reflectionExampleType = typeof(ReflectionExample);
                var methodInfo            = reflectionExampleType.GetMethod("Multiply");
                var returnValue           = (double)methodInfo.Invoke(reflectionExample, new object[] { 4, 5 });

                Console.WriteLine("Return Value: {0}", returnValue);
            }
                public bool GetPerson(int personId)
                {
                    //Open the connection to the database.
                    var cn = new SqlConnection("Server=(local);Database=Reflection;Trusted_Connection=True;");

                    cn.Open();
                    //Retrieve the record.
                    var cmd = new SqlCommand(string.Format("SELECT * FROM Person WHERE PersonId = {0}", personId), cn);
                    var dr  = cmd.ExecuteReader(CommandBehavior.CloseConnection);

                    return(ReflectionExample.LoadClassFromSQLDataReader(this, dr));
                }
            public static void Example11_GetMethod()
            {
                var reflectionExample     = new ReflectionExample();
                var reflectionExampleType = typeof(ReflectionExample);
                var returnValue           = (double)reflectionExampleType.InvokeMember("Multiply",
                                                                                       BindingFlags.InvokeMethod,
                                                                                       null,
                                                                                       reflectionExample,
                                                                                       new object[] { 4, 5 });

                Console.WriteLine(string.Format("Return Value: {0}", returnValue));
            }
            public static void Example8_GetFields()
            {
                var reflectionExample     = new ReflectionExample();
                var reflectionExampleType = typeof(ReflectionExample);
                var fields = reflectionExampleType.GetFields(BindingFlags.Public |
                                                             BindingFlags.Instance |
                                                             BindingFlags.Static |
                                                             BindingFlags.NonPublic |
                                                             BindingFlags.FlattenHierarchy);

                foreach (FieldInfo field in fields)
                {
                    var fieldValue = field.GetValue(reflectionExample);
                    Console.WriteLine("Field Name: {0}, Value: {1}", field.Name, fieldValue.ToString());
                }
            }
コード例 #7
0
ファイル: Form1.cs プロジェクト: mfwojciechowski/originToci
        private void button1_Click(object sender, System.EventArgs e)
        {
            DataTable result = dal.GetTranslationsFromTo("pl", textBox1.Text);
            //AddTranslationsLabels(result, "fromword","toword",20,62);
            // EfClassGenerator generator = new EfClassGenerator();

            //generator.GenerateCode();

            ReflectionExample re = new ReflectionExample();

            List <string> props = re.GetDataModelProperties();

            DataModel dm = new DataModel();

            re.SetPrivateField(dm, "dupa", "ToDaSieWypelnicRefleksja");

            re.RunGenericMethodByString(re, "SetPrivateField", new Type[] { typeof(DataModel), typeof(string) }, dm);
        }
コード例 #8
0
ファイル: ReflectionData.cs プロジェクト: bonahona/BonaJson
 public void ToMonoBehavior(ReflectionExample relfectionExample)
 {
     relfectionExample.CustomName = CustomName;
     relfectionExample.CustomIntArray = CustomIntArray;
 }
コード例 #9
0
ファイル: ReflectionData.cs プロジェクト: bonahona/BonaJson
 // These two methods are not neccesary for the packate to work but rather shows a way of moving data between the MonoBehaviours and the JSON classes.
 // The names of the fields in the two classes don't have to match. Both classes don't even have to have all fields. This is just for the sake of simplicity during this example.
 // In proper projects, it's always up to the application developer.
 public void FromMonoBehavior(ReflectionExample relfectionExample)
 {
     CustomName = relfectionExample.CustomName;
     CustomIntArray = relfectionExample.CustomIntArray;
 }
コード例 #10
0
        public void Test()
        {
            ReflectionExample reffff = new ReflectionExample();

            reffff.TestReflection();
        }
コード例 #11
0
 public static Func <Dictionary <string, object>, object> ReflectionGenerate() =>
 ReflectionExample.GenerateMethod(typeof(T));
コード例 #12
0
ファイル: ReflectionData.cs プロジェクト: bonahona/BonaJson
 public void ToMonoBehavior(ReflectionExample relfectionExample)
 {
     relfectionExample.CustomName     = CustomName;
     relfectionExample.CustomIntArray = CustomIntArray;
 }
コード例 #13
0
ファイル: ReflectionData.cs プロジェクト: bonahona/BonaJson
 // These two methods are not neccesary for the packate to work but rather shows a way of moving data between the MonoBehaviours and the JSON classes.
 // The names of the fields in the two classes don't have to match. Both classes don't even have to have all fields. This is just for the sake of simplicity during this example.
 // In proper projects, it's always up to the application developer.
 public void FromMonoBehavior(ReflectionExample relfectionExample)
 {
     CustomName     = relfectionExample.CustomName;
     CustomIntArray = relfectionExample.CustomIntArray;
 }