コード例 #1
0
        // CodeMapping Function
        public string CallbackHandlers(int depth = 0)
        {
            // [0] : Handler 연결 부분
            // [1] : Data Binding 부분

            if (logicCodes.Count > 3)
            {
                var indentBuilder = new IndentStringBuilder(depth);

                for (int i = 3; i < logicCodes.Count; i++)
                {
                    indentBuilder.AppendBlock(logicCodes[i]);

                    if (i < logicCodes.Count - 1)
                    {
                        indentBuilder.AppendLine();
                        indentBuilder.AppendLine();
                    }
                }

                return(indentBuilder.ToString());
            }

            return(null);
        }
コード例 #2
0
        // CodeMapping Function
        public string ComponentInitialize()
        {
            var indentBuilder = new IndentStringBuilder(3);

            foreach (var kv in this.Mapper.NameContainer)
            {
                var    attr = kv.Value.GetAttribute <WPFAttribute>();
                string name = kv.Key.Trim('_');

                indentBuilder.AppendLine($"{name} = this.FindElement<{attr.Name}>(\"{name}\");");
            }

            logicCodes.Clear();
            logicCodes.AddRange(this.NativeGenerator.Generate().ToArray());

            if (logicCodes.Count > 0)
            {
                indentBuilder.AppendLine();
                indentBuilder.AppendLine("// Event Handlers");

                indentBuilder.AppendBlock(logicCodes[0]);
            }

            return(indentBuilder.ToString());
        }
コード例 #3
0
ファイル: WPFTemplateBuilder.cs プロジェクト: sunfom/DeXign
        // CodeMapping Function
        public string Templates(int depth)
        {
            if (TemplateContents == null)
            {
                return(null);
            }

            var builder = new IndentStringBuilder(depth);

            for (int i = 0; i < TemplateContents.Length; i++)
            {
                if (i > 0)
                {
                    builder.AppendLine();
                }

                builder.AppendLine($"<DataTemplate x:Key=\"{TemplateNames[i]}\">");

                builder.AppendBlock(TemplateContents[i], 1);
                builder.AppendLine();

                builder.AppendLine("</DataTemplate>");
            }

            return(builder.ToString());
        }
コード例 #4
0
        private string GenerateCallback(PTrigger trigger)
        {
            var callbackBuilder = new IndentStringBuilder();

            string declareName = trigger.EventInfo.DeclaringType.GetAttribute <WPFAttribute>().Name;

            ParameterInfo[] infos = trigger.EventInfo.GetParameters();

            callbackBuilder.Append($"private async void {CallbackContainer[trigger]}(");

            for (int i = 0; i < infos.Length; i++)
            {
                string paramName = infos[i].Name;

                if (paramName == "sender")
                {
                    paramName = "oSender";
                }

                callbackBuilder.Append(infos[i].ParameterType.Name);
                callbackBuilder.Append(" ");
                callbackBuilder.Append(paramName);

                if (i < infos.Length - 1)
                {
                    callbackBuilder.Append(", ");
                }
            }

            callbackBuilder.AppendLine(")");

            // Ex: private void Button_Click(object oSender, EventArgs)

            callbackBuilder.AppendLine("{");
            //callbackBuilder.AppendLine("try", 1);
            //callbackBuilder.AppendLine("{", 1);

            callbackBuilder.AppendLine($"var sender = oSender as {declareName};", 1);
            callbackBuilder.AppendLine();
            callbackBuilder.AppendLine("{Code}");

            //callbackBuilder.AppendLine("}", 1);
            //callbackBuilder.AppendLine("catch (Exception ex)", 1);
            //callbackBuilder.AppendLine("{", 1);
            //callbackBuilder.AppendLine("MessageBox.Show(ex.ToString());", 1);
            //callbackBuilder.AppendLine("}", 1);
            callbackBuilder.Append("}");

            /*
             * Ex: private void Button_Click(object oSender, EventArgs)
             *  {
             *      var sender = oSender as {SenderType};
             *  {Code:1}
             *  }
             */

            return(callbackBuilder.ToString());
        }
