コード例 #1
0
ファイル: GlobalProjectProperties.cs プロジェクト: kzu/clide
		public GlobalProjectProperties(ProjectNode project)
		{
			msBuildProject = project.As<Project>();
			dteProject = project.As<EnvDTE.Project>();
			vsBuild = project.HierarchyNode.HierarchyIdentity.Hierarchy as IVsBuildPropertyStorage;
			accessor = new DynamicPropertyAccessor(this);
		}
コード例 #2
0
ファイル: ConfigProjectProperties.cs プロジェクト: kzu/clide
		public ConfigProjectProperties(ProjectNode project, string configName)
		{
			this.project = project;
			this.configName = configName;
			vsBuild = project.HierarchyNode.HierarchyIdentity.Hierarchy as IVsBuildPropertyStorage;
			if (vsBuild == null)
				tracer.Warn(Strings.ConfigProjectProperties.NonMsBuildProject(project.Text));

			accessor = new DynamicPropertyAccessor(this);
		}
コード例 #3
0
ファイル: UserProjectProperties.cs プロジェクト: kzu/clide
		public UserProjectProperties(ProjectNode project)
		{
			this.project = project;
			msBuildProject = project.As<Project>();
			dteProject = project.As<EnvDTE.Project>();
			vsBuild = project.HierarchyNode.HierarchyIdentity.Hierarchy as IVsBuildPropertyStorage;

			if (msBuildProject == null || vsBuild == null)
				tracer.Warn(Strings.UserProjectProperties.NonMsBuildProject(project.Text));

			accessor = new DynamicPropertyAccessor(this);
		}
コード例 #4
0
        public void SetValueTest()
        {
            int expected = 100;

            var t = new Temp {
                Value = null
            };

            PropertyInfo propertyInfo = t.GetType().GetProperty("Value");
            Stopwatch    watch1       = new Stopwatch();

            watch1.Start();
            for (var i = 0; i < 1000000; i++)
            {
                propertyInfo.SetValue(t, expected, null);
            }
            watch1.Stop();
            Trace.WriteLine("Reflection: " + watch1.Elapsed);

            Assert.AreEqual(expected, t.Value.Value);

            t.Value = 555;

            DynamicPropertyAccessor property = new DynamicPropertyAccessor(t.GetType(), "Value");
            Stopwatch watch2 = new Stopwatch();

            watch2.Start();
            for (var i = 0; i < 1000000; i++)
            {
                property.SetValue(t, expected);
            }
            watch2.Stop();
            Trace.WriteLine("Lambda: " + watch2.Elapsed);

            Assert.AreEqual(expected, t.Value.Value);

            t.Value = 555;

            Stopwatch watch3 = new Stopwatch();

            watch3.Start();
            for (var i = 0; i < 1000000; i++)
            {
                t.Value = expected;
            }
            watch3.Stop();
            Trace.WriteLine("Direct: " + watch3.Elapsed);

            Assert.AreEqual(expected, t.Value.Value);
        }
コード例 #5
0
        public void GetValueTest()
        {
            var t = new Temp {
                Value = null
            };

            PropertyInfo propertyInfo = t.GetType().GetProperty("Value");
            Stopwatch    watch1       = new Stopwatch();

            watch1.Start();
            for (var i = 0; i < 1000000; i++)
            {
                var value = propertyInfo.GetValue(t, null);
            }
            watch1.Stop();
            Trace.WriteLine("Reflection: " + watch1.Elapsed);

            DynamicPropertyAccessor property = new DynamicPropertyAccessor(t.GetType(), "Value");
            Stopwatch watch2 = new Stopwatch();

            watch2.Start();
            for (var i = 0; i < 1000000; i++)
            {
                var value = property.GetValue(t);
            }
            watch2.Stop();
            Trace.WriteLine("Lambda: " + watch2.Elapsed);

            Stopwatch watch3 = new Stopwatch();

            watch3.Start();
            for (var i = 0; i < 1000000; i++)
            {
                var value = t.Value;
            }
            watch3.Stop();
            Trace.WriteLine("Direct: " + watch3.Elapsed);
        }
コード例 #6
0
ファイル: FastEval.cs プロジェクト: zicjin/sharp_net
        public DynamicPropertyAccessor GetAccessor(Type type, string propertyName)
        {
            DynamicPropertyAccessor accessor;
            Dictionary<string, DynamicPropertyAccessor> typeCache;

            if (this.m_cache.TryGetValue(type, out typeCache)) {
                if (typeCache.TryGetValue(propertyName, out accessor)) {
                    return accessor;
                }
            }

            lock (m_mutex) {
                if (!this.m_cache.ContainsKey(type)) {
                    this.m_cache[type] = new Dictionary<string, DynamicPropertyAccessor>();
                }

                accessor = new DynamicPropertyAccessor(type, propertyName);
                this.m_cache[type][propertyName] = accessor;

                return accessor;
            }
        }
コード例 #7
0
        void SetPropertyInfo(object info, out PropertyInfo pi, out PropertyDescriptor pd, out DependencyProperty dp, out DynamicPropertyAccessor dpa)
        {
            pi = null;
            pd = null;
            dpa = null;
            dp = info as DependencyProperty;

            if (dp == null)
            {
                pi = info as PropertyInfo;
                if (pi == null)
                {
                    pd = info as PropertyDescriptor;

                    if (pd == null)
                        dpa = info as DynamicPropertyAccessor;
                }
            }
        }