private static ExceptionInfo ScanPlatformNotSupported(ITypeDefinitionMember item) { if (item is IMethodDefinition m) { if (m.IsPropertyOrEventAccessor()) { return(ExceptionInfo.DoesNotThrow); } return(ScanPlatformNotSupported(m)); } else if (item is IPropertyDefinition p) { return(ScanPlatformNotSupported(p.Accessors)); } else if (item is IEventDefinition e) { return(ScanPlatformNotSupported(e.Accessors)); } else if (item is IFieldDefinition || item is ITypeDefinition) { // Ignore return(ExceptionInfo.DoesNotThrow); } else { throw new NotImplementedException($"Unexpected type member: {item.FullName()} ({item.GetApiKind()})"); } }
private void WriteMemberGroupHeader(ITypeDefinitionMember member) { if (member == null) { return; } if (IncludeMemberGroupHeadings || IncludeSpaceBetweenMemberGroups) { string heading = CSharpWriter.MemberGroupHeading(member); if (heading != null) { if (IncludeSpaceBetweenMemberGroups) { if (!_firstMemberGroup) { _syntaxWriter.WriteLine(true); } _firstMemberGroup = false; } if (IncludeMemberGroupHeadings) { _syntaxWriter.Write("// {0}", heading); _syntaxWriter.WriteLine(); } } } }
public static bool IsOverride(this ITypeDefinitionMember member) { IMethodDefinition method = member as IMethodDefinition; if (method != null) { return(method.IsOverride()); } IPropertyDefinition property = member as IPropertyDefinition; if (property != null) { return(property.Accessors.Any(m => m.ResolvedMethod.IsOverride())); } IEventDefinition evnt = member as IEventDefinition; if (evnt != null) { return(evnt.Accessors.Any(m => m.ResolvedMethod.IsOverride())); } return(false); }
public static bool ShouldInclude(this ITypeDefinitionMember member, EmitContext context) { if (context.IncludePrivateMembers) { return(true); } var method = member as IMethodDefinition; if (method != null && method.IsVirtual) { return(true); } switch (member.Visibility) { case TypeMemberVisibility.Private: return(context.IncludePrivateMembers); case TypeMemberVisibility.Assembly: case TypeMemberVisibility.FamilyAndAssembly: return(context.IncludePrivateMembers || context.Module.SourceAssemblyOpt?.InternalsAreVisible == true); } return(true); }
public static bool InSameUnit(ITypeDefinitionMember member1, ITypeDefinitionMember member2) { IUnit unit1 = TypeHelper.GetDefiningUnit(member1.ContainingTypeDefinition); IUnit unit2 = TypeHelper.GetDefiningUnit(member2.ContainingTypeDefinition); return(UnitHelper.UnitsAreEquivalent(unit1, unit2)); }
public override void Visit(ITypeDefinitionMember member) { if (member.IsVisibleOutsideAssembly()) { base.Visit(member); } }
/// <summary> /// Returns the data in model file that corresponds to passed CCI2 type member /// </summary> /// <param name="typeDef">The CCI2 type member to look up</param> /// <returns>MemberElementBase of the data loaded from model file, or null if no entry exists</returns> public MemberElement this[ITypeDefinitionMember memberDef] { get { INamedTypeDefinition typeDef = Util.ContainingTypeDefinition(memberDef); AssemblyElement assembly; string assemblyName = GetAssemblyName(typeDef); if (_reader.Model.Assemblies.TryGetValue(assemblyName, out assembly)) { TypeElement type; string typeName = _formatter.GetTypeSignature(typeDef); if (assembly.Types.TryGetValue(typeName, out type)) { // Try to return the member data if there MemberElement member; string memberName = _formatter.GetMemberSignature(memberDef, true); if (type.Members.TryGetValue(memberName, out member)) { return(member); } } } return(null); } }
public override DifferenceType Diff(IDifferences differences, ITypeDefinitionMember impl, ITypeDefinitionMember contract) { if (impl == null || contract == null) { return(DifferenceType.Unknown); } if (!impl.ContainingTypeDefinition.IsEnum || !contract.ContainingTypeDefinition.IsEnum) { return(DifferenceType.Unknown); } IFieldDefinition implField = impl as IFieldDefinition; IFieldDefinition contractField = contract as IFieldDefinition; Debug.Assert(implField != null || contractField != null); string implValue = Convert.ToString(implField.Constant.Value); string contractValue = Convert.ToString(contractField.Constant.Value); // Calling the toString method to compare in since we might have the case where one Enum is type a and the other is type b, but they might still have same value. if (implValue != contractValue) { ITypeReference implValType = impl.ContainingTypeDefinition.GetEnumType(); ITypeReference contractValType = contract.ContainingTypeDefinition.GetEnumType(); differences.AddIncompatibleDifference(this, $"Enum value '{implField.FullName()}' is ({implValType.FullName()}){implField.Constant.Value} in the {Implementation} but ({contractValType.FullName()}){contractField.Constant.Value} in the {Contract}."); return(DifferenceType.Changed); } return(DifferenceType.Unknown); }
public override DifferenceType Diff(IDifferences differences, ITypeDefinitionMember impl, ITypeDefinitionMember contract) { var implMethod = impl as IMethodDefinition; var contractMethod = contract as IMethodDefinition; if (implMethod == null || contractMethod == null) { return(DifferenceType.Unknown); } bool changed = CheckAttributeDifferences(differences, implMethod, implMethod.Attributes, implMethod.Attributes); IParameterDefinition[] method1Params = implMethod.Parameters.ToArray(); IParameterDefinition[] method2Params = contractMethod.Parameters.ToArray(); for (int i = 0; i < implMethod.ParameterCount; i++) { changed |= CheckAttributeDifferences(differences, method1Params[i], method1Params[i].Attributes, method2Params[i].Attributes, member: implMethod); } if (implMethod.IsGeneric) { IGenericParameter[] method1GenParams = implMethod.GenericParameters.ToArray(); IGenericParameter[] method2GenParam = contractMethod.GenericParameters.ToArray(); for (int i = 0; i < implMethod.GenericParameterCount; i++) { changed |= CheckAttributeDifferences(differences, method1GenParams[i], method1GenParams[i].Attributes, method2GenParam[i].Attributes, member: implMethod); } } return(changed ? DifferenceType.Changed : DifferenceType.Unchanged); }
public override DifferenceType Diff(IDifferences differences, ITypeDefinitionMember impl, ITypeDefinitionMember contract) { if (impl == null || contract == null) { return(DifferenceType.Unknown); } // If implementation is public then contract can be any visibility if (impl.Visibility == TypeMemberVisibility.Public) { return(DifferenceType.Unknown); } // If implementation is protected or protected internal then contract must be protected or protected internal as well. if (impl.Visibility == TypeMemberVisibility.Family || impl.Visibility == TypeMemberVisibility.FamilyOrAssembly) { if (contract.Visibility != TypeMemberVisibility.Family && contract.Visibility != TypeMemberVisibility.FamilyOrAssembly) { differences.AddIncompatibleDifference(this, $"Visibility of member '{impl.FullName()}' is '{impl.Visibility}' in the {Implementation} but '{contract.Visibility}' in the {Contract}."); return(DifferenceType.Changed); } } return(DifferenceType.Unknown); }
public virtual bool Include(ITypeDefinitionMember member) { if (member == null) { return(false); } if (!member.ContainingTypeDefinition.IsVisibleOutsideAssembly()) { return(false); } switch (member.Visibility) { case TypeMemberVisibility.Public: return(true); case TypeMemberVisibility.Family: case TypeMemberVisibility.FamilyOrAssembly: // CCI's version of IsVisibleOutsideAssembly doesn't // consider protected members as being visible but for // our purposes which is to write CS files that can // be compiled we always need the protected members return(true); } if (!member.IsVisibleOutsideAssembly()) { return(false); } return(true); }
public bool Include(ITypeDefinitionMember member) { string memberId = member.DocId(); // include so long as it isn't in the exclude list. return(!_docIds.Contains(memberId)); }
public virtual bool Include(ITypeDefinitionMember member) { // Include internal and private protected members. if (member.Visibility == TypeMemberVisibility.Family || member.Visibility == TypeMemberVisibility.FamilyAndAssembly) { // Similar to special case in PublicOnlyCciFilter, include protected members even of a sealed type. // This is necessary to generate compilable code e.g. callers with IVT dependencies on this assembly // may call internal methods in a sealed type. (IsVisibleToFriendAssemblies() includes the IsSealed // check for other use cases besides this one.) return(true); } // Include public(-ish) members and explicit interface implementations. if (member.IsVisibleToFriendAssemblies()) { return(true); } // If a type is abstract and has an internal or public constructor, it must expose all abstract members. var containingType = member.ContainingTypeDefinition; if (containingType.IsAbstract && member.IsAbstract() && containingType.IsConstructorVisibleToFriendAssemblies()) { return(true); } // Otherwise... return(false); }
public void WriteMemberDeclaration(ITypeDefinitionMember member) { IMethodDefinition method = member as IMethodDefinition; if (method != null) { WriteMethodDefinition(method); return; } IPropertyDefinition property = member as IPropertyDefinition; if (property != null) { WritePropertyDefinition(property); return; } IEventDefinition evnt = member as IEventDefinition; if (evnt != null) { WriteEventDefinition(evnt); return; } IFieldDefinition field = member as IFieldDefinition; if (field != null) { WriteFieldDefinition(field); return; } _writer.Write("Unknown member definitions type {0}", member.ToString()); }
private static string GetReturnTypeName(ITypeMemberReference typeMemberReference) { ITypeDefinitionMember typeDefinitionMember = typeMemberReference.ResolvedTypeDefinitionMember; var fieldDefinition = typeDefinitionMember as IFieldDefinition; if (fieldDefinition != null) { return(GetName(fieldDefinition.Type)); } var propertyDefinition = typeDefinitionMember as IPropertyDefinition; if (propertyDefinition != null) { return(GetName(propertyDefinition.Type)); } var methodDefinition = typeDefinitionMember as IMethodDefinition; if (methodDefinition != null && !methodDefinition.IsConstructor && !methodDefinition.IsStaticConstructor) { return(GetName(methodDefinition.Type)); } return(null); }
public bool?IsUnsafe(ITypeDefinitionMember member) { var field = member as IFieldDefinition; if (field != null) { return(field.Type.IsUnsafeType()); } var method = member as IMethodDefinition; if (method != null) { return(method.IsMethodUnsafe()); } var property = member as IPropertyDefinition; if (property != null) { return(property.Accessors.Any(a => CSharpCciExtensions.IsMethodUnsafe(a.ResolvedMethod))); } var evnt = member as IEventDefinition; if (evnt != null) { return(evnt.Accessors.Any(a => a.ResolvedMethod.IsMethodUnsafe())); } return(null); }
public static string MemberGroupHeading(ITypeDefinitionMember member) { if (member == null) return null; IMethodDefinition method = member as IMethodDefinition; if (method != null) { if (method.IsConstructor) return "Constructors"; return "Methods"; } IFieldDefinition field = member as IFieldDefinition; if (field != null) return "Fields"; IPropertyDefinition property = member as IPropertyDefinition; if (property != null) return "Properties"; IEventDefinition evnt = member as IEventDefinition; if (evnt != null) return "Events"; INestedTypeDefinition nType = member as INestedTypeDefinition; if (nType != null) return "Nested Types"; return null; }
public override void Visit(ITypeDefinitionMember member) { IDisposable style = null; if (_styleWriter != null) { // Favor overrides over interface implemenations (i.e. consider override Dispose() as an override and not an interface implementation) if (this.HighlightBaseMembers && member.IsOverride()) { style = _styleWriter.StartStyle(SyntaxStyle.InheritedMember); } else if (this.HighlightInterfaceMembers && member.IsInterfaceImplementation()) { style = _styleWriter.StartStyle(SyntaxStyle.InterfaceMember); } } _declarationWriter.WriteDeclaration(member); if (style != null) { style.Dispose(); } _syntaxWriter.WriteLine(); base.Visit(member); }
public static List <ITypeDefinitionMember> FindRelatedInterfaceMembers(ITypeDefinitionMember member) { List <ITypeDefinitionMember> relatedMembers = new List <ITypeDefinitionMember>(); Dictionary <uint, ITypeReference> participatingTypes = new Dictionary <uint, ITypeReference>(); ITypeDefinition currentType = member.ContainingTypeDefinition; foreach (ITypeReference iface in currentType.Interfaces) { // check the closure against the template type, but add // the specialized type to participatingTypes so that // argument matching works if (!participatingTypes.ContainsKey(iface.InternedKey)) { participatingTypes.Add(iface.InternedKey, iface); } } foreach (ITypeReference type in participatingTypes.Values) { ITypeDefinitionMember relatedMember = FindRelatedMember(type, member); if (null != relatedMember) { relatedMembers.Add(relatedMember); } } return(relatedMembers); }
public virtual bool Include(ITypeDefinitionMember member) { if (member == null) return false; if (!member.ContainingTypeDefinition.IsVisibleOutsideAssembly()) return false; switch (member.Visibility) { case TypeMemberVisibility.Public: return true; case TypeMemberVisibility.Family: case TypeMemberVisibility.FamilyOrAssembly: // CCI's version of IsVisibleOutsideAssembly doesn't // consider protected members as being visible but for // our purposes which is to write CS files that can // be compiled we always need the protected members return true; } if (!member.IsVisibleOutsideAssembly()) return false; return true; }
public virtual bool Include(ITypeDefinitionMember member) { var evnt = member as IEventDefinition; if (evnt != null) { return(Include(evnt)); } var prop = member as IPropertyDefinition; if (prop != null) { return(Include(prop)); } var method = member as IMethodDefinition; if (method != null) { return(Include(method)); } return(true); }
private bool CanIgnoreAddedInterfaceMember(ITypeDefinitionMember member) { if (!RuleSettings.AllowDefaultInterfaceMethods) { return(false); } // Default Implementation Method (DIM) scenario. // On DIM, static fields or methods that are not abstract, // have conditional implementation and should not be considered a break if (member is IFieldDefinition field) { return(field.IsStatic); } if (member is IMethodDefinition method) { return(!method.IsAbstract); } // We can ignore PropertyDefinition and IEventDefinition // For properties we will receive the changes on the getter and setter as IMethodDefinition later // For events we will receive the changes on the adder and remover as IMethodDefinition later if (member is IPropertyDefinition || member is IEventDefinition) { return(true); } return(false); }
public override DifferenceType Diff(IDifferences differences, ITypeDefinitionMember impl, ITypeDefinitionMember contract) { if (impl == null || contract == null) return DifferenceType.Unknown; bool isImplOverridable = IsOverridable(impl); bool isContractOverridable = IsOverridable(contract); /* //@todo: Move to a separate rule that's only run in "strict" mode. if (isImplInhertiable && !isContractInheritiable) { // This is separate because it can be noisy and is generally allowed as long as it is reviewed properly. differences.AddIncompatibleDifference("CannotMakeMemberVirtual", "Member '{0}' is virtual in the implementation but non-virtual in the contract.", impl.FullName()); return DifferenceType.Changed; } */ if (isContractOverridable && !isImplOverridable) { differences.AddIncompatibleDifference("CannotMakeMemberNonVirtual", "Member '{0}' is non-virtual in the implementation but is virtual in the contract.", impl.FullName()); return DifferenceType.Changed; } return DifferenceType.Unknown; }
public ThinMember(ThinType declaringType, string memberName, string returnType, MemberTypes memberType, IncludeStatus includeStatus, ITypeDefinitionMember memberNode, VisibilityOverride visibility) : this(declaringType, memberName, returnType, memberType, includeStatus, memberNode, visibility, SecurityTransparencyStatus.Transparent) { }
public override DifferenceType Diff(IDifferences differences, Mappings.MemberMapping mapping) { ITypeDefinitionMember impl = mapping[0]; ITypeDefinitionMember contract = mapping[1]; if (impl == null) { return(DifferenceType.Unknown); } if (contract == null && impl.IsAbstract()) { // If the type is effectively sealed then it is ok to remove abstract members ITypeDefinition contractType = mapping.ContainingType[1]; // We check that interfaces have the same number of members in another rule so there is no need to check that here. if (contractType != null && (contractType.IsEffectivelySealed() || (contractType.IsInterface && mapping.ContainingType[0].IsInterface))) { return(DifferenceType.Unknown); } differences.AddIncompatibleDifference(this, impl.GetMemberViolationMessage("Member", $"is abstract in the {Implementation}", $"is missing in the {Contract}")); return(DifferenceType.Changed); } return(DifferenceType.Unknown); }
public override DifferenceType Diff(IDifferences differences, ITypeDefinitionMember impl, ITypeDefinitionMember contract) { if (impl == null || contract == null) { return(DifferenceType.Unknown); } bool isImplOverridable = IsOverridable(impl); bool isContractOverridable = IsOverridable(contract); /* * //@todo: Move to a separate rule that's only run in "strict" mode. * if (isImplInhertiable && !isContractInheritiable) * { * // This is separate because it can be noisy and is generally allowed as long as it is reviewed properly. * differences.AddIncompatibleDifference("CannotMakeMemberVirtual", * "Member '{0}' is virtual in the implementation but non-virtual in the contract.", * impl.FullName()); * * return DifferenceType.Changed; * } */ if (isContractOverridable && !isImplOverridable) { differences.AddIncompatibleDifference("CannotMakeMemberNonVirtual", $"Member '{impl.FullName()}' is non-virtual in the {Implementation} but is virtual in the {Contract}."); return(DifferenceType.Changed); } return(DifferenceType.Unknown); }
private static bool IsStatic(ITypeDefinitionMember member) { var f = member as IFieldDefinition; if (f != null) { return(f.IsStatic); } var p = member as IPropertyDefinition; if (p != null) { return(p.IsStatic); } var e = member as IEventDefinition; if (e != null) { return(e.Adder.IsStatic || e.Remover.IsStatic); } var method = (IMethodDefinition)member; return(method.IsStatic || method.IsStaticConstructor); }
public override DifferenceType Diff(IDifferences differences, ITypeDefinitionMember impl, ITypeDefinitionMember contract) { if (impl == null || contract == null) return DifferenceType.Unknown; if (!impl.ContainingTypeDefinition.IsEnum || !contract.ContainingTypeDefinition.IsEnum) return DifferenceType.Unknown; IFieldDefinition implField = impl as IFieldDefinition; IFieldDefinition contractField = contract as IFieldDefinition; Contract.Assert(implField != null || contractField != null); string implValue = Convert.ToString(implField.Constant.Value); string contractValue = Convert.ToString(contractField.Constant.Value); // Calling the toString method to compare in since we might have the case where one Enum is type a and the other is type b, but they might still have same value. if (implValue != contractValue) { ITypeReference implValType = impl.ContainingTypeDefinition.GetEnumType(); ITypeReference contractValType = contract.ContainingTypeDefinition.GetEnumType(); differences.AddIncompatibleDifference(this, "Enum value '{0}' is ({1}){2} in the implementation but ({3}){4} in the contract.", implField.FullName(), implValType.FullName(), implField.Constant.Value, contractValType.FullName(), contractField.Constant.Value); return DifferenceType.Changed; } return DifferenceType.Unknown; }
public static bool IsVisibleToFriendAssemblies(this ITypeDefinitionMember member) { // MemberHelper in CCI doesn't have a method like IsVisibleOutsideAssembly(...) to use here. This method // has similar behavior except that it returns true for all internal and internal protected members as well // as non-sealed private protected members. switch (member.Visibility) { case TypeMemberVisibility.Assembly: case TypeMemberVisibility.FamilyOrAssembly: case TypeMemberVisibility.Public: return(true); case TypeMemberVisibility.Family: case TypeMemberVisibility.FamilyAndAssembly: return(!member.ContainingTypeDefinition.IsSealed); } var containingType = member.ContainingTypeDefinition; return(member switch { IMethodDefinition methodDefinition => IsExplicitImplementationVisible(methodDefinition, containingType), IPropertyDefinition propertyDefinition => IsExplicitImplementationVisible(propertyDefinition.Getter, containingType) || IsExplicitImplementationVisible(propertyDefinition.Setter, containingType), IEventDefinition eventDefinition => IsExplicitImplementationVisible(eventDefinition.Adder, containingType) || IsExplicitImplementationVisible(eventDefinition.Remover, containingType), _ => false, });
public virtual bool Include(ITypeDefinitionMember member) { switch (member.Visibility) { case TypeMemberVisibility.Public: return(true); case TypeMemberVisibility.Family: case TypeMemberVisibility.FamilyOrAssembly: // CCI's version of IsVisibleOutsideAssembly doesn't // consider protected members as being visible but for // our purposes which is to write CS files that can // be compiled we always need the protected members return(true); } if (!member.IsVisibleOutsideAssembly()) { // If a type is public, abstract and has a public constructor, // then it must expose all abstract members. if (member.ContainingTypeDefinition.IsAbstract && member.IsAbstract() && member.ContainingTypeDefinition.IsConstructorVisible() ) { return(true); } return(false); } return(true); }
public MemberMapping FindMember(ITypeDefinitionMember member) { MemberMapping mapping = null; _members.TryGetValue(member, out mapping); return(mapping); }
public override DifferenceType Diff(IDifferences differences, ITypeDefinitionMember impl, ITypeDefinitionMember contract) { if (impl == null || contract == null) { return(DifferenceType.Unknown); } // If implementation is public then contract can be any visibility if (impl.Visibility == TypeMemberVisibility.Public) { return(DifferenceType.Unknown); } // If implementation is protected then contract must be protected as well. if (impl.Visibility == TypeMemberVisibility.Family) { if (contract.Visibility != TypeMemberVisibility.Family) { differences.AddIncompatibleDifference(this, "Visibility of member '{0}' is '{1}' in the implementation but '{2}' in the contract.", impl.FullName(), impl.Visibility, contract.Visibility); return(DifferenceType.Changed); } } return(DifferenceType.Unknown); }
public static ITypeReference GetReturnType(this ITypeDefinitionMember member) { IMethodDefinition method = member as IMethodDefinition; if (method != null) { return(method.Type); } IPropertyDefinition property = member as IPropertyDefinition; if (property != null) { return(property.Type); } IEventDefinition evnt = member as IEventDefinition; if (evnt != null) { return(evnt.Type); } IFieldDefinition field = member as IFieldDefinition; if (field != null) { return(field.Type); } return(null); }
/// <summary> /// Creates a new instance of the class. /// </summary> /// <param name="container">The containing type.</param> /// <param name="memberDef">The CCI member definition.</param> internal ScriptMember(ScriptType container, ITypeDefinitionMember memberDef) { if (container == null || memberDef == null) throw new InvalidOperationException(); _container = container; _cciMember = memberDef; }
// this method takes into account the FrameworkInternal annotation private bool IsMemberExternallyVisible2(ITypeDefinitionMember member) { return ((member.Visibility == TypeMemberVisibility.Public || member.Visibility == TypeMemberVisibility.Family || member.Visibility == TypeMemberVisibility.FamilyOrAssembly || m_implModel.IsFrameworkInternal(member)) && IsTypeExternallyVisible2(Util.ContainingTypeDefinition(member))); }
public override void TraverseChildren(ITypeDefinitionMember typeMember) { if (!_filter.Include(typeMember)) { return; } base.TraverseChildren(typeMember); }
public override void TraverseChildren(ITypeDefinitionMember typeMember) { if (this.PrintDefinitionSourceLocations(typeMember)) { this.sourceEmitterOutput.WriteLine(MemberHelper.GetMemberSignature(typeMember, NameFormattingOptions.DocumentationId)); } base.TraverseChildren(typeMember); }
// How MDIL affects member visibility: // // - A member marked [TreatAsPublicSurface] is treated as public regardless of its own visibility or that of its containing type. // public override bool Include(ITypeDefinitionMember member) { if (member == null) return false; //if (member.IsTreatedAsVisibleOutsideAssembly()) // return true; return base.Include(member); }
public static string GetMemberId(ITypeDefinitionMember member) { Contract.Requires(member != null); Contract.Ensures(Contract.Result<string>() != null); using (TextWriter writer = new StringWriter()) { WriteMember(member, writer); return (writer.ToString()); } }
public ThinMember(ThinType declaringType, ThinMember memberToCopy) { _declaringType = declaringType; _memberNode = memberToCopy._memberNode; _memberFullName = memberToCopy._memberFullName; _returnType = memberToCopy._returnType; _memberType = memberToCopy._memberType; _includeStatus = memberToCopy._includeStatus; _visibility = memberToCopy._visibility; _securityTransparencyStatus = memberToCopy._securityTransparencyStatus; CheckVisibility(); }
private bool IsOverridable(ITypeDefinitionMember member) { if (!member.IsVirtual()) return false; // member virtual final is not overridable if (member.IsSealed()) return false; // if member type is Effectively sealed and cannot be extended, then the member cannot be inherited if (member.ContainingTypeDefinition != null && member.ContainingTypeDefinition.IsEffectivelySealed()) return false; return true; }
public override DifferenceType Diff(IDifferences differences, ITypeDefinitionMember impl, ITypeDefinitionMember contract) { if (impl == null || contract == null) return DifferenceType.Unknown; bool added = false; //added |= AnyAttributeAdded(differences, impl, impl.Attributes, contract.Attributes); //added |= AnyMethodSpecificAttributeAdded(differences, impl as IMethodDefinition, contract as IMethodDefinition); if (added) return DifferenceType.Changed; return DifferenceType.Unknown; }
public ThinMember(ThinType declaringType, string memberName, string returnType, MemberTypes memberType, IncludeStatus includeStatus, ITypeDefinitionMember memberNode, VisibilityOverride visibility, SecurityTransparencyStatus securityTransparencyStatus) { _memberNode = memberNode; _declaringType = declaringType; _returnType = returnType; _memberType = memberType; _includeStatus = includeStatus; _visibility = visibility; _securityTransparencyStatus = securityTransparencyStatus; _memberFullName = memberName; CheckVisibility(); }
public override DifferenceType Diff(IDifferences differences, ITypeDefinitionMember impl, ITypeDefinitionMember contract) { if (impl == null || contract == null) return DifferenceType.Unknown; IMethodDefinition method1 = impl as IMethodDefinition; IMethodDefinition method2 = contract as IMethodDefinition; if (method1 == null || method2 == null) return DifferenceType.Unknown; if (!ParamModifiersMatch(differences, method1, method2)) return DifferenceType.Changed; return DifferenceType.Unknown; }
public override DifferenceType Diff(IDifferences differences, ITypeDefinitionMember impl, ITypeDefinitionMember contract) { if (impl == null || contract == null) return DifferenceType.Unknown; IMethodDefinition implMethod = impl as IMethodDefinition; IMethodDefinition contractMethod = contract as IMethodDefinition; if (implMethod == null || contractMethod == null) return DifferenceType.Unknown; if (!ParamNamesMatch(differences, implMethod, contractMethod)) return DifferenceType.Changed; return DifferenceType.Unknown; }
public override DifferenceType Diff(IDifferences differences, ITypeDefinitionMember impl, ITypeDefinitionMember contract) { if (impl == null || contract == null) return DifferenceType.Unknown; if (impl.IsAbstract() && !contract.IsAbstract()) { differences.AddIncompatibleDifference("CannotMakeMemberAbstract", "Member '{0}' is abstract in the implementation but is not abstract in the contract.", impl.FullName()); return DifferenceType.Changed; } return DifferenceType.Unknown; }
public override DifferenceType Diff(IDifferences differences, ITypeDefinitionMember impl, ITypeDefinitionMember contract) { if (contract != null && impl == null) { if (contract.ContainingTypeDefinition.IsInterface) { differences.AddIncompatibleDifference(this, "Contract interface member '{0}' is not in the implementation.", contract.FullName()); return DifferenceType.Changed; } } if (impl != null && contract == null) { if (impl.ContainingTypeDefinition.IsInterface) { differences.AddIncompatibleDifference(this, "Implementation interface member '{0}' is not in the contract.", impl.FullName()); return DifferenceType.Changed; } } return base.Diff(differences, impl, contract); }
private static void WriteMember(ITypeDefinitionMember member, TextWriter writer) { Contract.Requires(member != null); Contract.Requires(writer != null); IMethodDefinition method = member as IMethodDefinition; if (method != null) { writer.Write("M:"); WriteMethod(method, writer); return; } IFieldDefinition field = member as IFieldDefinition; if (field != null) { writer.Write("F:"); WriteField(field, writer); return; } IPropertyDefinition property = member as IPropertyDefinition; if (property != null) { writer.Write("P:"); WriteProperty(property, writer); return; } IEventDefinition eventdef = member as IEventDefinition; if (eventdef != null) { writer.Write("E:"); WriteEvent(eventdef, writer); return; } throw new NotImplementedException("missing case"); }
public override DifferenceType Diff(IDifferences differences, ITypeDefinitionMember impl, ITypeDefinitionMember contract) { if (impl == null || contract == null) return DifferenceType.Unknown; // If implementation is public then contract can be any visibility if (impl.Visibility == TypeMemberVisibility.Public) return DifferenceType.Unknown; // If implementation is protected then contract must be protected as well. if (impl.Visibility == TypeMemberVisibility.Family) { if (contract.Visibility != TypeMemberVisibility.Family) { differences.AddIncompatibleDifference(this, "Visibility of member '{0}' is '{1}' in the implementation but '{2}' in the contract.", impl.FullName(), impl.Visibility, contract.Visibility); return DifferenceType.Changed; } } return DifferenceType.Unknown; }
public ThinMember(ThinType declaringType, ITypeDefinitionMember member, IncludeStatus includeStatus, VisibilityOverride visibility) { _declaringType = declaringType; _memberNode = member; _memberType = Util.TypeMemberType(member); _returnType = Util.GetConversionOperatorReturnType(member); _memberFullName = Util.GetMemberSignature(member, false); // Remove the trailing return type for conversion operators if (_returnType != null) { string suffix = " : " + _returnType; if (_memberFullName.EndsWith(suffix)) _memberFullName = _memberFullName.Substring(0, _memberFullName.Length - suffix.Length); } _includeStatus = includeStatus; _visibility = visibility; _securityTransparencyStatus = SecurityTransparencyStatus.Transparent; CheckVisibility(); }
private bool ShouldHideMember(ITypeDefinitionMember member) { bool shouldHide = false; INamedTypeDefinition type = Util.ContainingTypeDefinition(member); if (IsHiddenMemberCandidate(member)) { if (!TypeIsVisibleInApi(type)) { // Declaring type is hidden, only modify the visibility on a // member when its corresponding member on a public base type // was hidden. INamedTypeDefinition baseType = Util.CanonicalizeType(TypeHelper.BaseClass(type)); while (baseType != null && baseType != Dummy.Type) { if (TypeIsVisibleInApi(baseType)) { ITypeDefinitionMember relatedMember = Util.FindRelatedMember(baseType, member); if (relatedMember != null) { ITypeDefinitionMember canonicalizedRelatedMember = Util.CanonicalizeMember(relatedMember); if (_depot.ContainsMember(canonicalizedRelatedMember) && ShouldHideMember(canonicalizedRelatedMember)) { shouldHide = true; break; } } } baseType = Util.CanonicalizeType(TypeHelper.BaseClass(baseType)); } } else { // declaring type is public, we must hide the member. shouldHide = true; } } return shouldHide; }
private bool IsHiddenMemberCandidate(ITypeDefinitionMember member) { return !Util.IsApi(GetIncludeStatus(member)) && Util.IsMemberExternallyVisible(member); }
private IncludeStatus GetIncludeStatus(ITypeDefinitionMember member) { ThinMember modelMember; if (!_rootMembers.TryGetValue(member, out modelMember)) { if (_depot.ContainsMember(member)) { // Special case ImplRoot // TODO: Visitor should set status instead. if (_closureStatus == IncludeStatus.ApiRoot && !Util.IsMemberExternallyVisible(member)) { return IncludeStatus.ImplRoot; } return _closureStatus; } throw new Exception("could not find IncludeStatus for member " + member.ToString()); } return modelMember.IncludeStatus; }
public virtual void AddMemberReference(ITypeDefinitionMember member) { Debug.Assert(CanInclude(Util.CanonicalizeTypeReference(member.ContainingType))); Debug.Assert(member == Util.CanonicalizeMember(member)); _depot.AddMemberReference(member); //if (!(member is IFieldDefinition && member.Name.Value.Equals("value__"))) //{ // _depot.AddMemberReference(member); //} //else //{ // // TODO: "value__" field accesses here. are those "this" pointer accesses? // // For now just ignore them. They could theoretically be used to make classic static when // // none of their instance methods are used. //} }
public bool ContainsMember(ITypeDefinitionMember member) { IMethodDefinition method = member as IMethodDefinition; if (method != null) return _methodsClosure.ContainsKey(method.InternedKey); else return _membersClosure.ContainsKey(member); }
public bool /*IApiInformationProvider.*/IsFrameworkInternal(ITypeDefinitionMember member) { // if member is a nested type we should be looking for it in _rootTypes INamedTypeDefinition type = member as INamedTypeDefinition; if (type != null) return IsFrameworkInternal(type); else return _rootMembers.ContainsKey(member) && _rootMembers[member].IncludeStatus == IncludeStatus.ApiFxInternal; }
public bool Contains(ITypeDefinitionMember member) { return false; }
public override void Visit(ITypeDefinitionMember typeMember) { m_implModel.AddTypeReference(Util.CanonicalizeTypeReference(typeMember.ContainingType)); base.Visit(typeMember); }
public override void TraverseChildren(ITypeDefinitionMember typeMember) { base.TraverseChildren(typeMember); }
public bool Contains(ITypeDefinitionMember member) { throw new NotImplementedException(); }