コード例 #5
0
        public static void AddMethodHandlersClass(DefClass type, IndentStringBuilder sb)
        {
            if (!type.HasWrapType(WrapTypes.NativeDirector))
            {
                throw new Exception("Unexpected");
            }

            if (type.IsNested)
            {
                sb.AppendIndent("public: ");
            }
            else
            {
                sb.AppendIndent("public ");
            }

            sb.Append("ref class " + type.Name + " abstract sealed\n");
            sb.AppendLine("{");
            sb.AppendLine("public:");
            sb.IncreaseIndent();

            foreach (DefFunction f in type.PublicMethods)
            {
                if (f.IsDeclarableFunction && f.IsVirtual)
                {
                    //if (f.Parameters.Count > 0)
                    //{
                    //    AddEventArgsClass(f, sb);
                    //}

                    sb.AppendIndent("delegate static " + f.CLRTypeName + " " + f.CLRName + "Handler(");
                    for (int i = 0; i < f.Parameters.Count; i++)
                    {
                        DefParam param = f.Parameters[i];
                        sb.Append(" " + param.Type.GetCLRParamTypeName(param) + " " + param.Name);
                        if (i < f.Parameters.Count - 1)
                        {
                            sb.Append(",");
                        }
                    }
                    sb.Append(" );\n");
                }
            }

            sb.DecreaseIndent();
            sb.AppendLine("};");
            sb.AppendLine();
        }
コード例 #6
0
        // CodeMapping Function
        public string ComponentInitialize(int depth = 0)
        {
            var indentBuilder = new IndentStringBuilder(depth);

            try
            {
                foreach (var kv in this.Mapper.NameContainer)
                {
                    var    attr = kv.Value.GetAttribute <WPFAttribute>();
                    string name = kv.Key.Trim('_');

                    indentBuilder.AppendLine($"{name} = this.FindElement<{attr.Name}>(\"{name}\");");
                }

                logicCodes.Clear();
                logicCodes.AddRange(this.NativeGenerator.Generate().ToArray());

                if (logicCodes.Count > 0 && logicCodes[0].Length > 0)
                {
                    indentBuilder.AppendLine();
                    indentBuilder.AppendLine("// Event Handlers");

                    indentBuilder.AppendBlock(logicCodes[0]);
                }

                if (logicCodes.Count > 1 && logicCodes[1].Length > 0)
                {
                    indentBuilder.AppendLine();
                    indentBuilder.AppendLine();
                    indentBuilder.AppendLine("// Data Bindings");

                    indentBuilder.AppendBlock(logicCodes[1]);
                }

                if (logicCodes.Count > 2 && logicCodes[2].Length > 0)
                {
                    indentBuilder.AppendLine();
                    indentBuilder.AppendLine();
                    indentBuilder.AppendLine("// Template Setting");

                    indentBuilder.AppendBlock(logicCodes[2]);
                }
            }
            catch (System.Exception e)
            {
            }

            return(indentBuilder.ToString());
        }
コード例 #7
0
        // CodeMapping Function
        public string LoadDynamicAssembly(int depth = 0)
        {
            var indentBuilder = new IndentStringBuilder(depth);

            foreach (string dllName in WPFCompiler.DynamicLibraries)
            {
                indentBuilder.AppendLine($"DynamicLoadDll(\"{dllName}\");");
            }

            return(indentBuilder.ToString());
        }
コード例 #8
0
        // CodeMapping Function
        public string CallbackHandlers()
        {
            if (logicCodes.Count > 1)
            {
                var indentBuilder = new IndentStringBuilder(2);

                for (int i = 1; i < logicCodes.Count; i++)
                {
                    indentBuilder.AppendBlock(logicCodes[i]);

                    if (i < logicCodes.Count - 1)
                    {
                        indentBuilder.AppendLine();
                        indentBuilder.AppendLine();
                    }
                }

                return(indentBuilder.ToString());
            }

            return(null);
        }
コード例 #9
0
        // CodeMapping Function
        public string PageInitialize()
        {
            var indentBuilder = new IndentStringBuilder(3);

            for (int i = 0; i < this.Parameter.Screens.Length; i++)
            {
                /* Ex
                 * var p0 = GenResourceManager.LoadXaml("Screen1") as DeXignPage;
                 * dw.Add(p0);
                 */

                indentBuilder.AppendLine($"var p{i} = GenResourceManager.LoadXaml(\"{this.Parameter.Screens[i].GetPageName()}.xaml\") as DeXignPage;");
                indentBuilder.AppendLine($"dw.Add(p{i});");
            }

            /* Ex
             * dw.SetPage(p0);
             */
            indentBuilder.Append($"dw.SetPage(p0);");

            return(indentBuilder.ToString());
        }
