private void CreateField(TypeInfo type, TypeAttr attr, VarDesc var, ref bool isConversionLoss) { TypeDesc fieldTypeDesc = var.elemdescVar.tdesc; TypeConverter typeConverter = new TypeConverter(m_info, type, fieldTypeDesc, ConversionType.Field); Type fieldType = typeConverter.ConvertedType; string fieldName = type.GetDocumentation(var.memid); FieldBuilder field = m_typeBuilder.DefineField(fieldName, fieldType, FieldAttributes.Public); typeConverter.ApplyAttributes(field); isConversionLoss |= typeConverter.IsConversionLoss; // // Emit ComConversionLossAttribute for fields if necessary // if (typeConverter.IsConversionLoss) { field.SetCustomAttribute(CustomAttributeHelper.GetBuilderForComConversionLoss()); // // Emit Wrn_UnconvertableField warning // m_info.ReportEvent( WarningCode.Wrn_UnconvertableField, Resource.FormatString("Wrn_UnconvertableField", type.GetDocumentation(), fieldName)); } // // Emit TypeLibVarAttribute if necessary // if (var.wVarFlags != 0) { field.SetCustomAttribute(CustomAttributeHelper.GetBuilderForTypeLibVar((TypeLibVarFlags)var.wVarFlags)); } }
public override void OnCreate() { string name = ManagedName; if (m_type != null) { return; } TypeInfo typeInfo = RefNonAliasedTypeInfo; using (TypeAttr typeAttr = typeInfo.GetTypeAttr()) { // // Create fields // int cVars = typeAttr.cVars; bool isConversionLoss = false; for (int n = 0; n < cVars; ++n) { using (VarDesc var = typeInfo.GetVarDesc(n)) { CreateField(typeInfo, typeAttr, var, ref isConversionLoss); } } // // Emit StructLayout(LayoutKind.Sequential, Pack=cbAlignment) // m_typeBuilder.SetCustomAttribute(CustomAttributeHelper.GetBuilderForStructLayout(LayoutKind.Explicit, typeAttr.cbAlignment, typeAttr.cbSizeInstance)); // // Emit ComConversionLossAttribute if necessary // if (isConversionLoss) { m_typeBuilder.SetCustomAttribute(CustomAttributeHelper.GetBuilderForComConversionLoss()); } // // Emit SerializableAttribute for /transform:serializablevalueclasses // if ((m_info.Settings.m_flags & TypeLibImporterFlags.SerializableValueClasses) != 0) { m_typeBuilder.SetCustomAttribute(CustomAttributeHelper.GetBuilderForSerializable()); } m_type = m_typeBuilder.CreateType(); } }
/// <summary> /// Test whether the specified VT_RECORD contains any field that can be converted to a managed reference type /// </summary> private bool HasObjectFields(TypeInfo typeInfo) { TypeAttr typeAttr = typeInfo.GetTypeAttr(); for (int i = 0; i < typeAttr.cVars; ++i) { VarDesc var = typeInfo.GetVarDesc(i); if (IsObjectType(typeInfo, var.elemdescVar.tdesc)) { return(true); } } return(false); }
private void CreateField(TypeInfo type, TypeAttr attr, VarDesc var, ref bool isConversionLoss) { if (IsObjectType(type, var.elemdescVar.tdesc)) { isConversionLoss = true; } else { TypeConverter typeConverter = new TypeConverter(m_info, type, var.elemdescVar.tdesc, ConversionType.Field); Type fieldType = typeConverter.ConvertedType; // TlbImp2 will only skip reference types, instead of skipping every field // Also, TlbImp1 will skip ValueType *, which doesn't make any sense. TlbImp2 will keep ValueType * as IntPtr string fieldName = type.GetDocumentation(var.memid); // Generates the [FieldOffset(0)] layout declarations that approximate unions in managed code FieldBuilder field = m_typeBuilder.DefineField(fieldName, fieldType, FieldAttributes.Public); field.SetCustomAttribute(CustomAttributeHelper.GetBuilderForFieldOffset(0)); typeConverter.ApplyAttributes(field); isConversionLoss |= typeConverter.IsConversionLoss; // // Emit ComConversionLossAttribute for fields if necessary // if (typeConverter.IsConversionLoss) { field.SetCustomAttribute(CustomAttributeHelper.GetBuilderForComConversionLoss()); // // Emit Wrn_UnconvertableField warning // m_info.ReportEvent( WarningCode.Wrn_UnconvertableField, Resource.FormatString("Wrn_UnconvertableField", type.GetDocumentation(), fieldName)); } } }
public ElemDesc(VarDesc varDesc, ELEMDESC elemdesc) { m_parent = varDesc; Init(elemdesc); }