public override CodeFieldReferenceExpression GenerateCodeDom(ICodeDOMTranslationOptions options) { CodeFieldReferenceExpression fieldRef = new CodeFieldReferenceExpression(); fieldRef.TargetObject = Reference.GenerateCodeDom(options); fieldRef.FieldName = this.Name; return(fieldRef); }
public override CodeVariableReferenceExpression GenerateCodeDom(ICodeDOMTranslationOptions options) { if (options.NameHandler.HandlesName(this.referencePoint)) { return(new CodeVariableReferenceExpression(options.NameHandler.HandleName(this.referencePoint))); } return(new CodeVariableReferenceExpression(this.Name)); }
public override CodePropertyReferenceExpression GenerateCodeDom(ICodeDOMTranslationOptions options) { CodePropertyReferenceExpression propRef = new CodePropertyReferenceExpression(); propRef.TargetObject = Reference.GenerateCodeDom(options); propRef.PropertyName = this.Name; return(propRef); }
/// <summary> /// Generates the <see cref="CodeConstructor"/> that represents the <see cref="ConstructorMember"/>. /// </summary> /// <param name="options">The CodeDOM generator options that directs the generation /// process.</param> /// <returns>A new instance of a <see cref="CodeConstructor"/> if successful.-null- otherwise.</returns> public override CodeConstructor GenerateCodeDom(ICodeDOMTranslationOptions options) { if (options.BuildTrail != null) { options.BuildTrail.Push(this); } CodeConstructor result = new CodeConstructor(); /* * * Most collections in the OIL framework have Generate Code Dom * functionality; as such, simply add the custom attributes, * parameters, and statements of the constructor member. * */ result.CustomAttributes = this.Attributes.GenerateCodeDom(options); result.Parameters.AddRange(this.Parameters.GenerateCodeDom(options)); result.Statements.AddRange(this.Statements.GenerateCodeDom(options)); //Next insert the cascade parameters, if the target is defined. switch (this.CascadeExpressionsTarget) { case ConstructorCascadeTarget.Undefined: break; case ConstructorCascadeTarget.This: /* * * If they need to call another constructor with no arguments * use a null snippet expression, otherwise just insert the * expressions collection. * */ if (this.CascadeMembers.Count > 0) { result.ChainedConstructorArgs.AddRange(this.CascadeMembers.GenerateCodeDom(options)); } else { result.ChainedConstructorArgs.Add(new CodeSnippetExpression("")); } break; case ConstructorCascadeTarget.Base: //Same as above, but this time insert it into the base //constructor args. if (this.CascadeMembers.Count > 0) { result.BaseConstructorArgs.AddRange(this.CascadeMembers.GenerateCodeDom(options)); } else { result.BaseConstructorArgs.Add(new CodeSnippetExpression("")); } break; } result.Attributes = AccessLevelAttributes(this.AccessLevel); if (options.BuildTrail != null) { options.BuildTrail.Pop(); } return(result); }
public CodeNamespace[] GenerateCodeDom(ICodeDOMTranslationOptions options) { List <CodeNamespace> result = new List <CodeNamespace>(); foreach (INameSpaceDeclaration nameSpace in this.Values) { result.AddRange(nameSpace.GenerateGroupCodeDom(options)); } return(result.ToArray()); }
public override CodePropertyReferenceExpression GenerateCodeDom(ICodeDOMTranslationOptions options) { CodePropertyReferenceExpression result = base.GenerateCodeDom(options); if (options.NameHandler.HandlesName(this.referencePoint)) { result.PropertyName = options.NameHandler.HandleName(this.referencePoint); } return(result); }
public CodeExpression[] GenerateCodeDom(ICodeDOMTranslationOptions options) { List <CodeExpression> result = new List <CodeExpression>(this.Count); foreach (IExpression expression in this) { result.Add(expression.GenerateCodeDom(options)); } return(result.ToArray()); }
public CodeAttributeDeclarationCollection GenerateCodeDom(ICodeDOMTranslationOptions options) { List <CodeAttributeDeclaration> result = new List <CodeAttributeDeclaration>(); foreach (IAttributeDeclaration ia in this) { result.Add(ia.GenerateCodeDom(options)); } return(new CodeAttributeDeclarationCollection(result.ToArray())); }
private string GetPartialTypeName(ICodeDOMTranslationOptions options) { System.Type[] nestingChain = GetNestChain(); string[] nestNames = new string[nestingChain.Length]; for (int i = 0; i < nestingChain.Length; i++) { nestNames[i] = nestingChain[i].Name; } return(string.Join("+", nestNames)); }
public override CodeMethodReturnStatement GenerateCodeDom(ICodeDOMTranslationOptions options) { if (result == null) { return(new CodeMethodReturnStatement()); } else { return(new CodeMethodReturnStatement(result.GenerateCodeDom(options))); } }
/// <summary> /// Returns the <see cref="CodeTypeReference"/> which links back to the /// <see cref="TypeInstance"/>. /// </summary> /// <returns>A <see cref="CodeTypeReference"/> which links back to the <see cref="TypeInstance"/>.</returns> public virtual CodeTypeReference GenerateCodeDom(ICodeDOMTranslationOptions options) { if (this.ArrayElementType != null && this.ArrayRank > 0) { return(new CodeTypeReference(this.ArrayElementType.GenerateCodeDom(options), this.ArrayRank)); } else { CodeTypeReference ctr = new CodeTypeReference(); CodeTypeReference n = null; if (nullable) { n = new CodeTypeReference(typeof(Nullable <>)); } bool autoResolve = false; if ((this.resolutionOptions & TypeReferenceResolveOptions.GlobalType) == TypeReferenceResolveOptions.GlobalType) { ctr.Options |= CodeTypeReferenceOptions.GlobalReference; } if ((this.resolutionOptions & TypeReferenceResolveOptions.FullType) == TypeReferenceResolveOptions.FullType || (this.resolutionOptions & TypeReferenceResolveOptions.GlobalType) == TypeReferenceResolveOptions.GlobalType) { autoResolve = options.AutoResolveReferences; if (autoResolve) { options.AutoResolveReferences = false; } } if ((this.resolutionOptions & TypeReferenceResolveOptions.TypeParameter) == TypeReferenceResolveOptions.TypeParameter) { ctr.Options |= CodeTypeReferenceOptions.GenericTypeParameter; } ctr.BaseType = this.TypeInstance.GetTypeName(options, TypeParameters.ToArray()); if (autoResolve && ((this.resolutionOptions & TypeReferenceResolveOptions.FullType) == TypeReferenceResolveOptions.FullType || (this.resolutionOptions & TypeReferenceResolveOptions.GlobalType) == TypeReferenceResolveOptions.GlobalType)) { options.AutoResolveReferences = autoResolve; } //Clear auto-inferred entries. ctr.TypeArguments.Clear(); foreach (ITypeReference itr in this.TypeParameters) { if (itr != null) { ctr.TypeArguments.Add(itr.GenerateCodeDom(options)); } } if (nullable) { n.TypeArguments.Add(ctr); ctr = n; } //Pointers: Not supported by CodeDOM. return(ctr); } }
/// <summary> /// Generates the <typeparamref name="TDom"/> that represents the <see cref="SegmentableParameteredType{TItem, TDom, TPartials}"/>. /// </summary> /// <returns>A new instance of a <typeparamref name="TDom"/> if successful.-null- otherwise.</returns> public override TDom GenerateCodeDom(ICodeDOMTranslationOptions options) { TDom result = base.GenerateCodeDom(options); if (options.AllowPartials && (this.IsPartial || (this.IsRoot && this.Partials.Count > 0))) { result.IsPartial = true; } return(result); }
public override CodeArrayIndexerExpression GenerateCodeDom(ICodeDOMTranslationOptions options) { CodeArrayIndexerExpression caie = base.GenerateCodeDom(options); caie.TargetObject = target.GenerateCodeDom(options); if (this.indices != null) { caie.Indices.AddRange(this.Indices.GenerateCodeDom(options)); } return(caie); }
public virtual TDom[] GenerateCodeDom(ICodeDOMTranslationOptions options) { TDom[] result = new TDom[this.Count]; TItem[] items = new TItem[this.Count]; this.Values.CopyTo(items, 0); for (int i = 0; i < this.Count; i++) { result[i] = items[i].GenerateCodeDom(options); } return(result); }
public override CodeLabeledStatement GenerateCodeDom(ICodeDOMTranslationOptions options) { if (options.NameHandler != null && options.NameHandler.HandlesName(this.Name)) { return(new CodeLabeledStatement(options.NameHandler.HandleName(this.Name))); } else { return(new CodeLabeledStatement(this.name)); } }
public override CodeConditionStatement GenerateCodeDom(ICodeDOMTranslationOptions options) { CodeConditionStatement result = new CodeConditionStatement(); result.TrueStatements.AddRange(base.Statements.GenerateCodeDom(options)); if (this.falseStatements != null && this.falseStatements.Count > 0) { result.FalseStatements.AddRange(this.FalseBlock.GenerateCodeDom(options)); } result.Condition = this.Condition.GenerateCodeDom(options); return(result); }
public override CodeMemberField GenerateCodeDom(ICodeDOMTranslationOptions options) { if (options.BuildTrail != null) { options.BuildTrail.Push(this); } CodeMemberField result = new CodeMemberField(); result.CustomAttributes = this.Attributes.GenerateCodeDom(options); result.Type = this.FieldType.GenerateCodeDom(options); if (this.IsConstant) { result.Attributes = MemberAttributes.Const; } else if (this.IsStatic) { result.Attributes = MemberAttributes.Static; } else { result.Attributes = MemberAttributes.Final; } result.Attributes |= AccessLevelAttributes(this.AccessLevel); if (this.HidesPrevious) { result.Attributes |= MemberAttributes.New; } if (options.NameHandler.HandlesName(this)) { result.Name = options.NameHandler.HandleName(this); } else { result.Name = this.Name; } if (this.summary != null && this.summary != string.Empty) { result.Comments.Add(new CodeCommentStatement(new CodeComment(this.summary, true))); } if (this.remarks != null && this.remarks != string.Empty) { result.Comments.Add(new CodeCommentStatement(new CodeComment(this.remarks, true))); } if (this.InitializationExpression != null) { result.InitExpression = this.InitializationExpression.GenerateCodeDom(options); } if (options.BuildTrail != null) { options.BuildTrail.Pop(); } return(result); }
public CodeCompileUnit GenerateCodeDom(ICodeDOMTranslationOptions options) { CodeCompileUnit ccu = new CodeCompileUnit(); ProjectDependencyReport pdr = new ProjectDependencyReport(this, options); ccu.ReferencedAssemblies.AddRange(Tweaks.TranslateArray <Assembly, string>(pdr.CompiledAssemblyReferences.ToArray(), delegate(Assembly a) { return(a.Location); })); ccu.Namespaces.AddRange(this.NameSpaces.GenerateCodeDom(options)); return(ccu); }
public override CodeSnippetStatement GenerateCodeDom(ICodeDOMTranslationOptions options) { if (options.LanguageProvider != null) { if (options.LanguageProvider is CSharpCodeProvider) { return(new CodeSnippetStatement(this.ConvertToString(TranslationLanguage.CSharp))); } //else if (options.LanguageProvider is VBCodeProvider) // return new CodeSnippetStatement(this.ConvertToString(TranslationLanguage.VisualBasic)); } return(new CodeSnippetStatement(this.ConvertToString(TranslationLanguage.CSharp) + " /* Unknown language. */")); }
public override CodeMemberProperty GenerateCodeDom(ICodeDOMTranslationOptions options) { if (options.BuildTrail != null) { options.BuildTrail.Push(this); } CodeMemberProperty result = base.GenerateCodeDom(options); result.Parameters.AddRange(this.Parameters.GenerateCodeDom(options)); if (options.BuildTrail != null) { options.BuildTrail.Pop(); } return(result); }
/// <summary> /// Generates the <see cref="CodeTypeDeclaration"/> that represents the <see cref="StructType"/>. /// </summary> /// <returns>A new instance of a <see cref="CodeTypeDeclaration"/> if successful.-null- otherwise.</returns> public override CodeTypeDeclaration GenerateCodeDom(ICodeDOMTranslationOptions options) { if (options.BuildTrail != null) { options.BuildTrail.Push(this); } CodeTypeDeclaration result = base.GenerateCodeDom(options); ITypeReference[] impls = this.ImplementsList.ToArray(); bool[] duplicate = new bool[impls.Length]; List <string> names = new List <string>(); for (int i = 0; i < impls.Length; i++) { string currentName = impls[i].TypeInstance.GetTypeName(options); if (impls[i].TypeParameters.Count > 0 && impls[i].TypeInstance.IsGeneric) { currentName += string.Format("`{0}", impls[i].TypeParameters.Count); } duplicate[i] = names.Contains(currentName); if (duplicate[i]) { duplicate[names.IndexOf(currentName)] = true; } names.Add(currentName); } bool autoResolve = options.AutoResolveReferences; for (int i = 0; i < impls.Length; i++) { ITypeReference typeRef = impls[i]; if (duplicate[i] && autoResolve) { options.AutoResolveReferences = false; } result.BaseTypes.Add(typeRef.GenerateCodeDom(options)); if (duplicate[i] && autoResolve) { options.AutoResolveReferences = autoResolve; } } result.IsStruct = true; if (options.BuildTrail != null) { options.BuildTrail.Pop(); } return(result); }
internal static string GenerateExpressionSnippet(ICodeDOMTranslationOptions options, CodeExpression codeExpression) { BufferArea.SetLength(0); BufferArea.Seek(0, SeekOrigin.Begin); if (options.LanguageProvider != null) { options.LanguageProvider.GenerateCodeFromExpression(codeExpression, BufferWriter, DefaultDOMOptions); } else { DefaultCSharpCodeProvider.GenerateCodeFromExpression(codeExpression, BufferWriter, DefaultDOMOptions); } BufferWriter.Flush(); BufferArea.Seek(0, SeekOrigin.Begin); return(BufferReader.ReadToEnd()); }
internal static string GenerateMemberSnippet(ICodeDOMTranslationOptions options, CodeTypeMember codeMember) { BufferArea.SetLength(0); BufferArea.Seek(0, SeekOrigin.Begin); if (options.LanguageProvider != null) { options.LanguageProvider.GenerateCodeFromMember(codeMember, BufferWriter, _OIL._Core.DefaultDOMOptions); } else { DefaultCSharpCodeProvider.GenerateCodeFromMember(codeMember, BufferWriter, _OIL._Core.DefaultDOMOptions); } BufferWriter.Flush(); BufferArea.Seek(0, SeekOrigin.Begin); return(BufferReader.ReadToEnd()); }
public override CodeTypeDeclaration GenerateCodeDom(ICodeDOMTranslationOptions options) { if (options.BuildTrail != null) { options.BuildTrail.Push(this); } CodeTypeDeclaration ctd = base.GenerateCodeDom(options); ctd.IsEnum = true; ctd.Members.AddRange(this.Fields.GenerateCodeDom(options)); switch (this.BaseType) { case EnumeratorBaseType.UByte: ctd.BaseTypes.Add(typeof(byte)); break; case EnumeratorBaseType.SByte: ctd.BaseTypes.Add(typeof(sbyte)); break; case EnumeratorBaseType.UShort: ctd.BaseTypes.Add(typeof(ushort)); break; case EnumeratorBaseType.Short: ctd.BaseTypes.Add(typeof(short)); break; case EnumeratorBaseType.UInt: ctd.BaseTypes.Add(typeof(uint)); break; case EnumeratorBaseType.ULong: ctd.BaseTypes.Add(typeof(ulong)); break; case EnumeratorBaseType.SLong: ctd.BaseTypes.Add(typeof(long)); break; } if (options.BuildTrail != null) { options.BuildTrail.Pop(); } return(ctd); }
public CodeNamespace[] GenerateGroupCodeDom(ICodeDOMTranslationOptions options) { List <CodeNamespace> result = new List <CodeNamespace>(); CodeNamespace cnsThisResult = this.GenerateCodeDom(options); if (cnsThisResult != null) { result.Add(cnsThisResult); } foreach (INameSpaceDeclaration ind in this.ChildSpaces.Values) { CodeNamespace[] childSpaces; if (!options.AllowPartials) { //Auto-flattens hierarchhy. childSpaces = ind.GenerateGroupCodeDom(options); } else { //There's extra work to do. List <CodeNamespace> childSpacesList = new List <CodeNamespace>(); if (ind.ParentTarget == this) { childSpacesList.AddRange(ind.GenerateGroupCodeDom(options)); } foreach (INameSpaceDeclaration indPartial in ind.Partials) { if (indPartial.ParentTarget == this) { childSpacesList.AddRange(indPartial.GenerateGroupCodeDom(options)); } } childSpaces = childSpacesList.ToArray(); } for (int i = 0; i < childSpaces.Length; i++) { if (childSpaces[i] != null) { result.Add(childSpaces[i]); } } } return(result.ToArray()); }
public override CodeMethodReferenceExpression GenerateCodeDom(ICodeDOMTranslationOptions options) { CodeMethodReferenceExpression cmreResult = base.GenerateCodeDom(options); if (options.NameHandler.HandlesName(this.name)) { cmreResult.MethodName = options.NameHandler.HandleName(this.name); } else { cmreResult.MethodName = this.Name; } cmreResult.TargetObject = this.Reference.GenerateCodeDom(options); foreach (ITypeReference itr in this.TypeArguments) { cmreResult.TypeArguments.Add(itr.GenerateCodeDom(options)); } return(cmreResult); }
/// <summary> /// Generates the <see cref="CodeTypeDelegate"/> that represents the <see cref="DelegateType"/>. /// </summary> /// <returns>A new instance of a <see cref="CodeTypeDelegate"/> if successful.-null- otherwise.</returns> public override CodeTypeDelegate GenerateCodeDom(ICodeDOMTranslationOptions options) { if (options.BuildTrail != null) { options.BuildTrail.Push(this); } CodeTypeDelegate result = base.GenerateCodeDom(options); result.Parameters.AddRange(this.Parameters.GenerateCodeDom(options)); if (this.returnType != null) { result.ReturnType = this.ReturnType.GenerateCodeDom(options); } if (options.BuildTrail != null) { options.BuildTrail.Pop(); } return(result); }
public override CodeStatement[] GenerateCodeDom(ICodeDOMTranslationOptions options) { List <CodeStatement> result = new List <CodeStatement>(); CodeVariableReferenceExpression varRef = TerminalVariable.GetReference().GenerateCodeDom(options); result.Add(new CodeSnippetStatement()); if (this.condition != null) { result.Add(new CodeAssignStatement(varRef, this.condition.GenerateCodeDom(options))); result.Add(new CodeConditionStatement(varRef, new CodeCommentStatement("break;"), ExitSymbol.GetCodeDomGoTo())); } else { result.Add(new CodeCommentStatement("break;")); result.Add(ExitSymbol.GetCodeDomGoTo()); } return(result.ToArray()); }
public override CodeArrayCreateExpression GenerateCodeDom(ICodeDOMTranslationOptions options) { CodeArrayCreateExpression result = new CodeArrayCreateExpression(); result.CreateType = this.ArrayType.GenerateCodeDom(options); if (this.initializers != null && this.initializers.Count > 0) { result.Initializers.AddRange(this.initializers.GenerateCodeDom(options)); } if (this.sizeExpression != null) { result.SizeExpression = this.sizeExpression.GenerateCodeDom(options); } else { result.Size = this.size; } return(result); }
public override CodeIterationStatement GenerateCodeDom(ICodeDOMTranslationOptions options) { #if LIGHT_CORE IEnumeratorExp enumMemberExp; enumMemberExp = new IEnumeratorExp(enumMember.GetReference()); #endif CodeIterationStatement result = new CodeIterationStatement(); result.Statements.Add(new CodeCommentStatement(String.Format("foreach ({0} {1} in {2})", this.currentMember.LocalType.TypeInstance.GetTypeName(options), this.enumMember.Name, _OIL._Core.GenerateExpressionSnippet(options, this.enumeratorSource.GenerateCodeDom(options))))); #if LIGHT_CORE //LIGHT_CORE result.InitStatement = this.enumMember.GetDeclarationStatement().GenerateCodeDom(options); result.TestExpression = enumMemberExp.MoveNext().GenerateCodeDom(options); #else result.TestExpression = enumMember.GetReference().GetMethod("MoveNext").Invoke().GenerateCodeDom(options); #endif result.IncrementStatement = new CodeSnippetStatement(""); result.Statements.AddRange(this.Statements.GenerateCodeDom(options)); return(result); }