コード例 #1
0
        public void SetValue(string systemvar, params object[] values)
        {
            foreach (PropertyInfo p in this.GetType().GetProperties())
            {
                CadSystemVariableAttribute att = p.GetCustomAttribute <CadSystemVariableAttribute>();
                if (att == null || att.Name != systemvar)
                {
                    continue;
                }

                object          build  = null;
                ConstructorInfo constr = p.PropertyType.GetConstructor(values.Select(o => o.GetType()).ToArray());

                if (p.PropertyType.IsEnum)
                {
                    build = Enum.ToObject(p.PropertyType, values.First());
                }
                else if (constr == null)
                {
                    build = Convert.ChangeType(values.First(), p.PropertyType);
                }
                else
                {
                    build = Activator.CreateInstance(p.PropertyType, values);
                }

                //Set the value if it has any
                if (build != null)
                {
                    p.SetValue(this, build);
                    break;
                }
            }
        }
コード例 #2
0
        public static Dictionary <string, DxfCode[]> GetHeaderMap()
        {
            Dictionary <string, DxfCode[]> map = new Dictionary <string, DxfCode[]>();

            foreach (PropertyInfo p in typeof(CadHeader).GetProperties())
            {
                CadSystemVariableAttribute att = p.GetCustomAttribute <CadSystemVariableAttribute>();
                if (att == null)
                {
                    continue;
                }

                map.Add(att.Name, att.ValueCodes);
            }

            return(map);
        }
コード例 #3
0
ファイル: CadHeader.cs プロジェクト: lanicon/ACadSharp
        public void SetValue(string systemvar, object value)
        {
            foreach (PropertyInfo p in GetType().GetProperties())
            {
                CadSystemVariableAttribute att = p.GetCustomAttribute <CadSystemVariableAttribute>();
                if (att == null)
                {
                    continue;
                }

                if ($"${att.Name}" == systemvar)
                {
                    p.SetValue(this, value);
                    break;
                }
            }
        }
コード例 #4
0
        public object GetValue(string systemvar)
        {
            object value = null;

            foreach (PropertyInfo p in this.GetType().GetProperties())
            {
                CadSystemVariableAttribute att = p.GetCustomAttribute <CadSystemVariableAttribute>();
                if (att == null)
                {
                    continue;
                }

                if (att.Name == systemvar)
                {
                    value = p.GetValue(this);
                    break;
                }
            }

            return(value);
        }