public static CSMethod PInvoke(CSVisibility vis, CSType type, string name, CSBaseExpression dllName, string externName, CSParameterList parms) { CSMethod method = new CSMethod(vis, CSMethodKind.StaticExtern, Exceptions.ThrowOnNull(type, "type"), new CSIdentifier(name), parms, null); CSAttribute.DllImport(dllName, externName).AttachBefore(method); return(method); }
static LineCodeElementCollection <ICodeElement> MakeEtter(CSVisibility vis, string getset, bool unifiedVis, bool moreRestrictiveVis) { LineCodeElementCollection <ICodeElement> getLine = new LineCodeElementCollection <ICodeElement> (null, false, true); if (!unifiedVis && vis != CSVisibility.None && moreRestrictiveVis) { getLine.And(new SimpleElememt(CSMethod.VisibilityToString(vis))).And(SimpleElememt.Spacer); } return(getLine.And(new SimpleElememt(getset, false))); }
protected override void LLWrite(ICodeWriter writer, object o) { writer.BeginNewLine(true); writer.Write(CSMethod.VisibilityToString(Visibility), false); writer.Write(" delegate ", true); Type.WriteAll(writer); writer.Write(' ', true); Name.WriteAll(writer); writer.Write('(', true); Parameters.WriteAll(writer); writer.Write(')', true); writer.Write(';', false); writer.EndLine(); }
public CSFieldDeclaration(CSType type, IEnumerable <CSBinding> bindings, CSVisibility vis = CSVisibility.None, bool isStatic = false, bool isReadonly = false) : base(type, bindings) { Visibilty = vis; IsStatic = isStatic; if (isReadonly) { this.Insert(0, new SimpleElememt("readonly")); this.Insert(1, SimpleElememt.Spacer); } if (isStatic) { this.Insert(0, new SimpleElememt("static")); this.Insert(1, SimpleElememt.Spacer); } if (vis != CSVisibility.None) { this.Insert(0, new SimpleElememt(CSMethod.VisibilityToString(vis))); this.Insert(1, SimpleElememt.Spacer); } }
CSProperty(CSType type, CSMethodKind kind, CSIdentifier name, CSVisibility getVis, CSCodeBlock getter, CSVisibility setVis, CSCodeBlock setter, CSParameterList parms) { bool unifiedVis = getVis == setVis; IndexerParameters = parms; LineCodeElementCollection <ICodeElement> decl = new LineCodeElementCollection <ICodeElement> (null, false, true); GetterVisibility = getVis; SetterVisibility = setVis; CSVisibility bestVis = (CSVisibility)Math.Min((int)getVis, (int)setVis); decl.And(new SimpleElememt(CSMethod.VisibilityToString(bestVis))).And(SimpleElememt.Spacer); if (kind != CSMethodKind.None) { decl.And(new SimpleElememt(CSMethod.MethodKindToString(kind))).And(SimpleElememt.Spacer); } PropType = type; Name = name; decl.And(Exceptions.ThrowOnNull(type, "type")).And(SimpleElememt.Spacer) .And(Exceptions.ThrowOnNull(name, nameof(name))); if (parms != null) { decl.And(new SimpleElememt("[", true)).And(parms).And(new SimpleElememt("]")); } Add(decl); CSCodeBlock cb = new CSCodeBlock(null); if (getter != null) { Getter = getter; LineCodeElementCollection <ICodeElement> getLine = MakeEtter(getVis, "get", unifiedVis, getVis > setVis); cb.Add(getLine); if (getter.Count() == 0) { getLine.Add(new SimpleElememt(";")); } else { cb.Add(getter); } } if (setter != null) { Setter = setter; LineCodeElementCollection <ICodeElement> setLine = MakeEtter(setVis, "set", unifiedVis, setVis > getVis); cb.Add(setLine); if (setter.Count() == 0) { setLine.Add(new SimpleElememt(";")); } else { cb.Add(setter); } } Add(cb); }
public static CSMethod RemoveGenerics(CSMethod from) { var newMethod = new CSMethod(from.Visibility, from.Kind, from.Type, from.Name, from.Parameters, from.Body); return(newMethod); }
public static CSMethod CopyGenerics(CSMethod from, CSMethod to) { to.GenericParameters.AddRange(from.GenericParameters); to.GenericConstraints.AddRange(from.GenericConstraints); return(to); }
public CSMethod AsPrivate() { var privateMethod = new CSMethod(CSVisibility.None, Kind, Type, Name, Parameters, BaseOrThisCallParameters, CallsBase, Body, IsSealed); return(CopyGenerics(this, privateMethod)); }
public CSMethod AsOverride() { var overrideMethod = new CSMethod(Visibility, CSMethodKind.Override, Type, Name, Parameters, BaseOrThisCallParameters, CallsBase, Body, IsSealed); return(CopyGenerics(this, overrideMethod)); }
public CSMethod AsSealed() { var sealedMethod = new CSMethod(Visibility, Kind, Type, Name, Parameters, BaseOrThisCallParameters, CallsBase, Body, true); return(CopyGenerics(this, sealedMethod)); }