コード例 #10
0
 public override void Add()
 {
     if (_t.IsInterface)
     {
         IndentStringBuilder tempsb = _sb;
         _sb = new IndentStringBuilder();
         base.Add();
         string fname = _t.FullCLRName.Replace(_t.CLRName, _t.Name);
         string res   = _sb.ToString().Replace(_t.FullCLRName + "::", fname + "::");
         _sb = tempsb;
         _sb.AppendLine(res);
     }
     else
     {
         base.Add();
     }
 }
コード例 #11
0
        // CodeMapping Function
        public string GlobalVariableDefine()
        {
            var indentBuilder = new IndentStringBuilder(2);

            for (int i = 0; i < this.Mapper.NameContainer.Count; i++)
            {
                var kv   = this.Mapper.NameContainer.ElementAt(i);
                var attr = kv.Value.GetAttribute <WPFAttribute>();

                indentBuilder.Append($"private {attr.Name} {kv.Key.Trim('_')};");

                if (i < this.Mapper.NameContainer.Count - 1)
                {
                    indentBuilder.AppendLine();
                }
            }

            return(indentBuilder.ToString());
        }
コード例 #12
0
        // CreateScope (Recursive)
        internal static string CreateScope(DXMapper <CSharpCodeMapAttribute> mapper, CodeComponent <CSharpCodeMapAttribute>[] scopeComponents, NameContainer localVariableContainer, bool isCodeBlock = false)
        {
            var scopeBuilder = new IndentStringBuilder();
            var stack        = new Stack <CodeComponent <CSharpCodeMapAttribute> >(scopeComponents.Reverse());

            if (!isCodeBlock)
            {
                scopeBuilder.AppendLine();
                scopeBuilder.AppendLine("{");
            }

            while (stack.Count > 0)
            {
                var cc = stack.Pop();

                var mappingResult = mapper.Build(cc.Element, cc.Attribute.MappingCode);
                var sourceBuilder = new IndentStringBuilder(mappingResult.Source);

                if (cc.Element is PBinderHost host)
                {
                    foreach (DXToken token in mappingResult.Errors)
                    {
                        switch (token.Token)
                        {
                        case "Scope":
                        {
                            if (!token.IsIndexed)
                            {
                                continue;
                            }

                            int index = int.Parse(token.Parameters[0]) - 1;

                            if (host is PFunction)
                            {
                                index++;
                            }

                            var scopeBinder    = host[BindOptions.Output].ElementAt(index) as PBinder;
                            var scopeZeroHosts = scopeBinder.Items.Select(b => b.GetBinderHost());

                            var childScopeComponents = BinderHelper.FindZeroLevelNodes(scopeZeroHosts, withRoot: true)
                                                       .Distinct()
                                                       .Select(childHost => new CodeComponent <CSharpCodeMapAttribute>(
                                                                   childHost, childHost.GetAttribute <CSharpCodeMapAttribute>()))
                                                       .ToArray();

                            sourceBuilder.Replace(
                                token.OriginalSource,
                                CreateScope(mapper, childScopeComponents, localVariableContainer));

                            break;
                        }

                        case "Line":
                        {
                            if (!token.IsIndexed)
                            {
                                continue;
                            }

                            int index = int.Parse(token.Parameters[0]) - 1;

                            var paramBinder = host[BindOptions.Parameter].ElementAt(index) as PBinder;

                            ProcessBinderValue(mapper, sourceBuilder, token, paramBinder);
                            break;
                        }

                        default:
                            break;
                        }
                    }
                }

                scopeBuilder.AppendBlock(sourceBuilder.ToString(), 1);
                scopeBuilder.AppendLine();
            }

            if (!isCodeBlock)
            {
                scopeBuilder.AppendLine("}");
            }

            return(scopeBuilder.ToString());
        }
