/// <summary> /// Converts the <see cref="ModifierEnum"/> to string that can be used in code /// </summary> /// <param name="modifierEnum">Modifier to convert</param> /// <returns>"Code compatible" modifier string</returns> public static string ToModifierString(this ModifierEnum modifierEnum) { switch (modifierEnum) { case ModifierEnum.NotApplicable: return(""); case ModifierEnum.Public: return("public"); case ModifierEnum.Private: return("private"); case ModifierEnum.Protected: return("protected"); case ModifierEnum.Internal: return("internal"); case ModifierEnum.ProtectedInternal: return("protected internal"); case ModifierEnum.PrivateProtected: return("private protected"); default: throw new ArgumentOutOfRangeException(nameof(modifierEnum), modifierEnum, null); } }
string ConvertAccessibility(ModifierEnum modifier) { StringBuilder builder = new StringBuilder(); if (ShowAccessibility) { if ((modifier & ModifierEnum.Public) == ModifierEnum.Public) { builder.Append("Public"); } else if ((modifier & ModifierEnum.Private) == ModifierEnum.Private) { builder.Append("Private"); } else if ((modifier & (ModifierEnum.Protected | ModifierEnum.Internal)) == (ModifierEnum.Protected | ModifierEnum.Internal)) { builder.Append("Protected Friend"); } else if ((modifier & ModifierEnum.Internal) == ModifierEnum.Internal) { builder.Append("Friend"); } else if ((modifier & ModifierEnum.Protected) == ModifierEnum.Protected) { builder.Append("Protected"); } builder.Append(' '); } return(builder.ToString()); }
void InitMemberNode(IMember member) { this.member = member; this.ContextmenuAddinTreePath = "/SharpDevelop/Pads/ClassBrowser/MemberContextMenu"; declaringType = member.DeclaringType; modifiers = member.Modifiers; }
static ModifierEnum TranslateModifiers(FieldDefinition field) { ModifierEnum m = ModifierEnum.None; if (field.IsStatic) { m |= ModifierEnum.Static; } if (field.IsLiteral) { m |= ModifierEnum.Const; } else if (field.IsReadOnly) { m |= ModifierEnum.Readonly; } if ((field.Attributes & FieldAttributes.Public) == FieldAttributes.Public) { m |= ModifierEnum.Public; } else { m |= ModifierEnum.Protected; } return(m); }
public override string Convert(ModifierEnum modifier) { if (ShowAccessibility) { if (ModifierIsSet(modifier, ModifierEnum.Public)) { return("public "); } else if (ModifierIsSet(modifier, ModifierEnum.Private)) { return("private "); } else if (ModifierIsSet(modifier, ModifierEnum.ProtectedAndInternal)) { return("protected internal "); } else if (ModifierIsSet(modifier, ModifierEnum.Internal)) { return("internal "); } else if (ModifierIsSet(modifier, ModifierEnum.Protected)) { return("protected "); } } return(string.Empty); }
/// <summary> /// Calculate information from class parts (Modifier, Base classes, Type parameters etc.) /// </summary> void UpdateInformationFromParts() { // Common for all parts: this.ClassType = parts[0].ClassType; ModifierEnum modifier = ModifierEnum.None; const ModifierEnum defaultClassVisibility = ModifierEnum.Internal; this.BaseTypes.Clear(); this.InnerClasses.Clear(); this.Attributes.Clear(); this.Methods.Clear(); this.Properties.Clear(); this.Events.Clear(); this.Fields.Clear(); string shortestFileName = null; foreach (IClass part in parts) { if (!string.IsNullOrEmpty(part.CompilationUnit.FileName)) { if (shortestFileName == null || part.CompilationUnit.FileName.Length < shortestFileName.Length) { shortestFileName = part.CompilationUnit.FileName; this.Region = part.Region; } } if ((part.Modifiers & ModifierEnum.VisibilityMask) != defaultClassVisibility) { modifier |= part.Modifiers; } else { modifier |= part.Modifiers & ~ModifierEnum.VisibilityMask; } foreach (IReturnType rt in part.BaseTypes) { if (!rt.IsDefaultReturnType || rt.FullyQualifiedName != "System.Object") { this.BaseTypes.Add(rt); } } this.InnerClasses.AddRange(part.InnerClasses); this.Attributes.AddRange(part.Attributes); this.Methods.AddRange(part.Methods); this.Properties.AddRange(part.Properties); this.Events.AddRange(part.Events); this.Fields.AddRange(part.Fields); this.AddDefaultConstructorIfRequired |= part.GetAddDefaultConstructorIfRequired(); } this.CompilationUnit.FileName = shortestFileName; if ((modifier & ModifierEnum.VisibilityMask) == ModifierEnum.None) { modifier |= defaultClassVisibility; } this.Modifiers = modifier; }
public ReflectionEvent(EventInfo eventInfo, IClass declaringType) : base(declaringType, eventInfo.Name) { this.ReturnType = ReflectionReturnType.Create(this, eventInfo.EventHandlerType, false); // get modifiers MethodInfo methodBase = null; try { methodBase = eventInfo.GetAddMethod(true); } catch (Exception) { } if (methodBase == null) { try { methodBase = eventInfo.GetRemoveMethod(true); } catch (Exception) { } } ModifierEnum modifiers = ModifierEnum.None; if (methodBase != null) { if (methodBase.IsStatic) { modifiers |= ModifierEnum.Static; } if (methodBase.IsAssembly) { modifiers |= ModifierEnum.Internal; } if (methodBase.IsPrivate) { // I assume that private is used most and public last (at least should be) modifiers |= ModifierEnum.Private; } else if (methodBase.IsFamily || methodBase.IsFamilyOrAssembly) { modifiers |= ModifierEnum.Protected; } else if (methodBase.IsPublic) { modifiers |= ModifierEnum.Public; } else { modifiers |= ModifierEnum.Internal; } } else { // assume public property, if no methodBase could be get. modifiers = ModifierEnum.Public; } this.Modifiers = modifiers; }
public DefaultField(IReturnType type, string name, ModifierEnum m, DomRegion region, IClass declaringType) : base(declaringType, name) { this.ReturnType = type; this.Region = region; this.Modifiers = m; }
public DefaultProperty(string name, IReturnType type, ModifierEnum m, DomRegion region, DomRegion bodyRegion, IClass declaringType) : base(declaringType, name) { this.ReturnType = type; this.Region = region; this.BodyRegion = bodyRegion; Modifiers = m; }
public DefaultClass(ICompilationUnit compilationUnit, ClassType classType, ModifierEnum modifiers, DomRegion region, IClass declaringType) : base(declaringType) { _compilationUnit = compilationUnit; _region = region; _classType = classType; Modifiers = modifiers; }
public DefaultMethod(string name, IReturnType type, ModifierEnum m, DomRegion region, DomRegion bodyRegion, IClass declaringType) : base(declaringType, name) { this.ReturnType = type; this.Region = region; this.BodyRegion = bodyRegion; Modifiers = m; }
int GetAccessSortValue(ModifierEnum mods) { if ((mods & ModifierEnum.Private) != 0) return 0; if ((mods & ModifierEnum.Internal) != 0) return 1; if ((mods & ModifierEnum.Protected) != 0) return 2; if ((mods & ModifierEnum.Public) != 0) return 3; return 4; }
ModifierEnum ConvertModifier(AST.Modifiers m, ModifierEnum defaultVisibility) { ModifierEnum r = (ModifierEnum)m; if ((r & ModifierEnum.VisibilityMask) == ModifierEnum.None) return r | defaultVisibility; else return r; }
public DefaultEvent(string name, IReturnType type, ModifierEnum m, DomRegion region, DomRegion bodyRegion, IClass declaringType) : base(declaringType, name) { this.ReturnType = type; this.Region = region; this.BodyRegion = bodyRegion; Modifiers = (ModifierEnum)m; if (Modifiers == ModifierEnum.None) { Modifiers = ModifierEnum.Private; } }
public static Modifiers ConvertModifier(ModifierEnum modifiers, ClassFinder targetContext) { if (targetContext != null && targetContext.ProjectContent != null && targetContext.CallingClass != null) { if (targetContext.ProjectContent.Language.IsClassWithImplicitlyStaticMembers(targetContext.CallingClass)) { return(((Modifiers)modifiers) & ~Modifiers.Static); } } return((Modifiers)modifiers); }
public DefaultClass(ICompilationUnit compilationUnit, ClassType classType, ModifierEnum modifiers, DomRegion region, IClass declaringType) : base(declaringType) { if (compilationUnit == null) { throw new ArgumentNullException("compilationUnit"); } this.compilationUnit = compilationUnit; this.region = region; this.classType = classType; Modifiers = modifiers; this.UsingScope = compilationUnit.UsingScope; }
public Constructor(IClass declaringType, SR.MethodInfo tinfo) { this.declaringType = declaringType; ModifierEnum mod = (ModifierEnum)0; if (tinfo.IsPrivate) { mod |= ModifierEnum.Private; } if (tinfo.IsAssembly) { mod |= ModifierEnum.Internal; } if (tinfo.IsFamily) { mod |= ModifierEnum.Protected; } if (tinfo.IsPublic) { mod |= ModifierEnum.Public; } if (tinfo.IsAbstract) { mod |= ModifierEnum.Abstract; } if (tinfo.IsFinal) { mod |= ModifierEnum.Sealed; } if (tinfo.IsStatic) { mod |= ModifierEnum.Static; } if (tinfo.IsVirtual) { mod |= ModifierEnum.Virtual; } modifiers = mod; this.FullyQualifiedName = tinfo.Name; this.region = Class.GetRegion(); this.bodyRegion = Class.GetRegion(); this._member = null; // Add parameters foreach (SR.ParameterInfo pinfo in tinfo.GetParameters()) { parameters.Add(new Parameter(this, pinfo, null)); } }
static int GetModifierOffset(ModifierEnum modifier) { if ((modifier & ModifierEnum.Public) == ModifierEnum.Public) { return 0; } if ((modifier & ModifierEnum.Protected) == ModifierEnum.Protected) { return protectedModifierOffset; } if ((modifier & ModifierEnum.Internal) == ModifierEnum.Internal) { return internalModifierOffset; } return privateModifierOffset; }
ModifierEnum ConvertModifier(AST.Modifiers m, ModifierEnum defaultVisibility) { ModifierEnum r = (ModifierEnum)m; if ((r & ModifierEnum.VisibilityMask) == ModifierEnum.None) { return(r | defaultVisibility); } else { return(r); } }
public static AST.TypeMemberModifiers ConvertVisibilityBack(ModifierEnum modifier) { AST.TypeMemberModifiers r = AST.TypeMemberModifiers.None; if ((modifier & ModifierEnum.Public) == ModifierEnum.Public) r |= AST.TypeMemberModifiers.Public; if ((modifier & ModifierEnum.Protected) == ModifierEnum.Protected) r |= AST.TypeMemberModifiers.Protected; if ((modifier & ModifierEnum.Internal) == ModifierEnum.Internal) r |= AST.TypeMemberModifiers.Internal; if ((modifier & ModifierEnum.Private) == ModifierEnum.Private) r |= AST.TypeMemberModifiers.Private; return r; }
static ModifierEnum GetAccessorVisibility(IProperty p, MethodDefinition accessor) { ModifierEnum visibility = ModifierEnum.VisibilityMask & TranslateModifiers(accessor); if (visibility == (p.Modifiers & ModifierEnum.VisibilityMask)) { return(ModifierEnum.None); } else { return(visibility); } }
public Event(Class declaringType, SR.EventInfo tinfo) { this.declaringType = declaringType; ModifierEnum mod = (ModifierEnum)0; modifiers = mod; this.FullyQualifiedName = tinfo.Name; returnType = new ReturnType(tinfo.EventHandlerType); this.region = Class.GetRegion(); this.bodyRegion = Class.GetRegion(); LoadXml(declaringType); }
public static Modifiers ConvertModifier(ModifierEnum modifiers, ClassFinder targetContext) { if (targetContext != null && targetContext.ProjectContent != null && targetContext.CallingClass != null) { if (targetContext.ProjectContent.Language.IsClassWithImplicitlyStaticMembers(targetContext.CallingClass)) { return(((Modifiers)modifiers) & ~Modifiers.Static); } } if (modifiers.HasFlag(ModifierEnum.Static)) { modifiers &= ~(ModifierEnum.Abstract | ModifierEnum.Sealed); } return((Modifiers)modifiers); }
static int GetModifierOffset(ModifierEnum modifier) { if ((modifier & ModifierEnum.Public) == ModifierEnum.Public) { return(0); } if ((modifier & ModifierEnum.Protected) == ModifierEnum.Protected) { return(3); } if ((modifier & ModifierEnum.Internal) == ModifierEnum.Internal) { return(4); } return(2); }
static ModifierEnum TranslateModifiers(MethodDefinition method) { ModifierEnum m = ModifierEnum.None; if (method.IsStatic) { m |= ModifierEnum.Static; } else { if (method.IsAbstract) { m |= ModifierEnum.Abstract; } else if (method.IsFinal) { m |= ModifierEnum.Sealed; } else if (method.Overrides.Count > 0) { m |= ModifierEnum.Override; } else if (method.IsVirtual) { if (method.IsNewSlot) { m |= ModifierEnum.Virtual; } else { m |= ModifierEnum.Override; } } } if ((method.Attributes & MethodAttributes.Public) == MethodAttributes.Public) { m |= ModifierEnum.Public; } else { m |= ModifierEnum.Protected; } return(m); }
public Local(Class declaringType, NCC.LocalValue tinfo) { this.declaringType = declaringType; ModifierEnum mod = ModifierEnum.Public; if (!tinfo.IsMutable) { mod |= ModifierEnum.Readonly; } modifiers = mod; this.FullyQualifiedName = tinfo.Name; returnType = new ReturnType(tinfo.Type.Fix()); this.region = Class.GetRegion(); }
string ConvertAccessibility(ModifierEnum modifier) { if (ShowAccessibility) { if (ModifierIsSet(modifier, ModifierEnum.Public)) { return "public "; } else if (ModifierIsSet(modifier, ModifierEnum.Private)) { return "private "; } else if (ModifierIsSet(modifier, ModifierEnum.ProtectedAndInternal)) { return "protected internal "; } else if (ModifierIsSet(modifier, ModifierEnum.Internal)) { return "internal "; } else if (ModifierIsSet(modifier, ModifierEnum.Protected)) { return "protected "; } } return string.Empty; }
public ReflectionField(FieldInfo fieldInfo, IClass declaringType) : base(declaringType, fieldInfo.Name) { this.ReturnType = ReflectionReturnType.Create(this, fieldInfo.FieldType, false); ModifierEnum modifiers = ModifierEnum.None; if (fieldInfo.IsInitOnly) { modifiers |= ModifierEnum.Readonly; } if (fieldInfo.IsStatic) { modifiers |= ModifierEnum.Static; } if (fieldInfo.IsAssembly) { modifiers |= ModifierEnum.Internal; } if (fieldInfo.IsPrivate) // I assume that private is used most and public last (at least should be) { modifiers |= ModifierEnum.Private; } else if (fieldInfo.IsFamily || fieldInfo.IsFamilyOrAssembly) { modifiers |= ModifierEnum.Protected; } else if (fieldInfo.IsPublic) { modifiers |= ModifierEnum.Public; } else { modifiers |= ModifierEnum.Internal; } if (fieldInfo.IsLiteral) { modifiers |= ModifierEnum.Const; } this.Modifiers = modifiers; }
public override object VisitFieldDeclaration(NRefactoryAST.FieldDeclaration fieldDeclaration, object data) { DomRegion region = GetRegion(fieldDeclaration.StartLocation, fieldDeclaration.EndLocation); DefaultClass c = GetCurrentClass(); ModifierEnum modifier = ConvertModifier(fieldDeclaration.Modifier, (c.ClassType == ClassType.Struct && this.IsVisualBasic) ? ModifierEnum.Public : ModifierEnum.Private); string doku = GetDocumentation(region.BeginLine, fieldDeclaration.Attributes); if (currentClass.Count > 0) { for (int i = 0; i < fieldDeclaration.Fields.Count; ++i) { NRefactoryAST.VariableDeclaration field = (NRefactoryAST.VariableDeclaration)fieldDeclaration.Fields[i]; IReturnType retType; if (c.ClassType == ClassType.Enum) { retType = c.DefaultReturnType; } else { retType = CreateReturnType(fieldDeclaration.GetTypeForField(i)); if (!field.FixedArrayInitialization.IsNull) { retType = new ArrayReturnType(cu.ProjectContent, retType, 1); } } DefaultField f = new DefaultField(retType, field.Name, modifier, region, c); ConvertAttributes(fieldDeclaration, f); f.Documentation = doku; if (c.ClassType == ClassType.Enum) { f.Modifiers = ModifierEnum.Const | ModifierEnum.Public; } c.Fields.Add(f); mapField(fieldDeclaration, f); } } return(null); }
public override string Convert(ModifierEnum modifier) { StringBuilder builder = new StringBuilder(); if (ShowAccessibility) { if ((modifier & ModifierEnum.Public) == ModifierEnum.Public) { builder.Append("Public"); } else if ((modifier & ModifierEnum.Private) == ModifierEnum.Private) { builder.Append("Private"); } else if ((modifier & (ModifierEnum.Protected | ModifierEnum.Internal)) == (ModifierEnum.Protected | ModifierEnum.Internal)) { builder.Append("Protected Friend"); } else if ((modifier & ModifierEnum.Internal) == ModifierEnum.Internal) { builder.Append("Friend"); } else if ((modifier & ModifierEnum.Protected) == ModifierEnum.Protected) { builder.Append("Protected"); } builder.Append(' '); } return builder.ToString(); }
/// <summary> /// Defines and returns a constructor for the given type /// </summary> /// <param name="container"></param> /// <param name="modifier"></param> /// <param name="parameters"></param> /// <returns></returns> public static CodeConstructor DefineConstructor(CodeTypeDeclaration container, ModifierEnum modifier, params ParameterInfo[] parameters) { CodeConstructor ctor = new CodeConstructor(); ctor.Attributes = (ctor.Attributes & ~MemberAttributes.AccessMask) | (MemberAttributes)modifier; if (parameters != null) { foreach (ParameterInfo parameter in parameters) { CodeParameterDeclarationExpression codeParameter = new CodeParameterDeclarationExpression( parameter.ParameterType, parameter.Name); ctor.Parameters.Add(codeParameter); } } container.Members.Add(ctor); return ctor; }
public override string Convert(ModifierEnum modifier, ConversionFlags conversionFlags) { if (ShowAccessibility(conversionFlags)) { if (ModifierIsSet(modifier, ModifierEnum.Public)) { return "public "; } else if (ModifierIsSet(modifier, ModifierEnum.Private)) { return "private "; } else if (ModifierIsSet(modifier, ModifierEnum.ProtectedAndInternal)) { return "protected internal "; } else if (ModifierIsSet(modifier, ModifierEnum.ProtectedOrInternal)) { return "internal protected "; } else if (ModifierIsSet(modifier, ModifierEnum.Internal)) { return "internal "; } else if (ModifierIsSet(modifier, ModifierEnum.Protected)) { return "protected "; } } return string.Empty; }
public static AST.TypeMemberModifiers ConvertVisibilityBack(ModifierEnum modifier) { AST.TypeMemberModifiers r = AST.TypeMemberModifiers.None; if ((modifier & ModifierEnum.Public) == ModifierEnum.Public) { r |= AST.TypeMemberModifiers.Public; } if ((modifier & ModifierEnum.Protected) == ModifierEnum.Protected) { r |= AST.TypeMemberModifiers.Protected; } if ((modifier & ModifierEnum.Internal) == ModifierEnum.Internal) { r |= AST.TypeMemberModifiers.Internal; } if ((modifier & ModifierEnum.Private) == ModifierEnum.Private) { r |= AST.TypeMemberModifiers.Private; } return(r); }
public Indexer(Class declaringType, SR.PropertyInfo tinfo) { this.declaringType = declaringType; ModifierEnum mod = (ModifierEnum)0; modifiers = mod; this.FullyQualifiedName = tinfo.Name; returnType = new ReturnType(tinfo.PropertyType); this.region = Class.GetRegion(); this.bodyRegion = Class.GetRegion(); LoadXml(declaringType); // Add parameters foreach (SR.ParameterInfo pinfo in tinfo.GetIndexParameters()) { parameters.Add(new Parameter(this, pinfo, node)); } }
/// <summary> /// Re-calculate information from class parts (Modifier, Base classes, Type parameters etc.) /// </summary> internal void UpdateInformationFromParts() { // Common for all parts: this.ClassType = parts[0].ClassType; this.CompilationUnit.FileName = parts[0].CompilationUnit.FileName; this.Region = parts[0].Region; ModifierEnum modifier = ModifierEnum.None; const ModifierEnum defaultClassVisibility = ModifierEnum.Internal; this.BaseTypes.Clear(); this.Attributes.Clear(); foreach (IClass part in parts) { if ((part.Modifiers & ModifierEnum.VisibilityMask) != defaultClassVisibility) { modifier |= part.Modifiers; } else { modifier |= part.Modifiers & ~ModifierEnum.VisibilityMask; } foreach (IReturnType rt in part.BaseTypes) { if (!rt.IsDefaultReturnType || rt.FullyQualifiedName != "System.Object") { this.BaseTypes.Add(rt); } } foreach (IAttribute attribute in part.Attributes) { this.Attributes.Add(attribute); } } if ((modifier & ModifierEnum.VisibilityMask) == ModifierEnum.None) { modifier |= defaultClassVisibility; } this.Modifiers = modifier; }
public Field(Class declaringType, SR.FieldInfo tinfo) { this.declaringType = declaringType; ModifierEnum mod = (ModifierEnum)0; if (tinfo.IsPrivate) { mod |= ModifierEnum.Private; } if (tinfo.IsAssembly) { mod |= ModifierEnum.Internal; } if (tinfo.IsFamily) { mod |= ModifierEnum.Protected; } if (tinfo.IsPublic) { mod |= ModifierEnum.Public; } if (tinfo.IsStatic) { mod |= ModifierEnum.Static; } if (tinfo.IsLiteral) { mod |= ModifierEnum.Const; } modifiers = mod; this.FullyQualifiedName = tinfo.Name; returnType = new ReturnType(tinfo.FieldType); this.region = Class.GetRegion(); LoadXml(declaringType); }
internal static void AddDefaultDelegateMethod(DefaultClass c, IReturnType returnType, IList <IParameter> parameters) { ModifierEnum modifiers = ModifierEnum.Public | ModifierEnum.Synthetic; DefaultMethod invokeMethod = new DefaultMethod("Invoke", returnType, modifiers, c.Region, DomRegion.Empty, c); foreach (IParameter par in parameters) { invokeMethod.Parameters.Add(par); } c.Methods.Add(invokeMethod); invokeMethod = new DefaultMethod("BeginInvoke", c.ProjectContent.SystemTypes.IAsyncResult, modifiers, c.Region, DomRegion.Empty, c); foreach (IParameter par in parameters) { invokeMethod.Parameters.Add(par); } invokeMethod.Parameters.Add(new DefaultParameter("callback", c.ProjectContent.SystemTypes.AsyncCallback, DomRegion.Empty)); invokeMethod.Parameters.Add(new DefaultParameter("object", c.ProjectContent.SystemTypes.Object, DomRegion.Empty)); c.Methods.Add(invokeMethod); invokeMethod = new DefaultMethod("EndInvoke", returnType, modifiers, c.Region, DomRegion.Empty, c); invokeMethod.Parameters.Add(new DefaultParameter("result", c.ProjectContent.SystemTypes.IAsyncResult, DomRegion.Empty)); c.Methods.Add(invokeMethod); }
/// <summary> /// Compares the SharpDevelop.Dom field declaration oldField to /// the CodeDom field declaration newField. /// </summary> /// <returns>true, if the fields are different in type or modifiers, otherwise false.</returns> static bool FieldChanged(IField oldField, CodeMemberField newField) { // compare types if (oldField.ReturnType != null && newField.Type != null) { if (AreTypesDifferent(oldField.ReturnType, newField.Type)) { LoggingService.Debug("FieldChanged (type): " + oldField.Name + ", " + oldField.ReturnType.FullyQualifiedName + " -> " + newField.Type.BaseType); return(true); } } // compare modifiers ModifierEnum oldModifiers = oldField.Modifiers & ModifierEnum.VisibilityMask; MemberAttributes newModifiers = newField.Attributes & MemberAttributes.AccessMask; // SharpDevelop.Dom always adds Private modifier, even if not specified // CodeDom omits Private modifier if not present (although it is the default) if (oldModifiers == ModifierEnum.Private) { if (newModifiers != 0 && newModifiers != MemberAttributes.Private) { return(true); } } ModifierEnum[] sdModifiers = new ModifierEnum[] { ModifierEnum.Protected, ModifierEnum.ProtectedAndInternal, ModifierEnum.Internal, ModifierEnum.Public }; MemberAttributes[] cdModifiers = new MemberAttributes[] { MemberAttributes.Family, MemberAttributes.FamilyOrAssembly, MemberAttributes.Assembly, MemberAttributes.Public }; for (int i = 0; i < sdModifiers.Length; i++) { if ((oldModifiers == sdModifiers[i]) ^ (newModifiers == cdModifiers[i])) { return(true); } } return(false); }
public override void VisitAttribute(AXmlAttribute attribute) { Debug.Assert(document != null); if (attribute.ParentElement != null) { if (attribute.ParentElement.Parent == document && attribute.LocalName == "Class" && attribute.Namespace == CompletionDataHelper.XamlNamespace) { this.generatedClass = AddClass(attribute.Value, attribute.ParentElement); } else if (generatedClass != null && attribute.LocalName == "Name") { string name = attribute.Value; if (!string.IsNullOrEmpty(name)) { IReturnType type = TypeFromXmlNode(CompilationUnit, attribute.ParentElement); DomRegion position = CreateRegion(attribute.ParentElement.StartOffset, attribute.ParentElement.StartOffset + attribute.ParentElement.Name.Length); ModifierEnum fieldModifier = ModifierEnum.Internal; string modifierValue = (attribute.ParentElement.GetAttributeValue(CompletionDataHelper.XamlNamespace, "FieldModifier") ?? string.Empty).Trim(); string publicString = currentAmbience.ConvertAccessibility(ModifierEnum.Public).Trim(); if (projectContent.Language.NameComparer.Compare(modifierValue, publicString) == 0) { fieldModifier = ModifierEnum.Public; } generatedClass.Fields.Add(new DefaultField(type, name, fieldModifier, position, generatedClass)); } } } base.VisitAttribute(attribute); }
/// <summary> /// Defines an accessor (get/set) /// </summary> /// <param name="container"></param> /// <param name="modifier"></param> /// <param name="typeInfo"></param> /// <param name="hasGet"></param> /// <param name="hasSet"></param> /// <param name="memberVariableName"></param> /// <returns></returns> public static CodeMemberProperty DefineAccessor(CodeTypeDeclaration container, ModifierEnum modifier, ParameterInfo typeInfo, bool hasGet, bool hasSet, string memberVariableName) { CodeMemberProperty property = DefineProperty(container, modifier, typeInfo, hasGet, hasSet); if (hasGet) { property.GetStatements.Add(new CodeMethodReturnStatement( new CodeFieldReferenceExpression( new CodeThisReferenceExpression(), memberVariableName ) ) ); } if (hasSet) { property.SetStatements.Add(new CodeAssignStatement( new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), memberVariableName), new CodePropertySetValueReferenceExpression())); } return property; }
public void AddModifier(ModifierEnum m) { modifiers = modifiers | m; }
public string Convert(ModifierEnum modifier) { return String.Empty; }
public override string Convert(ModifierEnum modifier) { return ""; }
public override string ConvertAccessibility(ModifierEnum accessibility) { return String.Empty; }
public DefaultClass(ICompilationUnit compilationUnit, ClassType classType, ModifierEnum modifiers, DomRegion region, IClass declaringType) : base(declaringType) { if (compilationUnit == null) throw new ArgumentNullException("compilationUnit"); this.compilationUnit = compilationUnit; this.region = region; this.classType = classType; Modifiers = modifiers; this.UsingScope = compilationUnit.UsingScope; }
public Constructor(ModifierEnum m, DomRegion region, DomRegion bodyRegion, IClass declaringType) : base((m & ModifierEnum.Static) != 0 ? "#cctor" : "#ctor", declaringType.DefaultReturnType, m, region, bodyRegion, declaringType) { }
public Constructor(ModifierEnum m, IReturnType returnType, IClass declaringType) : base("#ctor", returnType, m, DomRegion.Empty, DomRegion.Empty, declaringType) { }
/// <summary> /// Defines a member variable /// </summary> /// <param name="container"></param> /// <param name="modifier"></param> /// <param name="typeInfo"></param> /// <returns></returns> public static CodeMemberField DefineField(CodeTypeDeclaration container, ModifierEnum modifier, ParameterInfo typeInfo) { CodeMemberField member = new CodeMemberField(new CodeTypeReference(typeInfo.ParameterType), typeInfo.Name); member.Attributes = (member.Attributes & ~MemberAttributes.AccessMask) | (MemberAttributes)modifier; container.Members.Add(member); return member; }
/// <summary> /// Compares the SharpDevelop.Dom field declaration oldField to /// the CodeDom field declaration newField. /// </summary> /// <returns>true, if the fields are different in type or modifiers, otherwise false.</returns> static bool FieldChanged(IField oldField, CodeMemberField newField) { // compare types if (oldField.ReturnType != null && newField.Type != null) { if (AreTypesDifferent(oldField.ReturnType, newField.Type)) { LoggingService.Debug("FieldChanged (type): "+oldField.Name+", "+oldField.ReturnType.FullyQualifiedName+" -> "+newField.Type.BaseType); return true; } } // compare modifiers ModifierEnum oldModifiers = oldField.Modifiers & ModifierEnum.VisibilityMask; MemberAttributes newModifiers = newField.Attributes & MemberAttributes.AccessMask; // SharpDevelop.Dom always adds Private modifier, even if not specified // CodeDom omits Private modifier if not present (although it is the default) if (oldModifiers == ModifierEnum.Private) { if (newModifiers != 0 && newModifiers != MemberAttributes.Private) { return true; } } ModifierEnum[] sdModifiers = new ModifierEnum[] {ModifierEnum.Protected, ModifierEnum.ProtectedAndInternal, ModifierEnum.Internal, ModifierEnum.Public}; MemberAttributes[] cdModifiers = new MemberAttributes[] {MemberAttributes.Family, MemberAttributes.FamilyOrAssembly, MemberAttributes.Assembly, MemberAttributes.Public}; for (int i = 0; i < sdModifiers.Length; i++) { if ((oldModifiers == sdModifiers[i]) ^ (newModifiers == cdModifiers[i])) { return true; } } return false; }
public CodeGetterOrSetterFunction(IProperty property, ModifierEnum modifier) : base(property) { this.modifier = modifier; }
public void SetModifiers(ModifierEnum m) { modifiers = m; }
public string Convert(ModifierEnum modifier) { return conv.Convert(modifier); }
public abstract string Convert(ModifierEnum modifier);
bool ModifierIsSet(ModifierEnum modifier, ModifierEnum query) { return (modifier & query) == query; }
public abstract string ConvertAccessibility(ModifierEnum accessibility);
string GetWithModifiers(ModifierEnum modifier, string mod_public, string mod_protected, string mod_internal, string mod_private) { if ((modifier & ModifierEnum.Public) == ModifierEnum.Public) return mod_public; if ((modifier & ModifierEnum.Protected) == ModifierEnum.Protected) return mod_protected; if ((modifier & ModifierEnum.Internal) == ModifierEnum.Internal) return mod_internal; return mod_private; }
public Constructor(ModifierEnum m, IReturnType returnType, IClass declaringType) : base((m & ModifierEnum.Static) != 0 ? "#cctor" : "#ctor", returnType, m, DomRegion.Empty, DomRegion.Empty, declaringType) { }