private void Btn_ClassSetting_Click(object sender, RoutedEventArgs e)
        {
            if (CurrentResourceInfo.BaseType == null)
            {
                EditorCommon.MessageBox.Show("找不到当前Macross的基类");
                return;
            }

            if (mClassSettingPropertiesClassInstance == null)
            {
                var atts   = CurrentResourceInfo.BaseType.GetCustomAttributes(typeof(EngineNS.Editor.Editor_MacrossClassAttribute), true);
                var att    = atts[0] as EngineNS.Editor.Editor_MacrossClassAttribute;
                var csType = att.CSType;
                List <CodeGenerateSystem.Base.CustomPropertyInfo> cpInfos = new List <CodeGenerateSystem.Base.CustomPropertyInfo>();

                var baseTypeCPInfo = new CodeGenerateSystem.Base.CustomPropertyInfo()
                {
                    PropertyName = "BaseType",
                    PropertyType = typeof(Type),
                    DefaultValue = CurrentResourceInfo.BaseType,
                    CurrentValue = CurrentResourceInfo.BaseType,
                };
                // Editor.Editor_BaseTypeDefine 限定类型基类
                baseTypeCPInfo.PropertyAttributes.Add(new EngineNS.Editor.Editor_TypeFilterAttribute(EngineNS.Editor.Editor_TypeFilterAttribute.enTypeFilter.Class, EngineNS.Editor.Editor_MacrossClassAttribute.enMacrossType.Inheritable));

                cpInfos.Add(baseTypeCPInfo);

                var initParam = new CodeGenerateSystem.Base.ConstructionParams()
                {
                    CSType = csType,
                };
                var tempNode = new TempNode(initParam);
                mClassSettingPropertiesClassInstance = CodeGenerateSystem.Base.PropertyClassGenerator.CreateClassInstanceFromCustomPropertys(cpInfos, tempNode, "MCSetting_" + EngineNS.Editor.Assist.GetValuedGUIDString(Guid.NewGuid()), false);
                var classType = mClassSettingPropertiesClassInstance.GetType();
                //var classType = CodeGenerateSystem.Base.PropertyClassGenerator.CreateTypeFromCustomPropertys(cpInfos, "MacrossClassSettingDynamicAssembly", );
                //mClassSettingPropertiesClassInstance = System.Activator.CreateInstance(classType) as CodeGenerateSystem.Base.GeneratorClassBase;
                //mClassSettingPropertiesClassInstance.CSType = csType;
                foreach (var cpInfo in cpInfos)
                {
                    var pro = classType.GetProperty(cpInfo.PropertyName);
                    pro.SetValue(mClassSettingPropertiesClassInstance, cpInfo.CurrentValue, null);
                }

                mClassSettingPropertiesClassInstance.OnPropertyChangedAction = (propertyName, newValue, oldValue) =>
                {
                    switch (propertyName)
                    {
                    case "BaseType":
                        CurrentResourceInfo.ResetBaseType((Type)newValue);
                        break;
                    }
                };
            }

            var ctrl = LinksTabControl.SelectedContent as MacrossLinkControl;

            ctrl.PG.Instance = mClassSettingPropertiesClassInstance;
        }
Beispiel #2
0
        public void CreateTemplateClas()
        {
            var param = CSParam as CreateObjectConstructionParams;

            mClassProperties.Clear();
            if (param.CreateType != null)
            {
                var properties = param.CreateType.GetProperties();
                foreach (var property in properties)
                {
                    var att = EngineNS.Rtti.AttributeHelper.GetCustomAttribute(property, typeof(EngineNS.Editor.MacrossMemberAttribute).FullName, true);
                    if (att == null)
                    {
                        continue;
                    }

                    var cpInfo = new CodeGenerateSystem.Base.CustomPropertyInfo()
                    {
                        PropertyName = property.Name,
                        PropertyType = property.PropertyType,
                        DefaultValue = CodeGenerateSystem.Program.GetDefaultValueFromType(property.PropertyType),
                    };
                    cpInfo.CurrentValue = cpInfo.DefaultValue;
                    bool hasMetaAtt = false;
                    foreach (Attribute customAtt in property.GetCustomAttributes(false))
                    {
                        if (customAtt.GetType().FullName == typeof(EngineNS.Rtti.MetaDataAttribute).FullName)
                        {
                            hasMetaAtt = true;
                        }
                        cpInfo.PropertyAttributes.Add(customAtt);
                    }
                    if (!hasMetaAtt)
                    {
                        cpInfo.PropertyAttributes.Add(new EngineNS.Rtti.MetaDataAttribute());
                    }
                    mClassProperties.Add(cpInfo);
                }
                mTemplateClassInstance = CodeGenerateSystem.Base.PropertyClassGenerator.CreateClassInstanceFromCustomPropertys(mClassProperties, this, $"CreateObject_{param.CreateType.FullName}", false);
            }
            if (mDefaultValueObj == null)
            {
                mDefaultValueObj = System.Activator.CreateInstance(param.CreateType);
            }
            var classType = mTemplateClassInstance.GetType();

            foreach (var pro in mClassProperties)
            {
                var proInfo = classType.GetProperty(pro.PropertyName);
                if (proInfo == null)
                {
                    continue;
                }
                var srcProInfo = param.CreateType.GetProperty(pro.PropertyName);
                proInfo.SetValue(mTemplateClassInstance, srcProInfo.GetValue(mDefaultValueObj));
            }
        }