コード例 #13
0
        //private string

        public override void Generate(StringBuilder sb)
        {
            var entityName    = Helper.GetClassName(this.Model.Name);
            var varEntityName = Helper.GetVarName(this.Model.Name);
            var dtoName       = entityName + "Dto";
            var dtoVariable   = Helper.GetVarName(dtoName);

            var viewModel    = Helper.GetViewMode(this.Model.Name);
            var varViewModel = Helper.GetVarName(viewModel);

            var serivce    = Helper.GetClassName(Helper.GetModuleName(this.Model.Name) + "Service");
            var varSerivce = "_" + Helper.GetVarName(serivce);

            var builder = new IndentStringBuilder();

            builder.AppendLine(@"using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Company.ZCH49.OaSystem.WebSite.ServiceLayer;");
            builder.AppendLine();
            builder.AppendLine("namespace xxx");
            builder.IncreaseIndentLine("{");
            builder.AppendFormatLine("public class Edit{0}Model", entityName);
            builder.IncreaseIndentLine("{");
            builder.AppendLine("#region property");
            builder.AppendLine();
            foreach (var f in this.Model.Fields)
            {
                if (f.SystemType == "String")
                {
                    builder.AppendFormatLine("public {0} {1} ", f.SystemType, f.Name);
                }
                else
                {
                    builder.AppendFormatLine("public {0}? {1} ", f.SystemType, f.Name);
                }

                builder.AppendLine("{get;set;}");
                builder.AppendLine();
            }

            builder.AppendLine("public string ErrorMsg");
            builder.AppendLine("{get;set;}");
            builder.AppendLine();

            builder.AppendLine("public bool IsSave");
            builder.AppendLine("{get;set;}");
            builder.AppendLine();

            builder.AppendLine("public bool IsPostBack");
            builder.AppendLine("{get;set;}");
            builder.AppendLine();

            builder.AppendLine("#endregion");
            builder.AppendLine();
            builder.AppendFormatLine("public {0} {1} = new {0}();", serivce, varSerivce);
            builder.AppendLine();

            builder.AppendLine("public bool IsNew");
            builder.AppendLine("{");
            builder.AppendLine("\tget");
            builder.AppendLine("\t{");
            builder.AppendLine("\t\treturn !this.Id.HasValue;");
            builder.AppendLine("\t}");
            builder.AppendLine("}");
            builder.AppendLine();

            builder.AppendLine("public void Action()");
            builder.IncreaseIndentLine("{");
            builder.AppendLine("Init();");
            builder.AppendLine();
            builder.AppendLine("if (this.IsSave)");
            builder.AppendLine("{");
            builder.AppendLine("\tthis.Save();");
            builder.AppendLine("}");
            builder.DecreaseIndentLine("}");
            builder.AppendLine();

            builder.AppendLine("private void Init()");
            builder.IncreaseIndentLine("{");
            builder.AppendLine("if (this.Id.HasValue && this.IsPostBack == false)");
            builder.IncreaseIndentLine("{");
            builder.AppendFormatLine("var rslt = {0}.Get{1}(Id.Value);", varSerivce, entityName);
            builder.AppendFormatLine("if (rslt == null || !rslt.IsSuccess || rslt.Data == null)");
            builder.IncreaseIndentLine("{");
            builder.AppendLine("this.ErrorMsg = rslt == null ? \"no this data\" : rslt.Message;");
            builder.AppendLine("return;");
            builder.DecreaseIndentLine("}");
            builder.AppendLine();

            builder.AppendLine("var info = rslt.Data;");
            foreach (var f in this.Model.Fields)
            {
                builder.AppendFormatLine("this.{0} = info.{0};", Helper.GetClassName(f.Name));
            }
            builder.DecreaseIndentLine("}");
            builder.DecreaseIndentLine("}");
            builder.AppendLine();

            builder.AppendFormatLine("private bool Validate({0} info)", viewModel);
            builder.IncreaseIndentLine("{");
            foreach (var f in this.Model.Fields)
            {
                if (!f.NullAble)
                {
                    if (string.Compare(f.SystemType, "string", true) == 0)
                    {
                        builder.AppendFormatLine("if (string.IsNullOrWhiteSpace(info.{0}))", Helper.GetClassName(f.Name));
                    }
                    else
                    {
                        builder.AppendFormatLine("if (info.{0} == default({1}))", Helper.GetClassName(f.Name), f.SystemType);
                    }
                    builder.IncreaseIndentLine("{");
                    builder.AppendFormatLine("this.ErrorMsg = \"{0} Required\";", Helper.GetClassName(f.Name));
                    builder.AppendLine("return false;");
                    builder.DecreaseIndentLine("}");
                }
            }
            builder.AppendLine("return true;");
            builder.DecreaseIndentLine("}");
            builder.AppendLine();

            builder.AppendLine("private void Save()");
            builder.IncreaseIndentLine("{");

            //builder.AppendFormatLine("var {0} = new {1}();", varSerivce, serivce);

            builder.AppendFormatLine("var info = this.To{0}();", viewModel);
            builder.AppendFormatLine("if (!this.Validate(info))");
            builder.AppendLine("\treturn;");
            builder.AppendLine();
            builder.AppendFormatLine("var rslt = new ReturnInfo();", viewModel);
            builder.AppendLine();
            builder.AppendLine("if (this.IsNew)");
            builder.AppendLine("{");
            builder.AppendFormatLine("\trslt = {0}.Add{1}(info);", varSerivce, entityName);
            builder.AppendLine("}");
            builder.AppendLine("else");
            builder.AppendLine("{");
            builder.AppendFormatLine("\trslt = {0}.Update{1}(info);", varSerivce, entityName);
            builder.AppendLine("}");
            builder.AppendLine();
            builder.AppendLine("this.ErrorMsg = rslt.Message;");
            builder.DecreaseIndentLine("}");
            builder.AppendLine();

            builder.AppendFormatLine("private {0} To{0}()", viewModel);
            builder.IncreaseIndentLine("{");
            builder.AppendFormatLine("var info = new {0}()", viewModel);

            builder.IncreaseIndentLine("{");
            foreach (var f in this.Model.Fields)
            {
                if (f.NullAble)
                {
                    builder.AppendFormatLine("{0} = this.{0},", f.Name);
                }
                else
                {
                    if (f.SystemType == "Guid")
                    {
                        if (f.Name.Equals("id", StringComparison.OrdinalIgnoreCase))
                        {
                            builder.AppendFormatLine("{0} = this.{0}??Guid.NewGuid(),", f.Name);
                        }
                        else
                        {
                            builder.AppendFormatLine("{0} = this.{0}??Guid.Empty,", f.Name);
                        }
                    }
                    else if (f.SystemType == "DateTime")
                    {
                        builder.AppendFormatLine("{0} = this.{0}??DateTime.Now,", f.Name);
                    }
                    else
                    {
                        builder.AppendFormatLine("{0} = this.{0}??default({1}),", f.Name, f.SystemType);
                    }
                }
            }

            builder.DecreaseIndentLine("};");
            builder.AppendLine();
            builder.AppendLine("return info;");
            builder.DecreaseIndentLine("}");
            builder.AppendLine();

            builder.AppendFormatLine("public static ReturnInfo Delete{0}(Guid id)", entityName);
            builder.IncreaseIndentLine("{");
            builder.AppendFormatLine("var {0} = new {1}();", varSerivce, serivce);
            builder.AppendFormatLine("return {0}.Delete{1}(id);", varSerivce, entityName);
            builder.DecreaseIndentLine("}");

            builder.AppendLine();
            builder.AppendFormatLine("public static ReturnInfo Delete{0}(List<Guid> id_list)", entityName);
            builder.IncreaseIndentLine("{");
            builder.AppendFormatLine("var {0} = new {1}();", varSerivce, serivce);
            builder.AppendFormatLine("return {0}.Delete{1}(id_list);", varSerivce, entityName);
            builder.DecreaseIndentLine("}");

            builder.DecreaseIndentLine("}");
            builder.DecreaseIndentLine("}");
            sb.Append(builder.ToString());
        }
