protected abstract void GenerateSnippetExpression(CodeSnippetExpression e);
private void GenerateSnippetExpression(CodeSnippetExpression e) { Output.Write(e.Value); }
protected override void GenerateSnippetExpression (CodeSnippetExpression e) { Output.Write(e.Value); }
public void CodeSnippets() { var snippetStmt = new CodeSnippetStatement("blah"); AssertEqual(snippetStmt, "blah"); var snippetExpr = new CodeSnippetExpression(" blah "); AssertEqual(snippetExpr, " blah "); var snippetCu = new CodeSnippetCompileUnit(); snippetCu.Value = GetEmptyProgramSource(); AssertEqual(snippetCu, GetEmptyProgramSource()); }
private void ValidateSnippetExpression(CodeSnippetExpression e) { }
private void GenEntityEx(CodeNamespace ns, Type type, int outLang) { CodeTypeDeclaration entity; StringBuilder sb = new StringBuilder(); entity = new CodeTypeDeclaration(type.Name); ns.Types.Add(entity); entity.CustomAttributes.Add(new CodeAttributeDeclaration(typeof(System.SerializableAttribute).Name)); entity.IsClass = true; entity.IsPartial = true; Type[] interfaces = GetContractInterfaceTypes(type); bool findNonEntityBaseEntity = false; string entityBaseTypeName = null; foreach (Type item in interfaces) { if (typeof(IEntity).IsAssignableFrom(item) && (typeof(IEntity) != item)) { entityBaseTypeName = item.Name; entity.BaseTypes.Add(entityBaseTypeName); findNonEntityBaseEntity = true; break; } } if (!findNonEntityBaseEntity) { entity.BaseTypes.Add(typeof(Entity)); } string tableName = GetTableName(type); DescriptionAttribute ca = GetEntityAttribute <DescriptionAttribute>(type); #region 获取主键列 StringBuilder sbKey = new StringBuilder(); List <string> listKey = new List <string>(); GenGetPrimaryKeyFieldListEx(sbKey, type, listKey, outLang); #endregion if (ca != null) { //sb.Append("\t/// <summary>\r\n"); //sb.Append("\t/// "); //sb.Append(ca.Description.Replace("\n", "\n\t/// ")); //sb.Append("\r\n\t/// </summary>\r\n"); entity.Comments.Add(new CodeCommentStatement("<summary>", true)); entity.Comments.Add(new CodeCommentStatement(ca.Description + string.Format(" - 表名:{0} 主键列:{1}", tableName, string.Join(",", listKey.ToArray())), true)); entity.Comments.Add(new CodeCommentStatement("</summary>", true)); } else { entity.Comments.Add(new CodeCommentStatement("<summary>", true)); entity.Comments.Add(new CodeCommentStatement(string.Format("表名:{0} 主键列:{1}", tableName, string.Join(",", listKey.ToArray())), true)); entity.Comments.Add(new CodeCommentStatement("</summary>", true)); } bool isReadonly = false; ReadOnlyAttribute read = GetEntityAttribute <ReadOnlyAttribute>(type); if (read != null) { isReadonly = true; } //generate properties CodeStatementCollection reloadQueryStatements = new CodeStatementCollection(); GenPropertiesEx(entity, reloadQueryStatements, type, isReadonly, outLang); List <string> generatedProperties = new List <string>(); CodeMemberMethod method; CodeExpression[] arrayInit; StringBuilder sbPropertyValuesList; string[] fieldsList; #region 实现重载的信息 #region 重载获取表名和只读 CodeTypeReference reference = new CodeTypeReference(typeof(Table).FullName, new CodeTypeReference(type.Name, CodeTypeReferenceOptions.GenericTypeParameter)); CodeExpression codeExpression = new CodeObjectCreateExpression(reference, new CodeExpression[] { new CodePrimitiveExpression(tableName) }); //生成重载的方法 method = new CodeMemberMethod(); method.Name = "GetTable"; method.Attributes = MemberAttributes.Family | MemberAttributes.Override; method.ReturnType = new CodeTypeReference(typeof(Table)); //添加注释 method.Comments.Add(new CodeCommentStatement("<summary>", true)); method.Comments.Add(new CodeCommentStatement("获取实体对应的表名", true)); method.Comments.Add(new CodeCommentStatement("</summary>", true)); //CodeAssignStatement ass = new CodeAssignStatement(); //ass.Left = new CodeSnippetExpression("mappingTable"); //ass.Right = new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(new CodeSnippetExpression("EntityConfig"), "GetTable"), new CodePrimitiveExpression(tableName)); //CodeConditionStatement condition = new CodeConditionStatement(); //condition.Condition = new CodeBinaryOperatorExpression(new CodePrimitiveExpression(null), CodeBinaryOperatorType.IdentityEquality, new CodeSnippetExpression("mappingTable")); //condition.TrueStatements.Add(ass); //method.Statements.Add(condition); //method.Statements.Add(new CodeMethodReturnStatement(new CodeSnippetExpression("mappingTable"))); //entity.Members.Add(method); //new CodeTypeReference(type.Name, method.Statements.Add(new CodeMethodReturnStatement(codeExpression)); entity.Members.Add(method); if (isReadonly) { method = new CodeMemberMethod(); method.Name = "GetReadOnly"; method.Attributes = MemberAttributes.Family | MemberAttributes.Override; method.ReturnType = new CodeTypeReference(typeof(bool)); //添加注释 method.Comments.Add(new CodeCommentStatement("<summary>", true)); method.Comments.Add(new CodeCommentStatement("获取实体是否只读", true)); method.Comments.Add(new CodeCommentStatement("</summary>", true)); method.Statements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(true))); entity.Members.Add(method); } SequenceAttribute auto = GetEntityAttribute <SequenceAttribute>(type); if (auto != null) { method = new CodeMemberMethod(); method.Name = "GetSequence"; method.Attributes = MemberAttributes.Family | MemberAttributes.Override; method.ReturnType = new CodeTypeReference(typeof(string)); //添加注释 method.Comments.Add(new CodeCommentStatement("<summary>", true)); method.Comments.Add(new CodeCommentStatement("获取自增长列的名称", true)); method.Comments.Add(new CodeCommentStatement("</summary>", true)); method.Statements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(auto.Name))); entity.Members.Add(method); } #endregion sbPropertyValuesList = new StringBuilder(); generatedProperties.Clear(); //sb.Append("\t\tpublic override object[] GetPropertyValues()\r\n\t\t{\r\n"); //sb.Append("\t\t\treturn new object[] { "); GenGetIdentityFieldEx(sbPropertyValuesList, type, generatedProperties, outLang); //sb.Append(sbPropertyValuesList.ToString().TrimEnd(' ', ',')); //sb.Append(" };\r\n\t\t}\r\n\r\n"); fieldsList = sbPropertyValuesList.ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (generatedProperties.Count > 0) { method = new CodeMemberMethod(); method.Name = "GetIdentityField"; method.Attributes = MemberAttributes.Family | MemberAttributes.Override; method.ReturnType = new CodeTypeReference(typeof(Field)); //添加注释 method.Comments.Add(new CodeCommentStatement("<summary>", true)); method.Comments.Add(new CodeCommentStatement("获取实体中的标识列", true)); method.Comments.Add(new CodeCommentStatement("</summary>", true)); method.Statements.Add(new CodeMethodReturnStatement(new CodeSnippetExpression(fieldsList[0].Trim()))); entity.Members.Add(method); } sbPropertyValuesList = new StringBuilder(); generatedProperties.Clear(); //sb.Append("\t\tpublic override object[] GetPropertyValues()\r\n\t\t{\r\n"); //sb.Append("\t\t\treturn new object[] { "); GenGetPrimaryKeyFieldListEx(sbPropertyValuesList, type, generatedProperties, outLang); //sb.Append(sbPropertyValuesList.ToString().TrimEnd(' ', ',')); //sb.Append(" };\r\n\t\t}\r\n\r\n"); fieldsList = sbPropertyValuesList.ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); arrayInit = new CodeExpression[fieldsList.Length]; for (int i = 0; i < fieldsList.Length; i++) { arrayInit[i] = new CodeSnippetExpression(fieldsList[i].Trim()); } if (arrayInit.Length > 0) { method = new CodeMemberMethod(); method.Name = "GetPrimaryKeyFields"; method.Attributes = MemberAttributes.Family | MemberAttributes.Override; method.ReturnType = new CodeTypeReference(new CodeTypeReference(typeof(Field)), 1); //添加注释 method.Comments.Add(new CodeCommentStatement("<summary>", true)); method.Comments.Add(new CodeCommentStatement("获取实体中的主键列", true)); method.Comments.Add(new CodeCommentStatement("</summary>", true)); method.Statements.Add(new CodeMethodReturnStatement(new CodeArrayCreateExpression(typeof(Field), arrayInit))); entity.Members.Add(method); } method = new CodeMemberMethod(); method.Name = "GetFields"; method.Attributes = MemberAttributes.Family | MemberAttributes.Override; method.ReturnType = new CodeTypeReference(new CodeTypeReference(typeof(Field)), 1); sbPropertyValuesList = new StringBuilder(); generatedProperties.Clear(); //sb.Append("\t\tpublic override object[] GetPropertyValues()\r\n\t\t{\r\n"); //sb.Append("\t\t\treturn new object[] { "); GenGetFieldListEx(sbPropertyValuesList, type, generatedProperties, outLang); //sb.Append(sbPropertyValuesList.ToString().TrimEnd(' ', ',')); //sb.Append(" };\r\n\t\t}\r\n\r\n"); fieldsList = sbPropertyValuesList.ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); arrayInit = new CodeExpression[generatedProperties.Count]; for (int i = 0; i < generatedProperties.Count; i++) { arrayInit[i] = new CodeSnippetExpression(fieldsList[i].Trim()); } if (arrayInit.Length > 0) { //添加注释 method.Comments.Add(new CodeCommentStatement("<summary>", true)); method.Comments.Add(new CodeCommentStatement(string.Format("获取列信息"), true)); method.Comments.Add(new CodeCommentStatement("</summary>", true)); method.Statements.Add(new CodeMethodReturnStatement(new CodeArrayCreateExpression(typeof(Field), arrayInit))); entity.Members.Add(method); } #endregion method = new CodeMemberMethod(); method.Name = "GetValues"; method.Attributes = MemberAttributes.Family | MemberAttributes.Override; method.ReturnType = new CodeTypeReference(new CodeTypeReference(typeof(object)), 1); sbPropertyValuesList = new StringBuilder(); generatedProperties.Clear(); //sb.Append("\t\tpublic override object[] GetPropertyValues()\r\n\t\t{\r\n"); //sb.Append("\t\t\treturn new object[] { "); GenGetPropertyValues(sbPropertyValuesList, type, generatedProperties); //sb.Append(sbPropertyValuesList.ToString().TrimEnd(' ', ',')); //sb.Append(" };\r\n\t\t}\r\n\r\n"); fieldsList = sbPropertyValuesList.ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); arrayInit = new CodeExpression[generatedProperties.Count]; for (int i = 0; i < generatedProperties.Count; i++) { arrayInit[i] = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), fieldsList[i].Trim()); } if (arrayInit.Length > 0) { //添加注释 method.Comments.Add(new CodeCommentStatement("<summary>", true)); method.Comments.Add(new CodeCommentStatement(string.Format("获取列数据"), true)); method.Comments.Add(new CodeCommentStatement("</summary>", true)); method.Statements.Add(new CodeMethodReturnStatement(new CodeArrayCreateExpression(typeof(object), arrayInit))); entity.Members.Add(method); } else { method.Statements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(null))); entity.Members.Add(method); } method = new CodeMemberMethod(); method.Attributes = MemberAttributes.Family | MemberAttributes.Override; method.Name = "SetValues"; method.ReturnType = null; //添加注释 method.Comments.Add(new CodeCommentStatement("<summary>", true)); method.Comments.Add(new CodeCommentStatement("给当前实体赋值", true)); method.Comments.Add(new CodeCommentStatement("</summary>", true)); method.Parameters.Add(new CodeParameterDeclarationExpression(typeof(IRowReader), "reader")); //sb.Append("\t\tpublic override void SetPropertyValues(System.Data.IDataReader reader)\r\n\t\t{\r\n"); generatedProperties.Clear(); GenSetPropertyValuesFromReaderEx(method.Statements, type, generatedProperties, outLang); entity.Members.Add(method); //outNs + "." + string entityOutputTypeName = type.Name; //, CodeTypeReferenceOptions.GlobalReference CodeTypeReference entityOutputTypeNameRef = new CodeTypeReference(entityOutputTypeName); //sb.Append("\t\tpublic override int GetHashCode() { return base.GetHashCode(); }\r\n\r\n"); method = new CodeMemberMethod(); method.Attributes = MemberAttributes.Public | MemberAttributes.Override; method.Name = "GetHashCode"; method.ReturnType = new CodeTypeReference(typeof(int)); method.Statements.Add(new CodeMethodReturnStatement(new CodeMethodInvokeExpression(new CodeBaseReferenceExpression(), "GetHashCode", new CodeExpression[] { }))); entity.Members.Add(method); //sb.Append("\t\tpublic override bool Equals(object obj)\r\n\t\t{\r\n\t\t\treturn obj == null || (!(obj is " + entityOutputTypeName + ")) ? false : ((object)this) == ((object)obj) ? true : this.isAttached && ((" + entityOutputTypeName + ")obj).isAttached"); method = new CodeMemberMethod(); method.Name = "Equals"; method.Attributes = MemberAttributes.Public | MemberAttributes.Override; method.ReturnType = new CodeTypeReference(typeof(bool)); method.Parameters.Add(new CodeParameterDeclarationExpression(typeof(object), "obj")); //if (obj == null) return false; //if ((obj is global::Entities.LocalUser) == false) return false; //if (((object)this) == ((object)obj)) return true; //return this.isAttached && ((global::Entities.LocalUser)obj).isAttached && this.ID == ((global::Entities.LocalUser)obj).ID; method.Statements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodeArgumentReferenceExpression("obj"), CodeBinaryOperatorType.IdentityEquality, new CodePrimitiveExpression(null)), new CodeStatement[] { new CodeMethodReturnStatement(new CodePrimitiveExpression(false)) })); method.Statements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodePrimitiveExpression(false), CodeBinaryOperatorType.ValueEquality, new CodeMethodInvokeExpression(new CodeTypeOfExpression(entityOutputTypeNameRef), "IsAssignableFrom", new CodeExpression[] { new CodeMethodInvokeExpression(new CodeArgumentReferenceExpression("obj"), "GetType", new CodeExpression[] { }) })), new CodeStatement[] { new CodeMethodReturnStatement(new CodePrimitiveExpression(false)) })); method.Statements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodeCastExpression(typeof(object), new CodeThisReferenceExpression()), CodeBinaryOperatorType.IdentityEquality, new CodeCastExpression(typeof(object), new CodeArgumentReferenceExpression("obj"))), new CodeStatement[] { new CodeMethodReturnStatement(new CodePrimitiveExpression(true)) })); method.Statements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(false))); //sb.Append(";\r\n\t\t}\r\n"); entity.Members.Add(method); //sb.Append("\r\n\t\t#endregion\r\n\r\n"); CodeTypeDeclaration queryClass = new CodeTypeDeclaration(); queryClass.IsClass = true; queryClass.Name = outLang == 0 ? "_" : "__"; queryClass.Attributes = MemberAttributes.Public | MemberAttributes.Static; if (findNonEntityBaseEntity) { queryClass.Attributes |= MemberAttributes.New; } entity.Members.Add(queryClass); generatedProperties.Clear(); #region 添加All字段 if (interfaces.Length == 0) { CodeMemberField field = new CodeMemberField(); field.Name = "All"; field.Attributes = MemberAttributes.Public | MemberAttributes.Static; field.Type = new CodeTypeReference(typeof(AllField)); //new CodeTypeReference(type.Name, reference = new CodeTypeReference(typeof(AllField).FullName, new CodeTypeReference(type.Name, CodeTypeReferenceOptions.GenericTypeParameter)); field.InitExpression = new CodeObjectCreateExpression(reference); //添加注释 field.Comments.Add(new CodeCommentStatement("<summary>", true)); field.Comments.Add(new CodeCommentStatement("表示选择所有列,与*等同", true)); field.Comments.Add(new CodeCommentStatement("</summary>", true)); queryClass.Members.Add(field); } #endregion GenPropertyQueryCodeEx(queryClass, type, generatedProperties, isReadonly); }
public override void Initialize(CodeFileGenerator fileGenerator) { base.Initialize(fileGenerator); //Throw in NUnit base.Namespace.Imports.Add(new CodeNamespaceImport("NUnit.Framework")); //Declare test suite class var testSuitDeclaration = new CodeTypeDeclaration { Name = _testSuiteData.Name + "TestSuite", IsClass = true, }; //Adding text fixture attribute testSuitDeclaration.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference("TestFixture"))); foreach (var scenario in _testSuiteData.Scenarios) { var isMultiinstance = _elementData.IsMultiInstance; var useParameter = !String.IsNullOrEmpty(scenario.CommandData.RelatedTypeName); const string controllerVariableName = "controller"; const string argumentVariableName = "argument"; const string senderVariableName = "sender"; //Setup scenario method var testMethod = new CodeMemberMethod { Name = scenario.Name.Replace(" ", "_"), Attributes = MemberAttributes.Public, }; testMethod.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference("Test"))); //Create controller instance + comment var controllerDeclaractionComment = new CodeCommentStatement("GIVEN: setup your environment here"); var contollerDeclaractionStatement = new CodeVariableDeclarationStatement( new CodeTypeReference(_elementData.NameAsController), controllerVariableName, new CodeObjectCreateExpression(_elementData.NameAsController)); testMethod.Statements.Add(new CodeSnippetStatement("")); testMethod.Statements.Add(controllerDeclaractionComment); testMethod.Statements.Add(contollerDeclaractionStatement); //Create viewmodel if multiinstance if (isMultiinstance) { var viewModelDeclaration = new CodeVariableDeclarationStatement( new CodeTypeReference(_elementData.NameAsViewModel), senderVariableName, new CodeObjectCreateExpression( new CodeTypeReference(_elementData.NameAsViewModel), new CodeSnippetExpression(controllerVariableName))); testMethod.Statements.Add(viewModelDeclaration); } //Create parameter if needed if (useParameter) { CodeVariableDeclarationStatement argumentDeclaration = null; var viewModel = _elementData.OwnerData.GetViewModel(scenario.CommandData.RelatedTypeName); if (viewModel == null) argumentDeclaration = new CodeVariableDeclarationStatement( new CodeTypeReference(scenario.CommandData.RelatedTypeName), argumentVariableName, new CodeDefaultValueExpression(new CodeTypeReference(scenario.CommandData.RelatedTypeName)) ); else argumentDeclaration = new CodeVariableDeclarationStatement( new CodeTypeReference(viewModel.NameAsViewModel), argumentVariableName, new CodeDefaultValueExpression(new CodeTypeReference(viewModel.NameAsViewModel))); testMethod.Statements.Add(argumentDeclaration); } //Create invocation to the controller + comment var commandInvocationComment = new CodeCommentStatement("WHEN: call to the command"); var commandInvocation = new CodeMethodInvokeExpression( new CodeSnippetExpression(controllerVariableName), scenario.CommandData.Name); if(isMultiinstance) commandInvocation.Parameters.Add(new CodeSnippetExpression(senderVariableName)); if(useParameter) commandInvocation.Parameters.Add(new CodeSnippetExpression(argumentVariableName)); testMethod.Statements.Add(new CodeSnippetStatement("")); testMethod.Statements.Add(commandInvocationComment); testMethod.Statements.Add(commandInvocation); //Create template assertion + comment var assertionComment = new CodeCommentStatement("THEN: Assert anything here"); var assertionInvocation = new CodeSnippetExpression("Assert.That(true)"); testMethod.Statements.Add(new CodeSnippetStatement("")); testMethod.Statements.Add(assertionComment); testMethod.Statements.Add(assertionInvocation); testSuitDeclaration.Members.Add(testMethod); } base.Namespace.Types.Add(testSuitDeclaration); }
private void AddTestTheResultShouldbeTheExpectedOne(CodeTypeDeclaration targetClass, string methodName, CodeExpression[] methodParameters, Type targetType) { // generate test method name CodeMemberMethod testMethod = CreateTestMethodSignature(methodName, "ResultShouldHaveExpectedValue"); // ACT, create the method invocation statement CodeExpression invokeMethodExpression = new CodeExpression(); var targetTypeConstrucor = targetType.GetConstructors() .Where(c => c.GetParameters().Length != 0).FirstOrDefault(); CodeExpression[] ctorParams = _inputParamGenerator.ResolveInputParametersForCtorOrMethod( targetTypeConstrucor.GetParameters().Length, targetTypeConstrucor.GetParameters(), testMethod); CodeObjectCreateExpression mthodInvokeTargetObject = new CodeObjectCreateExpression(targetType.FullName, ctorParams); // declare the target object CodeVariableDeclarationStatement assignTargetObjectToVariable = new CodeVariableDeclarationStatement( targetType, targetType.Name.ToLower(), mthodInvokeTargetObject); testMethod.Statements.Add(assignTargetObjectToVariable); invokeMethodExpression = new CodeMethodInvokeExpression( // targetObject that contains the method to invoke. new CodeVariableReferenceExpression(targetType.Name.ToLower()), methodName, // methodName indicates the method to invoke. methodParameters); // parameters array contains the parameters for the method. // declare result variable CodeVariableDeclarationStatement assignMethodInvocatonResult = new CodeVariableDeclarationStatement( typeof(object), "result", invokeMethodExpression); testMethod.Statements.Add(assignMethodInvocatonResult); // ASSERT, create the result not null assertion statement CodeExpressionStatement assertNotNullStatement = new CodeExpressionStatement(); CodeExpression[] assertNotNullParameters = new CodeExpression[2]; assertNotNullParameters[0] = new CodeVariableReferenceExpression("result"); assertNotNullParameters[1] = new CodeSnippetExpression("new { }"); CodeComment comment = new CodeComment("Please insert here the expected result", false); CodeCommentStatement commentStatement = new CodeCommentStatement(comment); testMethod.Statements.Add(commentStatement); assertNotNullStatement.Expression = new CodeMethodInvokeExpression( new CodeTypeReferenceExpression("Assert"), // targetObject that contains the method to invoke. "AreEqual", // methodName indicates the method to invoke. assertNotNullParameters); // parameters array contains the parameters for the method. // add the above created expressions to the testMethod testMethod.Statements.Add(assertNotNullStatement); targetClass.Members.Add(testMethod); }
virtual protected void WriteSnippetExpression(CodeSnippetExpression e) { _writer.Write(e.Value); }
public void AppendCodeSnippetExpression(CodeMemberMethod method, string code) { CodeSnippetExpression snippetExpresion = new CodeSnippetExpression(code); method.Statements.Add(snippetExpresion); }
protected override void GenerateSnippetExpression(CodeSnippetExpression e) { }
private static CodeTypeDeclaration GenerateDelegatesClass(List <CodeTypeDelegate> delegates) { CodeTypeDeclaration delegate_class = new CodeTypeDeclaration("Delegates"); delegate_class.TypeAttributes = System.Reflection.TypeAttributes.NotPublic; CodeStatementCollection statements = new CodeStatementCollection(); foreach (CodeTypeDelegate d in delegates) { // Hack - turn FieldDirection.Out parameters to FieldDirection.In. The parameter flow // is handle by the [In, Out()] parameter attribute. foreach (CodeParameterDeclarationExpression p in d.Parameters) { p.Direction = FieldDirection.In; } delegate_class.Members.Add(d); CodeMemberField m = new CodeMemberField(); m.Name = "gl" + d.Name; m.Type = new CodeTypeReference(d.Name); m.Attributes = MemberAttributes.Public | MemberAttributes.Static; //m.InitExpression = //new CodeCastExpression( // "Delegates." + d.Name, // new CodeMethodInvokeExpression( // new CodeMethodReferenceExpression( // new CodeTypeReferenceExpression(Properties.Bind.Default.OutputClass), // "GetDelegateForExtensionMethod" // ), // new CodeExpression[] { // new CodeSnippetExpression("\"gl" + d.Name + "\""), // new CodeTypeOfExpression("Delegates." + d.Name) // } // ) //); // Hack - generate inline initialisers in the form: // public static Accum glAccum = GetDelegate[...] ?? new Accum(Imports.Accum); CodeSnippetExpression expr = new CodeSnippetExpression(); //expr.Value = "public static " + d.Name + " gl" + d.Name + " = "; expr.Value += "((" + d.Name + ")(Gl.GetDelegateForExtensionMethod(\"" + "gl" + d.Name + "\", typeof(" + d.Name + "))))"; if (d.UserData.Contains("Extension") && !(bool)d.UserData["Extension"]) { expr.Value += " ?? "; expr.Value += "new " + d.Name + "(Imports." + d.Name + ")"; } m.InitExpression = expr; delegate_class.Members.Add(m); /* * if (!(bool)d.UserData["Extension"]) * { * statements.Add( * new CodeSnippetExpression( * "Delegates.gl" + d.Name + " = Delegates.gl" + d.Name + " ?? new Delegates." + d.Name + "(Imports." + d.Name + ")" * ) * ); * } */ } // Disable BeforeFieldInit attribute and initialize OpenGL core. CodeTypeConstructor con = new CodeTypeConstructor(); //con.Statements.AddRange(statements); delegate_class.Members.Add(con); delegate_class.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, delegate_class.Name)); delegate_class.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, delegate_class.Name)); return(delegate_class); }