public UnresolvedSecurityDeclarationBlob(int securityAction, byte[] blob) { BlobReader reader = new BlobReader(blob, null); this.securityAction = new SimpleConstantValue(securityActionTypeReference, securityAction); this.blob = blob; if (reader.ReadByte() == '.') { // binary attribute uint attributeCount = reader.ReadCompressedUInt32(); for (uint i = 0; i < attributeCount; i++) { unresolvedAttributes.Add(new UnresolvedSecurityAttribute(this, (int)i)); } } else { // for backward compatibility with .NET 1.0: XML-encoded attribute var attr = new DefaultUnresolvedAttribute(permissionSetAttributeTypeReference); attr.ConstructorParameterTypes.Add(securityActionTypeReference); attr.PositionalArguments.Add(this.securityAction); string xml = System.Text.Encoding.Unicode.GetString(blob); attr.AddNamedPropertyArgument("XML", new SimpleConstantValue(KnownTypeReference.String, xml)); unresolvedAttributes.Add(attr); } }
public DefaultResolvedAttribute(DefaultUnresolvedAttribute unresolved, ITypeResolveContext context) { this.unresolved = unresolved; this.context = context; this.attributeType = unresolved.AttributeType.Resolve(context); this.positionalArguments = unresolved.PositionalArguments.Resolve(context); }
bool ISupportsInterning.EqualsForInterning(ISupportsInterning other) { DefaultUnresolvedAttribute o = other as DefaultUnresolvedAttribute; return(o != null && attributeType == o.attributeType && constructorParameterTypes == o.constructorParameterTypes && positionalArguments == o.positionalArguments && ListEquals(namedArguments ?? EmptyList <KeyValuePair <IMemberReference, IConstantValue> > .Instance, o.namedArguments ?? EmptyList <KeyValuePair <IMemberReference, IConstantValue> > .Instance)); }
/// <summary> /// Adds a type forwarder. /// This adds both an assembly attribute and an internal forwarder entry, which will be used /// by the resolved assembly to provide the forwarded types. /// </summary> /// <param name="typeName">The name of the type.</param> /// <param name="referencedType">The reference used to look up the type in the target assembly.</param> public void AddTypeForwarder(TopLevelTypeName typeName, ITypeReference referencedType) { if (referencedType == null) { throw new ArgumentNullException("referencedType"); } FreezableHelper.ThrowIfFrozen(this); var attribute = new DefaultUnresolvedAttribute(typeForwardedToAttributeTypeRef, new[] { KnownTypeReference.Type }); attribute.PositionalArguments.Add(new TypeOfConstantValue(referencedType)); assemblyAttributes.Add(attribute); typeForwarders[typeName] = referencedType; }
public UnresolvedSecurityDeclarationBlob(int securityAction, byte[] blob) { BlobReader reader = new BlobReader(blob, null); this.securityAction = new SimpleConstantValue(securityActionTypeReference, securityAction); this.blob = blob; if (reader.ReadByte() == '.') { // binary attribute uint attributeCount = reader.ReadCompressedUInt32(); for (uint i = 0; i < attributeCount; i++) { unresolvedAttributes.Add(new UnresolvedSecurityAttribute(this, (int)i)); } } else { // for backward compatibility with .NET 1.0: XML-encoded attribute var attr = new DefaultUnresolvedAttribute(permissionSetAttributeTypeReference); attr.ConstructorParameterTypes.Add(securityActionTypeReference); attr.PositionalArguments.Add(this.securityAction); string xml = System.Text.Encoding.Unicode.GetString(blob); attr.AddNamedPropertyArgument("XML", new SimpleConstantValue(KnownTypeReference.String, xml)); unresolvedAttributes.Add(attr); } }
/// <summary> /// Adds a type forwarder. /// This adds both an assembly attribute and an internal forwarder entry, which will be used /// by the resolved assembly to provide the forwarded types. /// </summary> /// <param name="typeName">The name of the type.</param> /// <param name="referencedType">The reference used to look up the type in the target assembly.</param> public void AddTypeForwarder(FullNameAndTypeParameterCount typeName, ITypeReference referencedType) { if (referencedType == null) throw new ArgumentNullException("referencedType"); FreezableHelper.ThrowIfFrozen(this); var attribute = new DefaultUnresolvedAttribute(typeForwardedToAttributeTypeRef, new[] { KnownTypeReference.Type }); attribute.PositionalArguments.Add(new TypeOfConstantValue(referencedType)); assemblyAttributes.Add(attribute); typeForwarders[typeName] = referencedType; }
public DefaultResolvedAttribute(DefaultUnresolvedAttribute unresolved, ITypeResolveContext context) { this.unresolved = unresolved; this.context = context; this.attributeType = unresolved.AttributeType.Resolve(context); this.positionalArguments = unresolved.PositionalArguments.Resolve(context); }
IUnresolvedAttribute ConvertMarshalInfo(FieldMarshal marshalInfo) { DefaultUnresolvedAttribute attr = new DefaultUnresolvedAttribute(marshalAsAttributeTypeRef, new[] { unmanagedTypeTypeRef }); attr.PositionalArguments.Add(CreateSimpleConstantValue(unmanagedTypeTypeRef, (int)marshalInfo.UnmanagedType)); if (marshalInfo.UnmanagedType ==UnmanagedType.ByValArray) { attr.AddNamedFieldArgument("SizeConst", CreateSimpleConstantValue(KnownTypeReference.Int32, (int)marshalInfo.SizeConst)); if (marshalInfo.ArraySubType.HasValue) attr.AddNamedFieldArgument("ArraySubType", CreateSimpleConstantValue(unmanagedTypeTypeRef, (int)marshalInfo.ArraySubType.Value)); } if (marshalInfo.UnmanagedType ==UnmanagedType.SafeArray) { attr.AddNamedFieldArgument("SafeArraySubType", CreateSimpleConstantValue(typeof(VarEnum).ToTypeReference(), (int)marshalInfo.SafeArraySubType)); } if (marshalInfo.UnmanagedType == UnmanagedType.LPArray) { if (marshalInfo.ArraySubType != null) attr.AddNamedFieldArgument("ArraySubType", CreateSimpleConstantValue(unmanagedTypeTypeRef, (int)marshalInfo.ArraySubType)); if (marshalInfo.SizeConst >= 0) attr.AddNamedFieldArgument("SizeConst", CreateSimpleConstantValue(KnownTypeReference.Int32, (int)marshalInfo.SizeConst)); if (marshalInfo.SizeParamIndex >= 0) attr.AddNamedFieldArgument("SizeParamIndex", CreateSimpleConstantValue(KnownTypeReference.Int16, (short)marshalInfo.SizeParamIndex)); } if (marshalInfo.UnmanagedType == UnmanagedType.CustomMarshaler) { attr.AddNamedFieldArgument("MarshalType", CreateSimpleConstantValue(KnownTypeReference.String, marshalInfo.MarshalTypeRef.FullName)); if (!string.IsNullOrEmpty(marshalInfo.MarshalCookie)) attr.AddNamedFieldArgument("MarshalCookie", CreateSimpleConstantValue(KnownTypeReference.String, marshalInfo.MarshalCookie)); } if (marshalInfo.UnmanagedType == UnmanagedType.ByValTStr) { attr.AddNamedFieldArgument("SizeConst", CreateSimpleConstantValue(KnownTypeReference.Int32, (int)marshalInfo.SizeConst)); } return InterningProvider.Intern(attr); }
void AddAttributes(FieldInfo fieldDefinition, IUnresolvedEntity targetEntity) { // FieldOffsetAttribute int fOffset; if (fieldDefinition.__TryGetFieldOffset(out fOffset)) { var fieldOffset = new DefaultUnresolvedAttribute(fieldOffsetAttributeTypeRef, new[] { KnownTypeReference.Int32 }); fieldOffset.PositionalArguments.Add(CreateSimpleConstantValue(KnownTypeReference.Int32, fOffset)); targetEntity.Attributes.Add(interningProvider.Intern(fieldOffset)); } // NonSerializedAttribute if (fieldDefinition.IsNotSerialized) { targetEntity.Attributes.Add(nonSerializedAttribute); } FieldMarshal marshal; if (fieldDefinition.__TryGetFieldMarshal (out marshal)) targetEntity.Attributes.Add(ConvertMarshalInfo(marshal)); AddCustomAttributes(fieldDefinition.CustomAttributes, targetEntity.Attributes); }
void AddAttributes(IKVM.Reflection.Type typeDefinition, IUnresolvedTypeDefinition targetEntity) { // SerializableAttribute if (typeDefinition.IsSerializable) targetEntity.Attributes.Add(serializableAttribute); // ComImportAttribute if (typeDefinition.IsImport) targetEntity.Attributes.Add(comImportAttribute); #region StructLayoutAttribute LayoutKind layoutKind = LayoutKind.Auto; switch (typeDefinition.Attributes & TypeAttributes.LayoutMask) { case TypeAttributes.SequentialLayout: layoutKind = LayoutKind.Sequential; break; case TypeAttributes.ExplicitLayout: layoutKind = LayoutKind.Explicit; break; } CharSet charSet = CharSet.None; switch (typeDefinition.Attributes & TypeAttributes.StringFormatMask) { case TypeAttributes.AnsiClass: charSet = CharSet.Ansi; break; case TypeAttributes.AutoClass: charSet = CharSet.Auto; break; case TypeAttributes.UnicodeClass: charSet = CharSet.Unicode; break; } int packingSize; int typeSize; if (typeDefinition.__GetLayout (out packingSize, out typeSize)) { LayoutKind defaultLayoutKind = (typeDefinition.IsValueType && !typeDefinition.IsEnum) ? LayoutKind.Sequential: LayoutKind.Auto; if (layoutKind != defaultLayoutKind || charSet != CharSet.Ansi || packingSize > 0 || typeSize > 0) { var structLayout = new DefaultUnresolvedAttribute(structLayoutAttributeTypeRef, new[] { layoutKindTypeRef }); structLayout.PositionalArguments.Add(CreateSimpleConstantValue(layoutKindTypeRef, (int)layoutKind)); if (charSet != CharSet.Ansi) { structLayout.AddNamedFieldArgument("CharSet", CreateSimpleConstantValue(charSetTypeRef, (int)charSet)); } if (packingSize > 0) { structLayout.AddNamedFieldArgument("Pack", CreateSimpleConstantValue(KnownTypeReference.Int32, packingSize)); } if (typeSize > 0) { structLayout.AddNamedFieldArgument("Size", CreateSimpleConstantValue(KnownTypeReference.Int32, typeSize)); } targetEntity.Attributes.Add(interningProvider.Intern(structLayout)); } } #endregion AddCustomAttributes(typeDefinition.CustomAttributes, targetEntity.Attributes); if (typeDefinition.Attributes.HasFlag (TypeAttributes.HasSecurity)) { AddSecurityAttributes(CustomAttributeData.__GetDeclarativeSecurity(typeDefinition), targetEntity.Attributes); } }
void AddAttributes(ConstructorInfo methodDefinition, IList<IUnresolvedAttribute> attributes, IList<IUnresolvedAttribute> returnTypeAttributes) { var implAttributes = methodDefinition.MethodImplementationFlags; #region PreserveSigAttribute if (implAttributes == MethodImplAttributes.PreserveSig) { attributes.Add(preserveSigAttribute); implAttributes = 0; } #endregion #region MethodImplAttribute if (implAttributes != MethodImplAttributes.IL) { var methodImpl = new DefaultUnresolvedAttribute(methodImplAttributeTypeRef, new[] { methodImplOptionsTypeRef }); methodImpl.PositionalArguments.Add(CreateSimpleConstantValue(methodImplOptionsTypeRef, (int)implAttributes)); attributes.Add(interningProvider.Intern(methodImpl)); } #endregion AddCustomAttributes(methodDefinition.CustomAttributes, attributes); if (methodDefinition.Attributes.HasFlag (MethodAttributes.HasSecurity)) { AddSecurityAttributes(CustomAttributeData.__GetDeclarativeSecurity (methodDefinition), attributes); } }
void AddAttributes(MethodInfo methodDefinition, IList<IUnresolvedAttribute> attributes, ICollection<IUnresolvedAttribute> returnTypeAttributes) { var implAttributes = methodDefinition.MethodImplementationFlags; #region DllImportAttribute if (methodDefinition.Attributes.HasFlag (MethodAttributes.PinvokeImpl)) { ImplMapFlags flags; string importName; string importScope; if (methodDefinition.__TryGetImplMap(out flags, out importName, out importScope)) { var dllImport = new DefaultUnresolvedAttribute(dllImportAttributeTypeRef, new[] { KnownTypeReference.String }); dllImport.PositionalArguments.Add(CreateSimpleConstantValue(KnownTypeReference.String, importScope)); if (flags.HasFlag (ImplMapFlags.BestFitOff)) dllImport.AddNamedFieldArgument("BestFitMapping", falseValue); if (flags.HasFlag (ImplMapFlags.BestFitOn)) dllImport.AddNamedFieldArgument("BestFitMapping", trueValue); CallingConvention callingConvention; switch (flags & ImplMapFlags.CallConvMask) { case (ImplMapFlags)0: Debug.WriteLine ("P/Invoke calling convention not set on:" + methodDefinition.Name); callingConvention = CallingConvention.StdCall; break; case ImplMapFlags.CallConvCdecl: callingConvention = CallingConvention.Cdecl; break; case ImplMapFlags.CallConvFastcall: callingConvention = CallingConvention.FastCall; break; case ImplMapFlags.CallConvStdcall: callingConvention = CallingConvention.StdCall; break; case ImplMapFlags.CallConvThiscall: callingConvention = CallingConvention.ThisCall; break; case ImplMapFlags.CallConvWinapi: callingConvention = CallingConvention.Winapi; break; default: throw new NotSupportedException("unknown calling convention"); } if (!flags.HasFlag (ImplMapFlags.CallConvWinapi)) dllImport.AddNamedFieldArgument("CallingConvention", CreateSimpleConstantValue(callingConventionTypeRef, (int)callingConvention)); CharSet charSet = CharSet.None; switch (flags & ImplMapFlags.CharSetMask) { case ImplMapFlags.CharSetAnsi: charSet = CharSet.Ansi; break; case ImplMapFlags.CharSetAuto: charSet = CharSet.Auto; break; case ImplMapFlags.CharSetUnicode: charSet = CharSet.Unicode; break; } if (charSet != CharSet.None) dllImport.AddNamedFieldArgument("CharSet", CreateSimpleConstantValue(charSetTypeRef, (int)charSet)); if (!string.IsNullOrEmpty(importName) && importName != methodDefinition.Name) dllImport.AddNamedFieldArgument("EntryPoint", CreateSimpleConstantValue(KnownTypeReference.String, importName)); if (flags.HasFlag (ImplMapFlags.NoMangle)) dllImport.AddNamedFieldArgument("ExactSpelling", trueValue); if ((implAttributes & MethodImplAttributes.PreserveSig) == MethodImplAttributes.PreserveSig) implAttributes &= ~MethodImplAttributes.PreserveSig; else dllImport.AddNamedFieldArgument("PreserveSig", falseValue); if (flags.HasFlag (ImplMapFlags.SupportsLastError)) dllImport.AddNamedFieldArgument("SetLastError", trueValue); if (flags.HasFlag (ImplMapFlags.CharMapErrorOff)) dllImport.AddNamedFieldArgument("ThrowOnUnmappableChar", falseValue); if (flags.HasFlag (ImplMapFlags.CharMapErrorOn)) dllImport.AddNamedFieldArgument("ThrowOnUnmappableChar", trueValue); attributes.Add(interningProvider.Intern(dllImport)); } } #endregion #region PreserveSigAttribute if (implAttributes == MethodImplAttributes.PreserveSig) { attributes.Add(preserveSigAttribute); implAttributes = (MethodImplAttributes)0; } #endregion #region MethodImplAttribute if (implAttributes != MethodImplAttributes.IL) { var methodImpl = new DefaultUnresolvedAttribute(methodImplAttributeTypeRef, new[] { methodImplOptionsTypeRef }); methodImpl.PositionalArguments.Add(CreateSimpleConstantValue(methodImplOptionsTypeRef, (int)implAttributes)); attributes.Add(interningProvider.Intern(methodImpl)); } #endregion var customAttributes = methodDefinition.CustomAttributes; AddCustomAttributes (customAttributes, attributes); if (methodDefinition.Attributes.HasFlag (MethodAttributes.HasSecurity)) { AddSecurityAttributes(CustomAttributeData.__GetDeclarativeSecurity (methodDefinition), attributes); } FieldMarshal marshalInfo; if (methodDefinition.ReturnParameter.__TryGetFieldMarshal (out marshalInfo)) { returnTypeAttributes.Add(ConvertMarshalInfo(marshalInfo)); } // TODO: Not needed in ikvm - maybe a work around for a cecil bug ? // AddCustomAttributes(methodDefinition.ReturnType.CustomAttributes, returnTypeAttributes); }
void AddAttributes(Assembly assembly, IList<IUnresolvedAttribute> outputList) { AddCustomAttributes(assembly.CustomAttributes, outputList); AddSecurityAttributes(CustomAttributeData.__GetDeclarativeSecurity (assembly), outputList); // AssemblyVersionAttribute if (assembly.GetName ().Version != null) { var assemblyVersion = new DefaultUnresolvedAttribute(assemblyVersionAttributeTypeRef, new[] { KnownTypeReference.String }); assemblyVersion.PositionalArguments.Add(CreateSimpleConstantValue(KnownTypeReference.String, assembly.GetName ().Version.ToString())); outputList.Add(interningProvider.Intern(assemblyVersion)); } }
public override void VisitDocument(AXmlDocument document) { currentDocument = document; AXmlElement rootElement = currentDocument.Children.OfType<AXmlElement>().FirstOrDefault(); if (rootElement != null) { string className = rootElement.GetAttributeValue(XamlConst.XamlNamespace, "Class"); string modifier = rootElement.GetAttributeValue(XamlConst.XamlNamespace, "ClassModifier"); if (className != null) { TypeDefinition = new DefaultUnresolvedTypeDefinition(className) { Kind = TypeKind.Class, UnresolvedFile = file, Accessibility = Accessibility.Public, Region = new DomRegion(file.FileName, textDocument.GetLocation(rootElement.StartOffset), textDocument.GetLocation(rootElement.EndOffset)) }; TypeDefinition.Members.Add( new DefaultUnresolvedMethod(TypeDefinition, "InitializeComponent") { Accessibility = Accessibility.Public, ReturnType = KnownTypeReference.Void }); TypeDefinition.Members.Add( new DefaultUnresolvedField(TypeDefinition, "_contentLoaded") { Accessibility = Accessibility.Private, ReturnType = KnownTypeReference.Boolean }); var connectMember = new DefaultUnresolvedMethod(TypeDefinition, "Connect") { Accessibility = Accessibility.Private, ReturnType = KnownTypeReference.Void }; connectMember.Parameters.Add(new DefaultUnresolvedParameter(KnownTypeReference.Int32, "connectionId")); connectMember.Parameters.Add(new DefaultUnresolvedParameter(KnownTypeReference.Object, "target")); TypeDefinition.Members.Add(connectMember); connectMember.ExplicitInterfaceImplementations.Add( new DefaultMemberReference(SymbolKind.Method, new GetClassTypeReference(new FullTypeName(typeof(System.Windows.Markup.IComponentConnector).FullName)), "Connect")); var browsableAttribute = new DefaultUnresolvedAttribute(new GetClassTypeReference(new FullTypeName(typeof(System.ComponentModel.EditorBrowsableAttribute).FullName))); browsableAttribute.PositionalArguments.Add( new SimpleConstantValue( new GetClassTypeReference(new FullTypeName(typeof(System.ComponentModel.EditorBrowsableAttribute).FullName)), System.ComponentModel.EditorBrowsableState.Never )); connectMember.Attributes.Add(browsableAttribute); TypeDefinition.BaseTypes.Add(CreateTypeReference(rootElement.Namespace, rootElement.LocalName)); TypeDefinition.BaseTypes.Add(new GetClassTypeReference(new FullTypeName(typeof(System.Windows.Markup.IComponentConnector).FullName))); if (modifier != null) TypeDefinition.Accessibility = ParseAccessibility(modifier); } } base.VisitDocument(document); }