コード例 #14
0
 public void CanAppendLine()
 {
     TestObject.AppendLine(TestString);
 }
コード例 #15
0
ファイル: CSharpGenerator.cs プロジェクト: sqler21c/DeXign
        protected override IEnumerable <string> OnGenerate(IEnumerable <CodeComponent <CSharpCodeMapAttribute> > components)
        {
            var items = components.ToArray();
            CodeComponent <CSharpCodeMapAttribute> root = items.FirstOrDefault();

            // Trigger Hosts
            CodeComponent <CSharpCodeMapAttribute>[] triggers = items
                                                                .Where(cc => cc.Depth == 0)
                                                                .SelectMany(item => item.Children)
                                                                .Where(item => item.Element is PTrigger)
                                                                .Distinct(new CodeComponentComparer <CSharpCodeMapAttribute>())
                                                                .ToArray();

            //// Trigger Hosts
            //CodeComponent<CSharpCodeMapAttribute>[] triggers = items
            //    .Where(cc => cc.Depth == 0)
            //    .SelectMany(item => item.Children)
            //    .Distinct(new CodeComponentComparer<CSharpCodeMapAttribute>())
            //    .ToArray();

            // Event Handle
            var eventHandlerBuilder = new StringBuilder();

            foreach (var trigger in triggers)
            {
                var    result       = this.Mapper.Build(trigger.Element, trigger.Attribute.MappingCode);
                string source       = result.Source;
                string callbackName = Mapper.MappingProvider.GetEventCallbackName(trigger.Element as PTrigger);

                source = source.Replace("{EventCallback}", callbackName);

                eventHandlerBuilder.AppendLine(source);
            }

            yield return(eventHandlerBuilder.ToString());

            // Callback
            foreach (var trigger in triggers)
            {
                string callbackSource = GenerateCallback(trigger.Element as PTrigger);
                string code           = "";

                if (trigger.HasChildren)
                {
                    // 지역 변수 컨테이너
                    var localVariableContainer = new NameContainer();

                    code = CreateScope(trigger.Children.ToArray(), localVariableContainer, true);
                }

                yield return(callbackSource.Replace("{Code}", code));
            }

            // CreateScope (Recursive)
            string CreateScope(CodeComponent <CSharpCodeMapAttribute>[] scopeComponents, NameContainer localVariableContainer, bool isCodeBlock = false)
            {
                var scopeBuilder = new IndentStringBuilder();
                var stack        = new Stack <CodeComponent <CSharpCodeMapAttribute> >(scopeComponents);

                if (!isCodeBlock)
                {
                    scopeBuilder.AppendLine();
                    scopeBuilder.AppendLine("{");
                }

                while (stack.Count > 0)
                {
                    var cc = stack.Pop();

                    var mappingResult = this.Mapper.Build(cc.Element, cc.Attribute.MappingCode);
                    var sourceBuilder = new IndentStringBuilder(mappingResult.Source);

                    if (cc.Element is PBinderHost host)
                    {
                        foreach (DXToken token in mappingResult.Errors)
                        {
                            switch (token.Token)
                            {
                            case "Scope":
                            {
                                if (!token.IsIndexed)
                                {
                                    continue;
                                }

                                int index = int.Parse(token.Parameter) - 1;

                                var scopeBinder          = host[BindOptions.Output].ElementAt(index) as PBinder;
                                var childScopeComponents = scopeBinder.Items
                                                           .Select(item => item.Host as PBinderHost)
                                                           .Distinct()
                                                           .Select(childHost => new CodeComponent <CSharpCodeMapAttribute>(
                                                                       childHost, childHost.GetAttribute <CSharpCodeMapAttribute>()))
                                                           .ToArray();

                                sourceBuilder.Replace(
                                    token.OriginalSource,
                                    CreateScope(childScopeComponents, localVariableContainer));

                                break;
                            }

                            case "Line":
                            {
                                if (!token.IsIndexed)
                                {
                                    continue;
                                }

                                int index = int.Parse(token.Parameter) - 1;

                                var paramBinder = host[BindOptions.Parameter].ElementAt(index) as PBinder;

                                ProcessBinderValue(sourceBuilder, token, paramBinder);
                                break;
                            }

                            default:
                                break;
                            }
                        }
                    }

                    scopeBuilder.AppendBlock(sourceBuilder.ToString(), 1);
                    scopeBuilder.AppendLine();
                }

                if (!isCodeBlock)
                {
                    scopeBuilder.AppendLine("}");
                }

                return(scopeBuilder.ToString());
            }

            //string CreateLambda()

            void ProcessBinderValue(IndentStringBuilder sourceBuilder, DXToken token, PBinder binder)
            {
                string valueLine = null;

                // 직접 입력
                if (binder.IsDirectValue)
                {
                    object value = binder.DirectValue;

                    valueLine = this.Mapper.MappingProvider.GetValueLine(value, true);
                }
                // 연결됨
                else if (binder.Items.Count == 1)
                {
                    var paramOutputHost = binder.Items[0].Host;

                    var attr = paramOutputHost.GetAttribute <CSharpCodeMapAttribute>();

                    if (paramOutputHost is PTrigger)
                    {
                        valueLine = "sender";
                    }
                    else
                    {
                        valueLine = this.Mapper.Build(paramOutputHost, attr.MappingCode).Source;
                    }
                }
                else
                {
                    // Error
                }

                if (valueLine != null)
                {
                    int idx = sourceBuilder.IndexOf(token.OriginalSource);

                    // 토큰 부분 제거
                    sourceBuilder.Replace(token.OriginalSource, "");

                    sourceBuilder.Insert(idx, valueLine);
                }
            }
        }
