public virtual bool Include(TypeMapping type) { bool anyIncluded = false; for (int i = 0; i < type.ElementCount; i++) { if (type[i] != null && _filter.Include(type[i])) { anyIncluded = true; } } if (!anyIncluded) { return(false); } if (Include(type.Difference)) { return(true); } if (type.ShouldDiffMembers) { return(type.Members.Any(Include)); } return(false); }
public static IEventDefinition GetHiddenBaseEvent(this IEventDefinition evnt, ICciFilter filter = null) { IMethodDefinition eventRep = evnt.Adder.ResolvedMethod; if (eventRep.IsVirtual && !eventRep.IsNewSlot) { return(Dummy.Event); // an override } foreach (ITypeReference baseClassRef in evnt.ContainingTypeDefinition.GetAllBaseTypes()) { ITypeDefinition baseClass = baseClassRef.ResolvedType; foreach (IEventDefinition baseEvent in baseClass.GetMembersNamed(evnt.Name, false).OfType <IEventDefinition>()) { if (baseEvent.Visibility == TypeMemberVisibility.Private) { continue; } if (IsAssembly(baseEvent) && !InSameUnit(baseEvent, evnt)) { continue; } if (filter != null && !filter.Include(baseEvent)) { continue; } return(baseEvent); } } return(Dummy.Event); }
public static IFieldDefinition GetHiddenBaseField(this IFieldDefinition field, ICciFilter filter = null) { foreach (ITypeReference baseClassRef in field.ContainingTypeDefinition.GetAllBaseTypes()) { ITypeDefinition baseClass = baseClassRef.ResolvedType; foreach (IFieldDefinition baseField in baseClass.GetMembersNamed(field.Name, false).OfType <IFieldDefinition>()) { if (baseField.Visibility == TypeMemberVisibility.Private) { continue; } if (IsAssembly(baseField) && !InSameUnit(baseField, field)) { continue; } if (filter != null && !filter.Include(baseField)) { continue; } return(baseField); } } return(Dummy.Field); }
public static ITypeDefinition GetHiddenBaseType(this ITypeDefinition type, ICciFilter filter = null) { if (!(type is INestedTypeDefinition nestedType)) { return(Dummy.Type); } ITypeDefinition containingType = nestedType.ContainingTypeDefinition; foreach (ITypeReference baseClassRef in containingType.GetAllBaseTypes()) { ITypeDefinition baseClass = baseClassRef.ResolvedType; foreach (ITypeDefinition baseType in baseClass.GetMembersNamed(nestedType.Name, ignoreCase: false).OfType <ITypeDefinition>()) { if (baseType.GetVisibility() == TypeMemberVisibility.Private) { continue; } if (IsAssembly(baseType) && !InSameUnit(baseType, nestedType)) { continue; } if (filter != null && !filter.Include(baseType)) { continue; } return(baseType); } } return(Dummy.Type); }
public static IMethodDefinition GetHiddenBaseMethod(this IMethodDefinition method, ICciFilter filter = null) { if (method.IsConstructor) { return(Dummy.Method); } if (method.IsVirtual && !method.IsNewSlot) { return(Dummy.Method); // an override } ITypeDefinition type = method.ContainingTypeDefinition; foreach (ITypeReference baseClassRef in type.GetAllBaseTypes()) { ITypeDefinition baseClass = baseClassRef.ResolvedType; foreach (IMethodDefinition baseMethod in baseClass.GetMembersNamed(method.Name, false).OfType <IMethodDefinition>()) { if (baseMethod.Visibility == TypeMemberVisibility.Private) { continue; } if (IsAssembly(baseMethod) && !InSameUnit(baseMethod, method)) { continue; } if (filter != null && !filter.Include(baseMethod.UnWrapMember())) { continue; } // NOTE: Do not check method.IsHiddenBySignature here. C# is *always* hide-by-signature regardless of the metadata flag. // Do not check return type here, C# hides based on parameter types alone. if (SignaturesParametersAreEqual(method, baseMethod)) { if (!method.IsGeneric && !baseMethod.IsGeneric) { return(baseMethod); } if (method.GenericParameterCount == baseMethod.GenericParameterCount) { return(baseMethod); } } } } return(Dummy.Method); }
public static IPropertyDefinition GetHiddenBaseProperty(this IPropertyDefinition property, ICciFilter filter = null) { IMethodDefinition propertyRep = property.Accessors.First().ResolvedMethod; if (propertyRep.IsVirtual && !propertyRep.IsNewSlot) { return(Dummy.Property); // an override } ITypeDefinition type = property.ContainingTypeDefinition; foreach (ITypeReference baseClassRef in type.GetAllBaseTypes()) { ITypeDefinition baseClass = baseClassRef.ResolvedType; foreach (IPropertyDefinition baseProperty in baseClass.GetMembersNamed(property.Name, false).OfType <IPropertyDefinition>()) { if (baseProperty.Visibility == TypeMemberVisibility.Private) { continue; } if (IsAssembly(baseProperty) && !InSameUnit(baseProperty, property)) { continue; } if (filter != null && !filter.Include(baseProperty)) { continue; } if (SignaturesParametersAreEqual(property, baseProperty)) { return(baseProperty); } } } return(Dummy.Property); }
public override void TraverseChildren(INamespaceDefinition namespaceDefinition) { if (!_filter.Include(namespaceDefinition)) { return; } base.TraverseChildren(namespaceDefinition); }
public bool Include(INamespaceDefinition ns) { return(_left.Include(ns) || _right.Include(ns)); }
public override void Visit(ITypeDefinition parentType, IEnumerable <IFieldDefinition> fields) { if (parentType.IsStruct && !_apiOnly) { // For compile-time compat, the following rules should work for producing a reference assembly. We drop all private fields, // but add back certain synthesized private fields for a value type (struct) as follows: // 1. If there is a ref field or reference type field in the struct or within the fields' type closure, // it should emit a reference type and a value type dummy field. // - The reference type dummy field is needed in order to inform the compiler to block // taking pointers to this struct because the GC will not track updating those references. // - The value type dummy field is needed in order for the compiler to error correctly on definite assignment checks in all scenarios. dotnet/roslyn#30194 // 2. If there are no reference type fields, but there are value type fields in the struct field closure, // and at least one of these fields is a nonempty struct, then we should emit a value type dummy field. // - The previous rules are for definite assignment checks, so the compiler knows there is a private field // that has not been initialized to error about uninitialized structs. // // 3. If the type is generic, then for every type parameter of the type, if there are any private // or internal fields that are or contain any members whose type is that type parameter, // we add a direct private field of that type. // - Compiler needs to see all fields that have generic arguments (even private ones) to be able // to validate there aren't any struct layout cycles. // Note: By "private", we mean not visible outside the assembly. // For more details see issue https://github.com/dotnet/corefx/issues/6185 // this blog is helpful as well http://blog.paranoidcoding.com/2016/02/15/are-private-members-api-surface.html List <IFieldDefinition> newFields = new List <IFieldDefinition>(); var includedVisibleFields = fields.Where(f => _cciFilter.Include(f)); includedVisibleFields = includedVisibleFields.OrderBy(GetMemberKey, StringComparer.OrdinalIgnoreCase); var excludedFields = fields.Except(includedVisibleFields).Where(f => !f.IsStatic); if (excludedFields.Any()) { var genericTypedFields = excludedFields.Where(f => f.Type.UnWrap().IsGenericParameter()); foreach (var genericField in genericTypedFields) { IFieldDefinition fieldType = new DummyPrivateField(parentType, genericField.Type, genericField.Name.Value, genericField.Attributes.Where(a => !a.FullName().EndsWith("NullAttribute")), genericField.IsReadOnly); newFields.Add(fieldType); } IFieldDefinition intField = DummyFieldWriterHelper(parentType, excludedFields, parentType.PlatformType.SystemInt32, "_dummyPrimitive"); bool hasRefPrivateField = excludedFields.Any(f => f.Type.IsOrContainsReferenceType()); if (hasRefPrivateField) { newFields.Add(DummyFieldWriterHelper(parentType, excludedFields, parentType.PlatformType.SystemObject)); newFields.Add(intField); } else { bool hasNonEmptyStructPrivateField = excludedFields.Any(f => f.Type.IsOrContainsNonEmptyStruct()); if (hasNonEmptyStructPrivateField) { newFields.Add(intField); } } } foreach (var visibleField in includedVisibleFields) { newFields.Add(visibleField); } foreach (var field in newFields) { Visit(field); } } else { base.Visit(parentType, fields); } }
public bool Include(INamespaceDefinition ns) { return(!_filter.Include(ns)); }
public static IMethodDefinition GetHiddenBaseMethod(this IMethodDefinition method, ICciFilter filter = null) { if (method.IsConstructor) return Dummy.Method; if (method.IsVirtual && !method.IsNewSlot) return Dummy.Method; // an override ITypeDefinition type = method.ContainingTypeDefinition; foreach (ITypeReference baseClassRef in type.GetAllBaseTypes()) { ITypeDefinition baseClass = baseClassRef.ResolvedType; foreach (IMethodDefinition baseMethod in baseClass.GetMembersNamed(method.Name, false).OfType<IMethodDefinition>()) { if (baseMethod.Visibility == TypeMemberVisibility.Private) continue; if (IsAssembly(baseMethod) && !InSameUnit(baseMethod, method)) continue; if (filter != null && !filter.Include(baseMethod)) continue; // NOTE: Do not check method.IsHiddenBySignature here. C# is *always* hide-by-signature regardless of the metadata flag. // Do not check return type here, C# hides based on parameter types alone. if (SignaturesParametersAreEqual(method, baseMethod)) { if (!method.IsGeneric && !baseMethod.IsGeneric) return baseMethod; if (method.GenericParameterCount == baseMethod.GenericParameterCount) return baseMethod; } } } return Dummy.Method; }
public static IPropertyDefinition GetHiddenBaseProperty(this IPropertyDefinition property, ICciFilter filter = null) { IMethodDefinition propertyRep = property.Accessors.First().ResolvedMethod; if (propertyRep.IsVirtual && !propertyRep.IsNewSlot) return Dummy.Property; // an override ITypeDefinition type = property.ContainingTypeDefinition; foreach (ITypeReference baseClassRef in type.GetAllBaseTypes()) { ITypeDefinition baseClass = baseClassRef.ResolvedType; foreach (IPropertyDefinition baseProperty in baseClass.GetMembersNamed(property.Name, false).OfType<IPropertyDefinition>()) { if (baseProperty.Visibility == TypeMemberVisibility.Private) continue; if (IsAssembly(baseProperty) && !InSameUnit(baseProperty, property)) continue; if (filter != null && !filter.Include(baseProperty)) continue; if (SignaturesParametersAreEqual(property, baseProperty)) return baseProperty; } } return Dummy.Property; }
public static IEventDefinition GetHiddenBaseEvent(this IEventDefinition evnt, ICciFilter filter = null) { IMethodDefinition eventRep = evnt.Adder.ResolvedMethod; if (eventRep.IsVirtual && !eventRep.IsNewSlot) return Dummy.Event; // an override foreach (ITypeReference baseClassRef in evnt.ContainingTypeDefinition.GetAllBaseTypes()) { ITypeDefinition baseClass = baseClassRef.ResolvedType; foreach (IEventDefinition baseEvent in baseClass.GetMembersNamed(evnt.Name, false).OfType<IEventDefinition>()) { if (baseEvent.Visibility == TypeMemberVisibility.Private) continue; if (IsAssembly(baseEvent) && !InSameUnit(baseEvent, evnt)) continue; if (filter != null && !filter.Include(baseEvent)) continue; return baseEvent; } } return Dummy.Event; }
public static IFieldDefinition GetHiddenBaseField(this IFieldDefinition field, ICciFilter filter = null) { foreach (ITypeReference baseClassRef in field.ContainingTypeDefinition.GetAllBaseTypes()) { ITypeDefinition baseClass = baseClassRef.ResolvedType; foreach (IFieldDefinition baseField in baseClass.GetMembersNamed(field.Name, false).OfType<IFieldDefinition>()) { if (baseField.Visibility == TypeMemberVisibility.Private) continue; if (IsAssembly(baseField) && !InSameUnit(baseField, field)) continue; if (filter != null && !filter.Include(baseField)) continue; return baseField; } } return Dummy.Field; }