public static CustomPropertyInfo GetFromParamInfo(System.Reflection.ParameterInfo info)
        {
            if (info == null)
            {
                return(null);
            }

            CustomPropertyInfo retInfo = new CustomPropertyInfo();

            retInfo.PropertyName = info.Name;
            if (info.IsOut || info.ParameterType.IsByRef)
            {
                retInfo.PropertyType = EngineNS.Rtti.RttiHelper.GetTypeFromTypeFullName(info.ParameterType.FullName.Remove(info.ParameterType.FullName.Length - 1));
            }
            else
            {
                //retInfo.PropertyType = CSUtility.Program.GetTypeFromTypeFullName(info.ParameterType.FullName);
                retInfo.PropertyType = info.ParameterType;
            }

            foreach (var att in info.GetCustomAttributes(true))
            {
                retInfo.PropertyAttributes.Add(att as Attribute);
            }
            retInfo.DefaultValue = CodeGenerateSystem.Program.GetDefaultValueFromType(retInfo.PropertyType);
            retInfo.CurrentValue = retInfo.DefaultValue;
            return(retInfo);
        }
        public static bool IsPropertyInfoValid(CustomPropertyInfo proInfo)
        {
            if (proInfo == null || proInfo.PropertyType == null)
            {
                return(false);
            }
            if (proInfo.PropertyType.IsGenericParameter || proInfo.PropertyType.IsGenericType || proInfo.PropertyType.IsInterface)
            {
                return(false);
            }

            if (EngineNS.Rtti.AttributeHelper.GetCustomAttribute(proInfo.PropertyType, typeof(EngineNS.Editor.Editor_LinkSystemCustomClassPropertyEnableShowAttribute).FullName, false) == null)
            {
                if (proInfo.PropertyType != typeof(string) && proInfo.PropertyType != typeof(System.Type) && proInfo.PropertyType.IsClass)
                {
                    return(false);
                }
            }
            return(true);
        }
        public static CodeGenerateSystem.Base.GeneratorClassBase CreateClassInstanceFromCustomPropertys(List <CustomPropertyInfo> propertys, BaseNodeControl node, string className = null, bool needNameProperty = true)
        {
            var cpPros = new List <CustomPropertyInfo>(propertys);

            // name属性Metadata不存
            if (needNameProperty)
            {
                var nameCPInfo = CustomPropertyInfo.GetFromParamInfo(typeof(string), "Name", new Attribute[] { new CategoryAttribute("Common") });
                cpPros.Add(nameCPInfo);
            }
            var nodeType = node.GetType();

            if (string.IsNullOrEmpty(className))
            {
                className = nodeType.FullName + "_" + EngineNS.Editor.Assist.GetValuedGUIDString(node.Id) + ".PropertyClass";
            }

            var classType     = CodeGenerateSystem.Base.PropertyClassGenerator.CreateTypeFromCustomPropertys(cpPros, nodeType.Assembly.GetName().Name + "DynamicAssembly", className);
            var classInstance = System.Activator.CreateInstance(classType) as CodeGenerateSystem.Base.GeneratorClassBase;
            var field         = classType.GetField("HostNode");

            if (field != null)
            {
                field.SetValue(classInstance, node);
            }
            if (needNameProperty)
            {
                var namePro = classType.GetProperty("Name");
                if (namePro != null)
                {
                    namePro.SetValue(classInstance, node.NodeName);
                    node.SetNameBinding(classInstance, "Name");
                    //node.SetBinding(BaseNodeControl.NodeNameBinderProperty, new Binding("Name") { Source = classInstance, Mode = BindingMode.TwoWay });
                }
            }
            classInstance.CSType = node.CSParam.CSType;

            return(classInstance);
        }
        public static CustomPropertyInfo GetFromParamInfo(Type paramType, string paramName, Attribute[] attributes = null)
        {
            if (paramType == null || string.IsNullOrEmpty(paramName))
            {
                return(null);
            }

            CustomPropertyInfo retInfo = new CustomPropertyInfo();

            retInfo.PropertyName = paramName;
            retInfo.PropertyType = paramType;

            if (attributes != null)
            {
                foreach (var att in attributes)
                {
                    retInfo.PropertyAttributes.Add(att);
                }
            }
            retInfo.DefaultValue = CodeGenerateSystem.Program.GetDefaultValueFromType(retInfo.PropertyType);
            retInfo.CurrentValue = retInfo.DefaultValue;
            return(retInfo);
        }