コード例 #16
0
        protected virtual void AddPreBody()
        {
            // If there are nested NativeDirectors, declare them before the declaration
            // of this class
            foreach (DefType nested in _t.NestedTypes)
            {
                if (nested.ProtectionType == ProtectionType.Public ||
                    ((AllowProtectedMembers || AllowSubclassing) && nested.ProtectionType == ProtectionType.Protected))
                {
                    if (nested.HasWrapType(WrapTypes.NativeDirector))
                    {
                        AddNestedTypeBeforeMainType(nested);
                    }
                }
            }

            _sb.AppendLine("//################################################################");
            _sb.AppendLine("//" + _t.CLRName);
            _sb.AppendLine("//################################################################\n");
        }
コード例 #17
0
        public static void AddNativeProxyMethodBody(DefFunction f, string managedTarget, IndentStringBuilder sb)
        {
            string managedCall;
            string fullPostConv = null;

            if (f.IsGetProperty)
            {
                sb.AppendLine(f.CLRTypeName + " mp_return = " + managedTarget + "->" + f.CLRName + ";");
                managedCall = "mp_return";
            }
            else if (f.IsSetProperty)
            {
                DefParam param = f.Parameters[0];
                managedCall = managedTarget + "->" + f.CLRName + " = " + param.Type.GetNativeCallConversion(param.Name, param);
            }
            else
            {
                string pre, post, conv;

                foreach (DefParam param in f.Parameters)
                {
                    param.Type.GetNativeParamConversion(param, out pre, out conv, out post);
                    if (!String.IsNullOrEmpty(pre))
                    {
                        sb.AppendLine(pre);
                    }

                    if (!String.IsNullOrEmpty(post))
                    {
                        fullPostConv += post + "\n";
                    }
                }

                bool explicitCast = f.HasAttribute <ExplicitCastingForParamsAttribute>();

                if (!f.IsVoid)
                {
                    sb.AppendIndent(f.CLRTypeName + " mp_return = " + managedTarget + "->" + f.CLRName + "(");
                    for (int i = 0; i < f.Parameters.Count; i++)
                    {
                        DefParam param = f.Parameters[i];
                        param.Type.GetNativeParamConversion(param, out pre, out conv, out post);
                        sb.Append(" ");
                        if (explicitCast)
                        {
                            sb.Append("(" + param.CLRTypeName + ")");
                        }
                        sb.Append(conv);
                        if (i < f.Parameters.Count - 1)
                        {
                            sb.Append(",");
                        }
                    }
                    sb.Append(" );\n");
                    managedCall = "mp_return";

                    if (!String.IsNullOrEmpty(fullPostConv))
                    {
                        sb.AppendLine(fullPostConv);
                    }
                }
                else
                {
                    managedCall = managedTarget + "->" + f.CLRName + "(";
                    for (int i = 0; i < f.Parameters.Count; i++)
                    {
                        DefParam param = f.Parameters[i];
                        param.Type.GetNativeParamConversion(param, out pre, out conv, out post);
                        managedCall += " ";
                        if (explicitCast)
                        {
                            managedCall += "(" + param.CLRTypeName + ")";
                        }
                        managedCall += conv;
                        if (i < f.Parameters.Count - 1)
                        {
                            managedCall += ",";
                        }
                    }
                    managedCall += " )";
                }
            }

            if (!f.IsVoid)
            {
                if (f.Type is IDefString)
                {
                    sb.AppendLine("SET_NATIVE_STRING( Mogre::Implementation::cachedReturnString, " + managedCall + " )");
                    sb.AppendLine("return Mogre::Implementation::cachedReturnString;");
                }
                else
                {
                    string   returnExpr;
                    string   newname, expr, postcall;
                    DefParam param = new DefParam(f, managedCall);
                    expr     = f.Type.GetPreCallParamConversion(param, out newname);
                    postcall = f.Type.GetPostCallParamConversionCleanup(param);
                    if (!String.IsNullOrEmpty(expr))
                    {
                        sb.AppendLine(expr);
                        if (String.IsNullOrEmpty(postcall))
                        {
                            returnExpr = newname;
                        }
                        else
                        {
                            throw new Exception("Unexpected");
                        }
                    }
                    else
                    {
                        returnExpr = newname;
                    }

                    if (IsCachedFunction(f))
                    {
                        sb.AppendLine("STATIC_ASSERT( sizeof(" + f.Type.FullNativeName + ") <= CACHED_RETURN_SIZE )");
                        sb.AppendLine("memcpy( Mogre::Implementation::cachedReturn, &" + returnExpr + ", sizeof(" + f.Type.FullNativeName + ") );");
                        sb.AppendLine("return *reinterpret_cast<" + f.Type.FullNativeName + "*>(Mogre::Implementation::cachedReturn);");
                    }
                    else
                    {
                        sb.AppendLine("return " + returnExpr + ";");
                    }
                }
            }
            else
            {
                sb.AppendLine(managedCall + ";");

                if (!String.IsNullOrEmpty(fullPostConv))
                {
                    sb.AppendLine(fullPostConv);
                }
            }
        }
