public override string GetAccessString(AccessModifier access, bool forCode) { switch (access) { case AccessModifier.ProtectedInternal: if (forCode) { return("protected internal"); } return("Protected Internal"); case AccessModifier.Default: if (forCode) { return(""); } return("Default"); default: if (forCode) { return(access.ToString().ToLower()); } return(access.ToString()); } }
public static string GetModifier(AccessModifier? access, MemberModifier? modifier) { if (modifier == null) return access.ToString().ToLower(); else return string.Format("{0} {1}", access.ToString().ToLower(), modifier.ToString().ToLower()); }
public override string GetAccessString(AccessModifier access, bool forCode) { switch (access) { case AccessModifier.Default: if (forCode) { return(""); } else { return("Default"); } case AccessModifier.Internal: if (forCode) { return(""); } else { return("Package"); } default: if (forCode) { return(access.ToString().ToLower()); } else { return(access.ToString()); } } }
/// <summary> /// Converts the enum value to its programming language keyword equivalent. /// </summary> public static string ToKeywordString(this AccessModifier am) { switch (am) { case AccessModifier.None: return(string.Empty); case AccessModifier.Public: return("public"); case AccessModifier.ProtectedInternal: return("protected internal"); case AccessModifier.Protected: return("protected"); case AccessModifier.Internal: return("internal"); case AccessModifier.Private: return("private"); default: return(am.ToString()); } }
public static string MethodHeader(int depth, AccessModifier scope, MethodModifier modifier, Type returnType, string name) { var header = string.Empty; string _modifier = modifier.ToString(); string _scope = scope.ToString(); string _returnType = returnType.Name.ToString(); _scope = _scope.AddLowerUpperNeighboringSpaces(); _scope = _scope.ToLower(); _modifier = _modifier.ToLower(); if (modifier == MethodModifier.None) { _modifier = string.Empty; } if (returnType.DeclaringType != returnType || returnType.DeclaringType != typeof(object)) { if (ToLowerReturnTypes.Contains(returnType)) { _returnType = _returnType.ToLower(); } } header += Indent(depth) + _scope + " " + _modifier + " " + _returnType + " " + name + "(" + ")"; return(header); }
//Serialization function. public override void GetObjectData(SerializationInfo info, StreamingContext ctxt) { info.AddValue("_name", Name); info.AddValue("_access_modifier", AccessModifier.ToString()); base.GetObjectData(info, ctxt); //OnSerializing(new SerializeEventArgsBinary(info,ctxt)); }
public override string GenerateCode(int tabulatorsCount) { string content = string.Empty; string tabulators = GenerateTabulations(tabulatorsCount); content += tabulators + CSharpFile.WriteObjects(ClassAttributes, tabulatorsCount); content += tabulators + string.Format( "{0} {1} {2} {3}", AccessModifier.ToString().ToLower(), IsAbstract ? "abstract" : string.Empty, Type.ToString().ToString().ToLower(), Name); if (DerivedFrom != null) { content += DerivedFrom.GenerateCode(0); } content += CSharpFile.NewLine; content += tabulators + CSharpFile.BeginBody; if (cSharpFileElements.Count > 0) { content += CSharpFile.NewLine; content += tabulators + CSharpFile.WriteObjects(cSharpFileElements, tabulatorsCount + 1); } content += tabulators + CSharpFile.EndBody; return(content); }
public async Task BuildAsync(CodeWriter writer) { if (writer is null) { throw new ArgumentNullException(nameof(writer)); } string modifier = _accessModifier.ToString().ToLowerInvariant(); await writer.WriteIndentAsync().ConfigureAwait(false); await writer.WriteAsync($"{modifier} ") .ConfigureAwait(false); if (_isConst) { await writer.WriteAsync("const ").ConfigureAwait(false); } if (_isStatic) { await writer.WriteAsync("static ").ConfigureAwait(false); } if (_isReadOnly) { await writer.WriteAsync("readonly ").ConfigureAwait(false); } await writer.WriteAsync($"{_type} {_name}").ConfigureAwait(false); if (_value is { })
/// <summary> /// Returns a readable string containing the <see cref="AccessModifier"/>. /// </summary> /// <param name="accessModifier">The <see cref="AccessModifier"/> to convert to a string.</param> /// <returns>The converted <see cref="AccessModifier"/></returns> private static string ToString(AccessModifier accessModifier) { if (accessModifier == AccessModifier.Default) { return(""); } return(accessModifier.ToString().ToLower() + " "); }
public async Task BuildAsync(CodeWriter writer) { string modifier = _accessModifier.ToString().ToLowerInvariant(); await writer.WriteIndentAsync().ConfigureAwait(false); await writer.WriteAsync( $"{modifier} {_typeName}(") .ConfigureAwait(false); if (_parameters.Count == 0) { await writer.WriteAsync(")").ConfigureAwait(false); } else if (_parameters.Count == 1) { await _parameters[0].BuildAsync(writer).ConfigureAwait(false); await writer.WriteAsync(")").ConfigureAwait(false); } else { await writer.WriteLineAsync().ConfigureAwait(false); using (writer.IncreaseIndent()) { for (int i = 0; i < _parameters.Count; i++) { await writer.WriteIndentAsync().ConfigureAwait(false); await _parameters[i].BuildAsync(writer).ConfigureAwait(false); if (i == _parameters.Count - 1) { await writer.WriteAsync(")").ConfigureAwait(false); } else { await writer.WriteAsync(",").ConfigureAwait(false); await writer.WriteLineAsync().ConfigureAwait(false); } } } } await writer.WriteLineAsync().ConfigureAwait(false); await writer.WriteIndentedLineAsync("{").ConfigureAwait(false); using (writer.IncreaseIndent()) { foreach (ICode code in _lines) { await code.BuildAsync(writer).ConfigureAwait(false); } } await writer.WriteIndentedLineAsync("}").ConfigureAwait(false); }
/// <summary> /// Create a class header line. Does not include brackets. /// </summary> public static string ClassHeader(int depth, AccessModifier scope, ClassModifier modifier, string @class, List <string> argumentNames) { // Set non string types to strings var header = string.Empty; string _modifier = modifier.ToString(); string _scope = scope.ToString(); // Add white spaces to types such as ProtectedInternal to Protected Internal and set all of it lowercase to match C# construct _scope = _scope.AddLowerUpperNeighboringSpaces(); _scope = _scope.ToLower(); // Do the same as with scope, except we may get addition white spaces for some reason. Remove them here. if (modifier != ClassModifier.None) { _modifier = _modifier.AddLowerUpperNeighboringSpaces(); if (char.IsWhiteSpace(_modifier[_modifier.Length - 1])) { _modifier.Remove(_modifier.Length - 1, 1); } _modifier = _modifier.ToString().ToLower(); } else { _modifier = string.Empty; } // Remove initial white spaces, we will do this ourselves where necessary if (char.IsWhiteSpace(@class[0])) { @class.Remove(0, 1); } header += Indent(depth) + _scope.ToLower() + " class " + _modifier + @class; // We dynamically create the Generics Arguments by manually creating all but the names, which are fed through this method. if (argumentNames != null) { if (argumentNames.Count > 0) { header += "<"; for (int i = 0; i < argumentNames.Count; i++) { header += argumentNames[i]; if (i < argumentNames.Count - 1) { header += ", "; } } header += ">"; } } return(header); }
public static string GetFieldDeclarationLine(AccessModifier accessModifier, string typeName, string fieldName, bool richText) { fieldName = FormatFieldName(accessModifier, fieldName); IFormatProvider format = richText ? _formatProvider : null; return(string.Format(format, "{0:b}{1:t}{2:b}\n{3:m} {4:t} {5:i}", "[", "SerializeField", "]", accessModifier.ToString().ToLower(), typeName, fieldName + ";")); }
public static string AsString(AccessModifier scope) { var output = scope.ToString(); if (scope == AccessModifier.PrivateProtected || scope == AccessModifier.ProtectedInternal) { output = Patcher.AddLowerUpperNeighboringSpaces(output); } return(output.ToLower()); }
/// <exception cref="ArgumentNullException"> /// <paramref name="node"/> is null. /// </exception> internal override void Serialize(XmlNode node) { if (node == null) { throw new ArgumentNullException("node"); } node.RemoveAll(); XmlElement child = node.OwnerDocument.CreateElement("Access"); child.InnerText = AccessModifier.ToString(); node.AppendChild(child); }
public void WriteXml(System.Xml.XmlWriter writer) { XmlSerializer parameterSerializer = new XmlSerializer(typeof(EshuProperty)); writer.WriteAttributeString("Name", Name); writer.WriteAttributeString("AccessModifier", AccessModifier.ToString()); writer.WriteAttributeString("ReturnType", ReturnType); writer.WriteStartElement("Parameters"); foreach (EshuProperty par in Parameters) { parameterSerializer.Serialize(writer, par); } writer.WriteEndElement(); }
protected override void SetupInput() { Input.Values.Add("AccessModifier", AccessModifier.ToString().ToLower()); if (Modifier == Modifiers.None) { Input.Values.Add("ExtraModifiers", ""); } else { Input.Values.Add("ExtraModifiers", Modifier.ToString().ToLower()); } Input.Values.Add("PropertyType", PropertyType); Input.Values.Add("PropertyName", Name); }
public string AccessibilityForType(IAccessibleElement element) { AccessModifier accessModifier = this.ActiveDTOStage ? AccessModifier.Public : element.Access; string accessibility = accessModifier.ToString().ToLowerInvariant(); // if (element is IPropertyBase) // { // if ((element as IPropertyBase).Owner.TypeKind == PersistentTypeKind.Interface) // { // accessibility = string.Empty; // } // } return(accessibility); }
protected override void SetupInput() { Input.Values.Add("AccessModifier", AccessModifier.ToString()); Input.Values.Add("ClassName", ClassName); Input.Values.Add("Body", Body); string TempString = ""; string Splitter = ""; foreach (IParameter Parameter in Parameters) { TempString += Splitter + Parameter.Transform(); Splitter = ","; } Input.Values.Add("ParameterList", TempString); }
private static XAttribute GenerateMethodAccessModifier(MethodAccessModifierAnnotation annotation) { if (annotation == null) { return(null); } AccessModifier methodAccessModifier = annotation.MethodAccessModifier; if (methodAccessModifier == AccessModifier.Unspecified) { return(null); } return(new XAttribute(EdmConstants.CodegenNamespace + "MethodAccess", methodAccessModifier.ToString())); }
public static string Emit(this AccessModifier modifier) { switch (modifier) { case AccessModifier.Private: case AccessModifier.Protected: case AccessModifier.Internal: case AccessModifier.Public: return(modifier.ToString().ToLowerInvariant()); case AccessModifier.ProtectedInternal: return("protected internal"); default: throw new NotSupportedException($"Unrecognised access modifier '{modifier}'"); } }
public async Task CreateConstructor_With_AccessModifier(AccessModifier accessModifier) { // arrange var sb = new StringBuilder(); var writer = new CodeWriter(sb); // act await ConstructorBuilder.New() .SetTypeName("GetAbc") .SetAccessModifier(accessModifier) .AddCode(CodeLineBuilder.New().SetLine("return;")) .BuildAsync(writer); // assert sb.ToString().MatchSnapshot( new SnapshotNameExtension( accessModifier.ToString())); }
/// <exception cref="ArgumentNullException"> /// <paramref name="node"/> is null. /// </exception> protected internal virtual void Serialize(XmlElement node) { if (node == null) { throw new ArgumentNullException("node"); } XmlElement child; child = node.OwnerDocument.CreateElement("Name"); child.InnerText = Name; node.AppendChild(child); child = node.OwnerDocument.CreateElement("Access"); child.InnerText = AccessModifier.ToString(); node.AppendChild(child); OnSerializing(new SerializeEventArgs(node)); }
protected override void SetupInput() { string TempString = ""; foreach (IProperty Property in Properties) { TempString += Property.Transform() + "\n\n"; } Input.Values.Add("Properties", TempString); TempString = ""; foreach (Using Using in Usings) { TempString += Using.Transform() + "\n"; } Input.Values.Add("Usings", TempString); TempString = ""; foreach (IFunction Constructor in Constructors) { TempString += Constructor.Transform() + "\n"; } Input.Values.Add("Constructor", TempString); TempString = ""; foreach (IFunction Function in Functions) { TempString += Function.Transform() + "\n"; } Input.Values.Add("Functions", TempString); Input.Values.Add("ClassName", ClassName); Input.Values.Add("AccessModifier", AccessModifier.ToString().ToLower()); if (Modifier == Modifiers.None) { Input.Values.Add("Modifier", ""); } else { Input.Values.Add("Modifier", Modifier.ToString().ToLower()); } Input.Values.Add("Namespace", Namespace); }
public async Task BuildAsync(CodeWriter writer) { string modifier = _accessModifier.ToString().ToLowerInvariant(); await writer.WriteIndentAsync().ConfigureAwait(false); await writer.WriteAsync($"{modifier} ") .ConfigureAwait(false); if (_isStatic) { await writer.WriteAsync("static ").ConfigureAwait(false); } if (_isReadOnly) { await writer.WriteAsync("readonly ").ConfigureAwait(false); } await writer.WriteAsync($"{_type} {_name}").ConfigureAwait(false); if (_value is { })
internal override void Write(ref CodeWriter writer) { _xmlDoc.RemoveUnusedParameters(_parameters); _xmlDoc.Write(ref writer); foreach (var attribute in _attributes) { writer.AppendLine($"[{attribute}]"); } var modifier = AccessModifier switch { null => Class.AccessModifier.ToString().ToLower(), _ => AccessModifier.ToString().ToLower() }; var parameters = _parameters.Any() ? string.Join(", ", _parameters.Select(x => x.ToString())) : string.Empty; using (writer.Block($"{modifier} {Class.Name}({parameters})", _baseCall?.Invoke())) { _methodBodyWriter?.Invoke(writer); } } }
public void Build(CodeWriter writer) { if (writer is null) { throw new ArgumentNullException(nameof(writer)); } if (_type is null) { throw new ArgumentNullException(nameof(_type)); } string modifier = _accessModifier.ToString().ToLowerInvariant(); writer.WriteIndent(); writer.Write($"{modifier} "); if (_isConst) { writer.Write("const "); } if (_isStatic) { writer.Write("static "); } if (_isReadOnly) { writer.Write("readonly "); } _type.Build(writer); writer.Write(_name); if (_value is { })
protected override void SetupInput() { Input.Values.Add("AccessModifier", AccessModifier.ToString().ToLower()); if (Modifier != Modifiers.None) { Input.Values.Add("Modifier", Modifier.ToString().ToLower()); } else { Input.Values.Add("Modifier", ""); } Input.Values.Add("Type", Type); Input.Values.Add("FunctionName", Name); Input.Values.Add("Body", Body); string TempString = ""; string Splitter = ""; foreach (IParameter Parameter in Parameters) { TempString += Splitter + Parameter.Transform(); Splitter = ","; } Input.Values.Add("ParameterList", TempString); }
public async Task BuildAsync(CodeWriter writer) { if (writer is null) { throw new ArgumentNullException(nameof(writer)); } await writer.WriteGeneratedAttributeAsync().ConfigureAwait(false); string modifier = _accessModifier.ToString().ToLowerInvariant(); await writer.WriteIndentAsync().ConfigureAwait(false); await writer.WriteAsync($"{modifier} ").ConfigureAwait(false); if (_isPartial) { await writer.WriteAsync("partial ").ConfigureAwait(false); } await writer.WriteAsync("interface ").ConfigureAwait(false); await writer.WriteLineAsync(_name).ConfigureAwait(false); if (_implements.Count > 0) { using (writer.IncreaseIndent()) { for (int i = 0; i < _implements.Count; i++) { if (i == 0) { await writer.WriteIndentedLineAsync( $": {_implements[i]}") .ConfigureAwait(false); } else { await writer.WriteIndentedLineAsync( $", {_implements[i]}") .ConfigureAwait(false); } } } } await writer.WriteIndentedLineAsync("{").ConfigureAwait(false); bool writeLine = false; using (writer.IncreaseIndent()) { if (_properties.Count > 0) { for (int i = 0; i < _properties.Count; i++) { if (writeLine || i > 0) { await writer.WriteLineAsync().ConfigureAwait(false); } await _properties[i].BuildAsync(writer).ConfigureAwait(false); } writeLine = true; } if (_methods.Count > 0) { for (int i = 0; i < _methods.Count; i++) { if (writeLine || i > 0) { await writer.WriteLineAsync().ConfigureAwait(false); } await _methods[i].BuildAsync(writer).ConfigureAwait(false); } writeLine = true; } } await writer.WriteIndentedLineAsync("}").ConfigureAwait(false); }
public static string GetModifier(AccessModifier? access, MemberModifier? modifier) { return !modifier.HasValue ? access.ToString().ToLower() : String.Format("{0} {1}", access.ToString().ToLower(), modifier.ToString().ToLower()); }
public static string GetVisualBasicModifier(AccessModifier? access) { return GetVisualBasicModifier(access.ToString()); }
public override string GetAccessString(AccessModifier access, bool forCode) { switch (access) { case AccessModifier.ProtectedInternal: if (forCode) return "protected internal"; else return "Protected Internal"; case AccessModifier.Default: if (forCode) return ""; else return "Default"; default: if (forCode) return access.ToString().ToLower(); else return access.ToString(); } }
public static string Scope(AccessModifier modifier) { return(Patcher.AddLowerUpperNeighboringSpaces(modifier.ToString()).ToLower()); }
public static string GetVisualBasicModifier(AccessModifier? access, MemberModifier? modifier) { return !modifier.HasValue ? GetVisualBasicModifier(access.ToString()) : String.Format("{0} {1}", GetVisualBasicModifier(access.ToString()), modifier); }
/// <summary> /// Initializes a new instance of the <see cref="TypeAccessModifierAnnotation"/> class. /// </summary> /// <param name="typeAccessModifier">The type visibility.</param> public TypeAccessModifierAnnotation(AccessModifier typeAccessModifier) { ExceptionUtilities.Assert(typeAccessModifier == AccessModifier.Public || typeAccessModifier == AccessModifier.Internal || typeAccessModifier == AccessModifier.Unspecified, "Cannot have AccessModiier " + typeAccessModifier.ToString() + " on typeAccess"); this.TypeAccessModifier = typeAccessModifier; }
/// <summary> /// Renders an access modifier /// </summary> private string GetAccessModifier(AccessModifier accessModifier) { return accessModifier.ToString().ToLower(); }
public static string GetModifier(AccessModifier? access) { return access.ToString().ToLower(); }
protected AccessModifierNotAllowedForMemberException(AccessModifier modifier, MemberInfo member, string description) : base($"The access modifier(s) [ {modifier.ToString()} ] are not allowed on \"{member.DeclaringType.ReadableName()}.{member.Name}\". {description}") { }
public override string ToString() { return($"{_AccessModifier.ToString()} {ReturnType.ToString()} {MethodName}"); }