Exemplo n.º 5
0
        void CreateTemplateClass_Show()
        {
            var allType = mTemplateClassInstance_All.GetType();

            if (mTemplateClassInstance_Show != null)
            {
                foreach (var pro in mTemplateClassInstance_Show.GetType().GetProperties())
                {
                    var allPro = allType.GetProperty(pro.Name);
                    allPro.SetValue(mTemplateClassInstance_All, pro.GetValue(mTemplateClassInstance_Show));
                }
            }

            var cpInfos_Show = new List <CodeGenerateSystem.Base.CustomPropertyInfo>();
            var param        = CSParam as ExpandNodeConstructParam;

            foreach (var pro in param.ExpandType.GetProperties())
            {
                if (!pro.CanWrite)
                {
                    continue;
                }
                var atts = pro.GetCustomAttributes(typeof(EngineNS.Editor.MacrossMemberAttribute), false);
                if (atts == null || atts.Length == 0)
                {
                    continue;
                }

                var mm = atts[0] as EngineNS.Editor.MacrossMemberAttribute;
                // 只读不能设置
                if (mm.HasType(EngineNS.Editor.MacrossMemberAttribute.enMacrossType.ReadOnly))
                {
                    continue;
                }

                if (param.ActiveMembers.Contains(pro.Name))
                {
                    var cpInfo = new CodeGenerateSystem.Base.CustomPropertyInfo();
                    cpInfo.PropertyName = pro.Name;
                    cpInfo.PropertyType = pro.PropertyType;
                    foreach (var att in pro.GetCustomAttributes(false))
                    {
                        cpInfo.PropertyAttributes.Add(att as System.Attribute);
                    }
                    cpInfo.DefaultValue = CodeGenerateSystem.Program.GetDefaultValueFromType(cpInfo.PropertyType);
                    cpInfo.CurrentValue = cpInfo.DefaultValue;

                    cpInfos_Show.Add(cpInfo);
                }
            }
            foreach (var field in param.ExpandType.GetFields())
            {
                var atts = field.GetCustomAttributes(typeof(EngineNS.Editor.MacrossMemberAttribute), false);
                if (atts == null || atts.Length == 0)
                {
                    continue;
                }

                var mm = atts[0] as EngineNS.Editor.MacrossMemberAttribute;
                // 只读不能设置
                if (mm.HasType(EngineNS.Editor.MacrossMemberAttribute.enMacrossType.ReadOnly))
                {
                    continue;
                }

                if (param.ActiveMembers.Contains(field.Name))
                {
                    var cpInfo = new CodeGenerateSystem.Base.CustomPropertyInfo();
                    cpInfo.PropertyName = field.Name;
                    cpInfo.PropertyType = field.FieldType;
                    foreach (var att in field.GetCustomAttributes(false))
                    {
                        cpInfo.PropertyAttributes.Add(att as System.Attribute);
                    }
                    cpInfo.DefaultValue = CodeGenerateSystem.Program.GetDefaultValueFromType(cpInfo.PropertyType);
                    cpInfo.CurrentValue = cpInfo.DefaultValue;

                    cpInfos_Show.Add(cpInfo);
                }
            }

            mTemplateClassInstance_Show = CodeGenerateSystem.Base.PropertyClassGenerator.CreateClassInstanceFromCustomPropertys(cpInfos_Show, this, "ExpandShow" + Guid.NewGuid().ToString(), false);
            bool createNewAllTC = false;

            foreach (var pro in mTemplateClassInstance_Show.GetType().GetProperties())
            {
                var allPro = allType.GetProperty(pro.Name);
                if (allPro == null)
                {
                    createNewAllTC = true;
                }
                else
                {
                    pro.SetValue(mTemplateClassInstance_Show, allPro.GetValue(mTemplateClassInstance_All));
                }
            }
            if (createNewAllTC)
            {
                var showType = mTemplateClassInstance_Show.GetType();
                CreateTemplateClass_All();
                foreach (var pro in mTemplateClassInstance_All.GetType().GetProperties())
                {
                    var showPro = showType.GetProperty(pro.Name);
                    pro.SetValue(mTemplateClassInstance_All, showPro.GetValue(mTemplateClassInstance_Show));
                }
            }
        }
Exemplo n.º 6
0
        void CreateTemplateClass_All()
        {
            var cpInfos_All = new List <CodeGenerateSystem.Base.CustomPropertyInfo>();
            var param       = CSParam as ExpandNodeConstructParam;

            if (param.ExpandType == null)
            {
                return;
            }
            foreach (var pro in param.ExpandType.GetProperties())
            {
                if (!pro.CanWrite)
                {
                    continue;
                }
                var atts = pro.GetCustomAttributes(typeof(EngineNS.Editor.MacrossMemberAttribute), false);
                if (atts == null || atts.Length == 0)
                {
                    continue;
                }

                var mm = atts[0] as EngineNS.Editor.MacrossMemberAttribute;
                // 只读不能设置
                if (mm.HasType(EngineNS.Editor.MacrossMemberAttribute.enMacrossType.ReadOnly))
                {
                    continue;
                }

                var cpInfo = new CodeGenerateSystem.Base.CustomPropertyInfo();
                cpInfo.PropertyName = pro.Name;
                cpInfo.PropertyType = pro.PropertyType;
                foreach (var att in pro.GetCustomAttributes(false))
                {
                    cpInfo.PropertyAttributes.Add(att as System.Attribute);
                }
                cpInfo.DefaultValue = CodeGenerateSystem.Program.GetDefaultValueFromType(cpInfo.PropertyType);
                cpInfo.CurrentValue = cpInfo.DefaultValue;
                cpInfos_All.Add(cpInfo);
            }
            foreach (var field in param.ExpandType.GetFields())
            {
                var atts = field.GetCustomAttributes(typeof(EngineNS.Editor.MacrossMemberAttribute), false);
                if (atts == null || atts.Length == 0)
                {
                    continue;
                }

                var mm = atts[0] as EngineNS.Editor.MacrossMemberAttribute;
                // 只读不能设置
                if (mm.HasType(EngineNS.Editor.MacrossMemberAttribute.enMacrossType.ReadOnly))
                {
                    continue;
                }

                var cpInfo = new CodeGenerateSystem.Base.CustomPropertyInfo();
                cpInfo.PropertyName = field.Name;
                cpInfo.PropertyType = field.FieldType;
                foreach (var att in field.GetCustomAttributes(false))
                {
                    cpInfo.PropertyAttributes.Add(att as System.Attribute);
                }
                cpInfo.DefaultValue = CodeGenerateSystem.Program.GetDefaultValueFromType(cpInfo.PropertyType);
                cpInfo.CurrentValue = cpInfo.DefaultValue;
                cpInfos_All.Add(cpInfo);
            }
            mTemplateClassInstance_All = CodeGenerateSystem.Base.PropertyClassGenerator.CreateClassInstanceFromCustomPropertys(cpInfos_All, this, $"ExpandNode_{param.ExpandType.FullName}.{NodeName}", false);
        }