public void CodeModelToCodeDomTypeAttributesTest_InternalSealed() { System.Reflection.TypeAttributes expected = System.Reflection.TypeAttributes.NestedAssembly | System.Reflection.TypeAttributes.Sealed; System.Reflection.TypeAttributes actual = CodeModelToCodeDomTypeAttributesImpl(EnvDTE.vsCMAccess.vsCMAccessProject, EnvDTE80.vsCMInheritanceKind.vsCMInheritanceKindSealed); Assert.AreEqual(expected, actual); }
public void CodeModelToCodeDomTypeAttributesTest_Public() { System.Reflection.TypeAttributes expected = System.Reflection.TypeAttributes.Public; System.Reflection.TypeAttributes actual = CodeModelToCodeDomTypeAttributesImpl(EnvDTE.vsCMAccess.vsCMAccessPublic, 0); Assert.AreEqual(expected, actual); }
public void CodeModelToCodeDomTypeAttributesTest_Internal() { System.Reflection.TypeAttributes expected = System.Reflection.TypeAttributes.NestedAssembly; System.Reflection.TypeAttributes actual = CodeModelToCodeDomTypeAttributesImpl(EnvDTE.vsCMAccess.vsCMAccessProject, 0); Assert.AreEqual(expected, actual); }
public TypeBuilder DefineNestedType(string name, System.Reflection.TypeAttributes attr, Type parent) { Contract.Ensures(0 <= name.Length); Contract.Ensures(Contract.Result <System.Reflection.Emit.TypeBuilder>() != null); Contract.Ensures(name.Length <= 1023); return(default(TypeBuilder)); }
// https://stackoverflow.com/questions/1175888/determine-if-a-type-is-static // static classes are declared abstract and sealed at the IL level. // type.IsAbstract && type.IsSealed // However, abstract classes are not the only types you can't instantiate directly. // You should check for things like interfaces (without the CoClass attribute) // and types that don't have a constructor accessible by the calling code. public static void isstatic() { System.Type t = typeof(System.GC); System.Console.WriteLine(t.Attributes); System.Reflection.TypeAttributes attribForStaticClass = System.Reflection.TypeAttributes.AutoLayout | System.Reflection.TypeAttributes.AnsiClass | System.Reflection.TypeAttributes.Class | System.Reflection.TypeAttributes.Public | System.Reflection.TypeAttributes.Abstract | System.Reflection.TypeAttributes.Sealed | System.Reflection.TypeAttributes.BeforeFieldInit; System.Console.WriteLine((t.Attributes == attribForStaticClass)); }
/// <summary> /// Assigns the generic blueprint and the type arguments to the generic instance type. /// </summary> /// <param name="conversion"></param> /// <param name="converted"></param> /// <param name="convertedDeclaringType"></param> /// <returns></returns> public void Build(ILConversion conversion, ConvertedTypeDefinition_I converted, ConvertedTypeDefinition_I convertedDeclaringType) { //Done on purpose to find errors var typeDefinition = (TypeDefinition)converted.SourceTypeReference; System.Reflection.TypeAttributes attributes = Cecil.Metadata.Members.Types.GetTypeAttributes(typeDefinition); if (converted is ConvertedTypeDefinitionWithDeclaringType_I withDeclaringType) { var packingSize = Cecil.GetPackingSize(typeDefinition); if (convertedDeclaringType == null) // Can occur if passing in a single nested type or if a nested class gets processed before its parents gets // processed. { if (!(converted.SourceTypeReference is TypeDefinition)) { throw new Exception("Expected a type definition"); } var semanticDeclaringType = Execution.Types.Ensuring.Ensure(conversion, converted.SourceTypeReference.DeclaringType, null, null); if (!(semanticDeclaringType is ConvertedTypeDefinition_I producedDeclaringType)) { throw new Exception($"Expected the declaring type of a nested class to be castable to {typeof(ConvertedTypeDefinition_I)}"); } convertedDeclaringType = producedDeclaringType; } withDeclaringType.DeclaringType = convertedDeclaringType; // The plus sign and the parent class name before it needs to be dropped from the full name prior to calling define nested class // as the type builder will automatically add them back on based upon the name of the declaring type. var fullName = Types.Naming.GetTypeBuilderNestedClassFullName(converted.FullName); converted.TypeBuilder = convertedDeclaringType.TypeBuilder.DefineNestedType(fullName, attributes, null, packingSize); } else { if (converted.FullName == "<Module>") { var x = converted.Module.ModuleBuilder.GetType("<Module>", true); } converted.TypeBuilder = converted.Module.ModuleBuilder.DefineType(converted.FullName, attributes); } converted.UnderlyingType = converted.TypeBuilder; this.Unified.Types.ExtendWithCrossReference(conversion.RuntimicSystem, converted, converted.UnderlyingType.AssemblyQualifiedName); Types.Building.UpdateBuildPhase(converted, BuildPhaseKind.TypeDefined); }
private System.Reflection.TypeAttributes CodeModelToCodeDomTypeAttributesImpl(EnvDTE.vsCMAccess access, EnvDTE80.vsCMInheritanceKind inheritanceKind) { SequenceMock <EnvDTE80.CodeClass2> cc2Mock = new SequenceMock <EnvDTE80.CodeClass2>(); cc2Mock.AddExpectation("get_Access", access); cc2Mock.AddExpectation("get_InheritanceKind", inheritanceKind); System.Reflection.TypeAttributes result = ProjectUtils.CodeModelToCodeDomTypeAttributes(cc2Mock.Instance); cc2Mock.Verify(); return(result); }
protected override System.Reflection.TypeAttributes GetAttributeFlagsImpl() { System.Reflection.TypeAttributes result = 0; if (this.Type.IsClass) { result |= System.Reflection.TypeAttributes.Class; } if (this.Type.IsInterface) { result |= System.Reflection.TypeAttributes.Interface; } if (this.Type.IsAbstract) { result |= System.Reflection.TypeAttributes.Abstract; } if (this.Type.IsSealed) { result |= System.Reflection.TypeAttributes.Sealed; } return(result); }
public System.Reflection.Emit.TypeBuilder DefineNestedType(string name, System.Reflection.TypeAttributes attr, System.Type parent, System.Reflection.Emit.PackingSize packSize, int typeSize) { return(default(System.Reflection.Emit.TypeBuilder)); }
public System.Reflection.Emit.TypeBuilder DefineNestedType(string name, System.Reflection.TypeAttributes attr) { return(default(System.Reflection.Emit.TypeBuilder)); }
public System.Reflection.Emit.TypeBuilder DefineType(string name, System.Reflection.TypeAttributes attr, System.Type parent, int typesize) { return(default(System.Reflection.Emit.TypeBuilder)); }
public TypeBuilder DefineType(string name, System.Reflection.TypeAttributes attr, Type parent, Type[] interfaces) { }
public System.Reflection.Emit.TypeBuilder DefineNestedType(string name, System.Reflection.TypeAttributes attr) { throw null; }
public System.Reflection.Emit.EnumBuilder DefineEnum(string name, System.Reflection.TypeAttributes visibility, System.Type underlyingType) { throw null; }
static CodeTypeDeclaration CreateTypeDeclaration(TypeDefinition publicType) { if (IsDelegate(publicType)) { return(CreateDelegateDeclaration(publicType)); } bool @static = false; TypeAttributes attributes = 0; if (publicType.IsPublic || publicType.IsNestedPublic) { attributes |= TypeAttributes.Public; } if (publicType.IsNestedFamily) { attributes |= TypeAttributes.NestedFamily; } if (publicType.IsSealed && !publicType.IsAbstract) { attributes |= TypeAttributes.Sealed; } else if (!publicType.IsSealed && publicType.IsAbstract && !publicType.IsInterface) { attributes |= TypeAttributes.Abstract; } else if (publicType.IsSealed && publicType.IsAbstract) { @static = true; } // Static support is a hack. CodeDOM does support it, and this isn't // correct C#, but it's good enough for our API outline var name = publicType.Name; var index = name.IndexOf('`'); if (index != -1) { name = name.Substring(0, index); } var declaration = new CodeTypeDeclaration(@static ? "static " + name : name) { CustomAttributes = CreateCustomAttributes(publicType), // TypeAttributes must be specified before the IsXXX as they manipulate TypeAttributes! TypeAttributes = attributes, IsClass = publicType.IsClass, IsEnum = publicType.IsEnum, IsInterface = publicType.IsInterface, IsStruct = publicType.IsValueType && !publicType.IsPrimitive && !publicType.IsEnum, }; if (declaration.IsInterface && publicType.BaseType != null) { throw new NotImplementedException("Base types for interfaces needs testing"); } PopulateGenericParameters(publicType, declaration.TypeParameters); if (publicType.BaseType != null && ShouldOutputBaseType(publicType)) { if (publicType.BaseType.FullName == "System.Enum") { var underlyingType = publicType.GetEnumUnderlyingType(); if (underlyingType.FullName != "System.Int32") { declaration.BaseTypes.Add(CreateCodeTypeReference(underlyingType)); } } else { declaration.BaseTypes.Add(CreateCodeTypeReference(publicType.BaseType)); } } foreach (var @interface in publicType.Interfaces.OrderBy(i => i.FullName)) { declaration.BaseTypes.Add(CreateCodeTypeReference(@interface)); } foreach (var memberInfo in publicType.GetMembers().Where(ShouldIncludeMember).OrderBy(m => m.Name)) { AddMemberToTypeDeclaration(declaration, memberInfo); } // Fields should be in defined order for an enum var fields = !publicType.IsEnum ? publicType.Fields.OrderBy(f => f.Name) : (IEnumerable <FieldDefinition>)publicType.Fields; foreach (var field in fields) { AddMemberToTypeDeclaration(declaration, field); } foreach (var nestedType in publicType.NestedTypes.Where(ShouldIncludeType).OrderBy(t => t.FullName)) { var nestedTypeDeclaration = CreateTypeDeclaration(nestedType); declaration.Members.Add(nestedTypeDeclaration); } return(declaration); }
public System.Reflection.Emit.TypeBuilder DefineNestedType(string name, System.Reflection.TypeAttributes attr, System.Type parent, System.Type[] interfaces) { throw new PlatformNotSupportedException(); }
public System.Reflection.Emit.TypeBuilder DefineNestedType(string name, System.Reflection.TypeAttributes attr, System.Type parent, System.Reflection.Emit.PackingSize packSize, int typeSize) { throw new PlatformNotSupportedException(); }
public TypeBuilder DefineNestedType(string name, System.Reflection.TypeAttributes attr, Type parent) { return(default(TypeBuilder)); }
public EnumBuilder DefineEnum(string name, System.Reflection.TypeAttributes visibility, Type underlyingType) { }
public TypeBuilder DefineType(string name, System.Reflection.TypeAttributes attr, Type parent, PackingSize packsize) { }
public System.Reflection.Emit.TypeBuilder DefineNestedType(string name, System.Reflection.TypeAttributes attr, System.Type parent, System.Type[] interfaces) { return(default(System.Reflection.Emit.TypeBuilder)); }
public IList <TypeInfo> GetTypesWithAttributeInModule(Type customAttribute, bool includePrivate) { if (IsDisposed) { throw new ObjectDisposedException(null); } if (customAttribute == null) { throw new ArgumentNullException("customAttribute"); } System.Diagnostics.Contracts.Contract.EndContractBlock(); _peFile.InitMetaData(); MDTables MetaData = _peFile.MetaData; List <TypeInfo> types = new List <TypeInfo>(); String attributeName = customAttribute.Name; String attributeNameSpace = customAttribute.Namespace; IList <MetadataToken> genericTypeTokens = GetGenericTypes(); uint numRows = MetaData.RowsInTable(MDTables.Tables.CustomAttribute); for (uint i = 0; i < numRows; i++) { MetaData.SeekToRowOfTable(MDTables.Tables.CustomAttribute, i); // Format: Parent type token, CA type token, value (index into blob heap) MetadataToken targetType = MetaData.ReadMetadataToken(MDTables.Encodings.HasCustomAttribute); MetadataToken caType = MetaData.ReadMetadataToken(MDTables.Encodings.CustomAttributeType); //UInt32 value = MetaData.ReadBlobIndex(); //Console.WriteLine("CA - Applied to: {0} CA .ctor: {1} Value: {2}", targetType, caType, value); //Console.WriteLine("CA MD Tokens Parent: {0} Type: {1}", targetType.ToMDToken(), caType.ToMDToken()); // Ensure the custom attribute type is the type we expect MetaData.SeekToMDToken(caType); String caTypeName = null, caNameSpace = null; if (caType.Table != MDTables.Tables.MemberRef) { // Custom attribute was defined in the assembly we are currently inspecting? // Ignore it. System.Diagnostics.Contracts.Contract.Assert(caType.Table == MDTables.Tables.MethodDef); continue; } MetadataToken customAttributeType = MetaData.ReadMetadataToken(MDTables.Encodings.MemberRefParent); //Console.WriteLine(" MemberRef: {0} Type of MemberRef: {1}", caType.ToMDToken(), customAttributeType.ToMDToken()); MetaData.SeekToMDToken(customAttributeType); MetadataToken resolutionScope = MetaData.ReadMetadataToken(MDTables.Encodings.ResolutionScope); // @ caTypeName = MetaData.ReadString(); if (!String.Equals(caTypeName, attributeName)) { continue; } caNameSpace = MetaData.ReadString(); if (!String.Equals(caNameSpace, attributeNameSpace)) { continue; } // Get type name & namespace. switch (targetType.Table) { case MDTables.Tables.TypeDef: MetaData.SeekToMDToken(targetType); System.Reflection.TypeAttributes flags = (System.Reflection.TypeAttributes)_peFile.B.ReadUInt32(); System.Reflection.TypeAttributes vis = flags & System.Reflection.TypeAttributes.VisibilityMask; bool isPublic = vis == System.Reflection.TypeAttributes.Public; // NestedPublic not supported if (!includePrivate && !isPublic) { continue; } String typeName = MetaData.ReadString(); String nameSpace = MetaData.ReadString(); bool isGeneric = genericTypeTokens.Contains(targetType); TypeInfo type = new TypeInfo(targetType, _assembly, this, typeName, nameSpace, isGeneric); types.Add(type); break; default: throw new NotImplementedException(String.Format(CultureInfo.CurrentCulture, Res.UnknownTokenType, targetType.Table, Assembly.FullName)); } } return(types); }
public System.Reflection.Emit.TypeBuilder DefineNestedType(string name, System.Reflection.TypeAttributes attr, System.Type parent, System.Type[] interfaces) { throw null; }
public TypeBuilder DefineType(string name, System.Reflection.TypeAttributes attr) { return(default(TypeBuilder)); }
public TypeBuilder DefineType(string name, System.Reflection.TypeAttributes attr) { }
public System.Reflection.Emit.TypeBuilder DefineType(string name, System.Reflection.TypeAttributes attr, System.Type parent, int typesize) { throw null; }
public System.Reflection.Emit.EnumBuilder DefineEnum(string name, System.Reflection.TypeAttributes visibility, System.Type underlyingType) { return(default(System.Reflection.Emit.EnumBuilder)); }
public System.Reflection.Emit.TypeBuilder DefineNestedType(string name, System.Reflection.TypeAttributes attr, System.Type parent, System.Reflection.Emit.PackingSize packSize, int typeSize) { throw null; }
public TypeBuilder DefineType(string name, System.Reflection.TypeAttributes attr, Type parent, int typesize) { }
private static TypeAttributes GetTypeAttributes(TypeDefinition typeDefinition) { TypeAttributes typeAttributes = 0; if (typeDefinition.IsAbstract) { typeAttributes |= TypeAttributes.Abstract; } if (typeDefinition.IsAnsiClass) { typeAttributes |= TypeAttributes.AnsiClass; } if (typeDefinition.IsAutoClass) { typeAttributes |= TypeAttributes.AutoClass; } if (typeDefinition.IsAutoLayout) { typeAttributes |= TypeAttributes.AutoLayout; } if (typeDefinition.IsClass) { typeAttributes |= TypeAttributes.Class; } if (typeDefinition.IsExplicitLayout) { typeAttributes |= TypeAttributes.ExplicitLayout; } if (typeDefinition.IsImport) { typeAttributes |= TypeAttributes.Import; } if (typeDefinition.IsInterface) { typeAttributes |= TypeAttributes.Interface; } if (typeDefinition.IsNestedAssembly) { typeAttributes |= TypeAttributes.NestedAssembly; } if (typeDefinition.IsNestedFamily) { typeAttributes |= TypeAttributes.NestedFamily; } if (typeDefinition.IsNestedPrivate) { typeAttributes |= TypeAttributes.NestedPrivate; } if (typeDefinition.IsNestedPublic) { typeAttributes |= TypeAttributes.NestedPublic; } if (typeDefinition.IsNotPublic) { typeAttributes |= TypeAttributes.NotPublic; } if (typeDefinition.IsPublic) { typeAttributes |= TypeAttributes.Public; } if (typeDefinition.IsSealed) { typeAttributes |= TypeAttributes.Sealed; } if (typeDefinition.IsSerializable) { typeAttributes |= TypeAttributes.Serializable; } if (typeDefinition.IsSpecialName) { typeAttributes |= TypeAttributes.SpecialName; } if (typeDefinition.IsUnicodeClass) { typeAttributes |= TypeAttributes.UnicodeClass; } return(typeAttributes); }
/// <summary> /// Fills the row from the array of bytes. /// </summary> unsafe public void FromRawData(byte [] buff, int offs) { if (buff == null) throw new Exception("buff == null"); if (offs + Size > buff.Length) throw new Exception("bounds"); this.Flags = (System.Reflection.TypeAttributes) LEBitConverter.ToUInt32(buff, offs); offs += sizeof (uint); this.TypeDefId = LEBitConverter.ToInt32(buff, offs); offs += 4; this.TypeName = LEBitConverter.ToInt32(buff, offs); offs += 4; this.TypeNamespace = LEBitConverter.ToInt32(buff, offs); offs += 4; this.Implementation = TabsDecoder.DecodeToken(CodedTokenId.Implementation, LEBitConverter.ToInt32(buff, offs)); }