Exemple #1
0
        public CodeGenType(TypeDefinition typeDefinition, CodeGenService.GhostComponent config = null)
        {
            _overrideConfig = config;

            // 模板参数
            templateArgs = new CommonT4Info
            {
                TypeName     = typeDefinition.Name,
                CurNamespace = typeDefinition.Namespace,
                ToNamespace  = GetNamespace(typeDefinition.Module.Assembly.Name.Name),
                Fields       = new List <FieldT4Info>()
            };

            outFileName = $"{templateArgs.TypeName}Serializer.cs";
        }
Exemple #2
0
        public CommandGenType(TypeDefinition typeDefinition, CodeGenService.GhostComponent config = null) : base(
                typeDefinition, config)
        {
            templateFilePath = CodeGenServiceEditor.CommandDataSerializerPath;

            foreach (var fieldDefinition in typeDefinition.Fields)
            {
                if (!fieldDefinition.FieldType.IsValueType || fieldDefinition.Name.StartsWith("<"))
                {
                    continue;
                }

                TypeReference fieldType = fieldDefinition.FieldType;

                templateArgs.Fields.Add(new FieldT4Info
                {
                    Name      = fieldDefinition.Name,
                    TypeName1 = ToUpper(fieldType.Name),
                });
            }
        }
Exemple #3
0
        public GhostComponentGenType(TypeDefinition typeDefinition, CodeGenService.GhostComponent config = null) : base(
                typeDefinition, config)
        {
            templateFilePath = CodeGenServiceEditor.GhostComponentSerializerPath;

            GhostComponentAttribute ghostComponentAttribute = null;

            if (config != null)
            {
                ghostComponentAttribute = config.Attribute;
            }
            else
            {
                ghostComponentAttribute = CecilExtensions.GetGhostComponentAttribute(typeDefinition);
            }

            if (ghostComponentAttribute == null)
            {
                Debug.LogError(typeDefinition.FullName);
            }

            templateArgs.IsUpdateValue = ghostComponentAttribute.IsUpdateValue ? "true" : "false";
            templateArgs.SendType      = ghostComponentAttribute.SendType.ToString();
            templateArgs.Fields        = new List <FieldT4Info>();

            foreach (var fieldDefinition in typeDefinition.Fields)
            {
                if (!fieldDefinition.FieldType.IsValueType || fieldDefinition.Name.StartsWith("<"))
                {
                    continue;
                }

                bool isGhostField = fieldDefinition.IsGhostField();

                CodeGenService.GhostComponentField field = null;
                if (config != null)
                {
                    field        = config.Fields.FirstOrDefault(f => f.Name == fieldDefinition.Name);
                    isGhostField = field != null;
                }

                if (!isGhostField)
                {
                    continue;
                }

                GhostFieldAttribute attr = null;
                if (field != null)
                {
                    attr = field.Attribute;
                }
                else
                {
                    attr = CecilExtensions.GetGhostFieldAttribute(typeDefinition, fieldDefinition);
                }

                TypeReference fieldType = fieldDefinition.FieldType;

                string type = ConvertBaseValueType(fieldType.Name);
                templateArgs.Fields.Add(new FieldT4Info
                {
                    Name                 = fieldDefinition.Name,
                    TypeName             = type,
                    TypeName1            = ToUpper(type),
                    Interpolate          = attr.Interpolate,
                    SendData             = attr.SendData,
                    InterpolateMethodStr = GetInterpolateMethodStr(type)
                });
            }
        }
Exemple #4
0
 public RpcCommandGenType(TypeDefinition typeDefinition, CodeGenService.GhostComponent config = null) : base(
         typeDefinition, config)
 {
     templateFilePath = CodeGenServiceEditor.RpcDataSerializerPath;
 }