コード例 #18
0
        public override void Generate(StringBuilder sb)
        {
            var entityName    = Helper.GetClassName(this.Model.Name);
            var varEntityName = Helper.GetVarName(this.Model.Name);
            var dtoName       = entityName + "Dto";
            var dtoVariable   = Helper.GetVarName(dtoName);

            var viewModel    = Helper.GetViewMode(this.Model.Name);
            var varViewModel = Helper.GetVarName(viewModel);
            var builder      = new IndentStringBuilder();

            builder.Increase();

            builder.AppendFormatLine("public ActionResult Edit{0}(Edit{0}Model model)", entityName);
            builder.IncreaseIndentLine("{");
            builder.AppendLine();
            builder.AppendLine("//model.UserId = Company.ZCH49.OaSystem.WebSite.Models.User.GetCurrentUser(this).Id;");
            builder.AppendLine("model.Action();");
            builder.AppendLine("return View(model);");
            builder.AppendLine();
            builder.DecreaseIndentLine("}");

            builder.AppendLine();

            builder.AppendLine("/*[HttpPost]");
            builder.AppendFormatLine("public ActionResult Delete{0}(Guid id)", entityName);
            builder.IncreaseIndentLine("{");
            builder.AppendLine("var model = new ReturnInfo();");
            builder.AppendLine();
            builder.AppendLine("if (id == default(Guid))");
            builder.IncreaseIndentLine("{");
            builder.AppendLine("model.Message = \"no id\";");
            builder.DecreaseIndentLine("}");
            builder.AppendLine("else");
            builder.IncreaseIndentLine("{");
            builder.AppendFormatLine(" model = Edit{0}Model.Delete{0}(id);", entityName);
            builder.DecreaseIndentLine("}");
            builder.AppendLine("return Json(model, JsonRequestBehavior.AllowGet);");
            builder.AppendLine("");
            builder.DecreaseIndentLine("}*/");

            builder.AppendLine();

            builder.AppendLine("[HttpPost]");
            builder.AppendFormatLine("public ActionResult Delete{0}(List<Guid> idList)", entityName);
            builder.IncreaseIndentLine("{");
            builder.AppendLine("var model = new ReturnInfo();");
            builder.AppendLine();
            builder.AppendLine("if (idList == null || idList.Count == 0)");
            builder.IncreaseIndentLine("{");
            builder.AppendLine("model.Message = \"no id\";");
            builder.DecreaseIndentLine("}");
            builder.AppendLine("else");
            builder.IncreaseIndentLine("{");
            builder.AppendFormatLine(" model = Edit{0}Model.Delete{0}(idList);", entityName);
            builder.DecreaseIndentLine("}");
            builder.AppendLine("return Json(model, JsonRequestBehavior.AllowGet);");
            builder.AppendLine("");
            builder.DecreaseIndentLine("}");
            sb.Append(builder.ToString());
            base.Generate(sb);
        }