Exemplo n.º 1
0
        private TypeReference Fix(TypeReference type, IGenericParameterProvider context)
        {
            if (type == null || type.IsDefinition)
                return type;

            if (type.IsGenericParameter)
            {
                var genPar = (GenericParameter)type;
                if (!fixedGenericParameters.Contains(genPar))
                {
                    fixedGenericParameters.Add(genPar);
                    FixReferences(genPar.Constraints, context);
                    FixReferences(genPar.CustomAttributes, context);
                }
                return type;
            }

            if (type is TypeSpecification)
                return Fix((TypeSpecification)type, context);
            
            var t2 = repack.GetMergedTypeFromTypeRef(type);
            if (t2 != null)
                return t2;
            
            if (type.IsNested)
                type.DeclaringType = Fix(type.DeclaringType, context);

            if (type.DeclaringType is TypeDefinition)
                return ((TypeDefinition)type.DeclaringType).NestedTypes.FirstOrDefault(x => x.FullName == type.FullName);
            
            return type;
        }
Exemplo n.º 2
0
		public void Push (IGenericParameterProvider provider)
		{
			if (stack == null)
				stack = new Collection<IGenericParameterProvider> (1) { provider };
			else
				stack.Add (provider);
		}
		internal void CheckProvider (IGenericParameterProvider provider, int count)
		{
			if (!AllowCreation)
				return;

			for (int i = provider.GenericParameters.Count; i < count; i++)
				provider.GenericParameters.Add (new GenericParameter (provider));
		}
Exemplo n.º 4
0
        public static void CopyGenericParameters(IGenericParameterProvider source, IGenericParameterProvider target, ReferenceResolver resolver)
        {
            if (!source.HasGenericParameters)
                return;

            foreach (var parameter in source.GenericParameters)
                target.InjectGenericParameter(parameter, resolver);
        }
Exemplo n.º 5
0
        public static void ImportGenericParameters(IGenericParameterProvider imported, Type original)
        {
            var parameters = original.GetGenericTypeDefinition().GetGenericArguments();
            var imported_parameters = imported.GenericParameters;

            for (int i = 0; i < parameters.Length; i++)
                imported_parameters.Add(new GenericParameter(parameters[i].Name, imported));
        }
Exemplo n.º 6
0
        public static void ImportGenericParameters(IGenericParameterProvider imported, IGenericParameterProvider original)
        {
            var parameters = original.GenericParameters;
            var imported_parameters = imported.GenericParameters;

            for (int i = 0; i < parameters.Count; i++)
                imported_parameters.Add(new GenericParameter(parameters[i].Name, imported));
        }
Exemplo n.º 7
0
 public TypeReference GetGenericParameter(GenericParameter genericParamter, IGenericParameterProvider[] paramProviders)
 {
     #if GENERIC
     IGenericParameterProvider context = GetContext(genericParamter, paramProviders);
     return context.GenericParameters[genericParamter.Position];
     #else
     return type;
     #endif
 }
 public static Collection<GenericParameter> GetGenericParameters(
     IGenericParameterProvider self,
     ref Collection<GenericParameter> collection,
     ModuleDefinition module)
 {
     return Mixin.HasImage(module)
         ? module.Read(ref collection, self, (provider, reader) => reader.ReadGenericParameters(provider))
         : collection = new GenericParameterCollection(self);
 }
	static void Process (IGenericParameterProvider provider)
	{
		if (!provider.HasGenericParameters)
			return;


		foreach (var parameter in provider.GenericParameters)
			Process (parameter);
	}
Exemplo n.º 10
0
        public GenericParameter(string name, IGenericParameterProvider owner)
            : base(string.Empty, name)
        {
            if (owner == null)
                throw new ArgumentNullException ();

            this.owner = owner;
            this.etype = owner.GenericParameterType == GenericParameterType.Type ? ElementType.Var : ElementType.MVar;
        }
Exemplo n.º 11
0
 public GenericContext(IGenericParameterProvider provider)
 {
     if (provider is TypeReference)
         m_type = provider as TypeReference;
     else if (provider is MethodReference) {
         MethodReference meth = provider as MethodReference;
         m_method = meth;
         m_type = meth.DeclaringType;
     }
 }
Exemplo n.º 12
0
 public static bool ContainsGenericParameter(IGenericParameterProvider provider, TypeReference parameter)
 {
     foreach (var param in provider.GenericParameters)
     {
         if (param.MetadataToken == parameter.MetadataToken)
         {
             return true;
         }
     }
     return false;
 }
Exemplo n.º 13
0
 private void AssertGenericParametersAreIdentical(IGenericParameterProvider expected, IGenericParameterProvider actual)
 {
     Assert.Equal(expected.HasGenericParameters, actual.HasGenericParameters);
     for (var i = 0; i < expected.GenericParameters.Count; i += 1)
     {
         var ap = expected.GenericParameters[i];
         var bp = actual.GenericParameters[i];
         Assert.Equal(ap.Name, bp.Name);
         Assert.Equal(ap.Position, bp.Position);
     }
 }
Exemplo n.º 14
0
		static TypeReference GenericTypeFor (IGenericParameterProvider context)
		{
			var type = context as TypeReference;
			if (type != null)
				return type.GetElementType ();

			var method = context as MethodReference;
			if (method != null)
				return method.DeclaringType.GetElementType ();

			throw new InvalidOperationException ();
		}
 public void Process(IGenericParameterProvider provider)
 {
     if (!provider.HasGenericParameters)
     {
         return;
     }
     foreach (var parameter in provider.GenericParameters
                                       .Where(x => x.HasCustomAttributes))
     {
         Process(parameter);
     }
 }
Exemplo n.º 16
0
 private FieldReference Fix(FieldReference field, IGenericParameterProvider context)
 {
     field.DeclaringType = Fix(field.DeclaringType, context);
     if (field.DeclaringType.IsDefinition && !field.IsDefinition)
     {
         FieldDefinition def = ((TypeDefinition)field.DeclaringType).Fields.First(x => x.Name == field.Name);
         if (def == null)
             throw new NullReferenceException("Field \"" + field + "\" not found in type \"" + field.DeclaringType + "\".");
         return def;
     }
     field.FieldType = Fix(field.FieldType, context);
     return field;
 }
Exemplo n.º 17
0
        internal MethodReference Fix(MethodReference method, IGenericParameterProvider context)
        {
            TypeReference declaringType = Fix(method.DeclaringType, context);
            if (method.IsGenericInstance)
            {
                return Fix((GenericInstanceMethod)method, context);
            }
            // if declaring type is in our new merged module, return the definition
            if (declaringType.IsDefinition && !method.IsDefinition)
            {
                MethodDefinition def = new ReflectionHelper(repack).FindMethodDefinitionInType((TypeDefinition)declaringType, method);
                if (def != null)
                    return def;
            }
            method.DeclaringType = declaringType;
            method.ReturnType = Fix(method.ReturnType, method);

            FixReferences(method.Parameters, method);
            FixReferences(method.GenericParameters, method);

            if (!method.IsDefinition &&
                !method.DeclaringType.IsGenericInstance &&
                !method.DeclaringType.IsArray &&
                (method.ReturnType.IsDefinition || method.Parameters.Any(x => x.ParameterType.IsDefinition)))
            {
                var culprit = method.ReturnType.IsDefinition
                                     ? method.ReturnType
                                     : method.Parameters.First(x => x.ParameterType.IsDefinition).ParameterType;
                // warn about invalid merge assembly set, as this method is not gonna work fine (peverify would warn as well)
                repack.WARN("Method reference is used with definition return type / parameter. Indicates a likely invalid set of assemblies, consider one of the following");
                repack.WARN(" - Remove the assembly defining " + culprit + " from the merge");
                repack.WARN(" - Add assembly defining " + method + " to the merge");

                // one case where it'll work correctly however (but doesn't seem common):
                // A references B
                // C references A
                // C is merged into B
            }
            return method;
        }
Exemplo n.º 18
0
        /// <summary>
        /// Returns the base-most MethodDefinition (for implicitly or explicitly overridden methods) in this assembly.
        /// (Meaning overridden methods in referenced assemblies do not count, therefore it returns a Definition, not a Reference.)
        /// </summary>
        public void FixOverridenMethodDef(MethodDefinition meth, IGenericParameterProvider context)
        {
            foreach (var ov in meth.Overrides)
            {
                MethodReference fixedOv = Fix(ov, context);
                if (fixedOv.IsDefinition)
                {
                    if (fixedOv.Module == meth.Module)
                    {
                        // it's a Definition, and in our module
                        MethodDefinition fixedOvDef = (MethodDefinition)fixedOv;
                        if (fixedOvDef.IsVirtual)
                            Fix((MethodDefinition) fixedOv, meth);
                    }
                }
            }

            // no explicit overrides found, check implicit overrides
            MethodDefinition @base = MethodMatcher.MapVirtualMethod(meth);
            if (@base != null && @base.IsVirtual)
                Fix(@base, meth);
        }
Exemplo n.º 19
0
        private TypeReference Fix(TypeReference type, IGenericParameterProvider context)
        {
            if (type == null || type.IsDefinition)
                return type;

            if (type.IsGenericParameter)
            {
                var genPar = (GenericParameter)type;
                if (!fixedGenericParameters.Contains(genPar))
                {
                    fixedGenericParameters.Add(genPar);
                    FixReferences(genPar.Constraints, context);
                    FixReferences(genPar.CustomAttributes, context);
                }
                return type;
            }

            if (type is TypeSpecification)
            {
                return Fix((TypeSpecification)type, context);
            }
            if (type.IsNested)
            {
                type.DeclaringType = Fix(type.DeclaringType, context);
                // might need to do more
                if (type.DeclaringType is TypeDefinition)
                {
                    return ((TypeDefinition)type.DeclaringType).NestedTypes.First(x => x.FullName == type.FullName);
                }
            }
            else
            {
                type = duplicateHandler.Rename(type);
                return FixImpl(type);
            }
            return type;
        }
Exemplo n.º 20
0
        public GenericResolutionWindow(IGenericParameterProvider generic, TypeDefinition context)
        {
            //Component initialization
            InitializeComponent();
            originalGeneric = generic;

            //Sets icon and text
            var node = new ILEditTreeNode(generic, true);
            ImgIcon.Source = (ImageSource)node.Icon;
            LblName.Text = node.Text.ToString();

            //Sets destination type
            LblDestinationType.Text = new ILEditTreeNode(context, true).Text.ToString();

            //Populates the list
            LstParameters.ItemsSource =
                generic.GenericParameters
                .Select(p => {
                    var row = new GenericParameterRowItem() { Name = p.Name, MemberFilter = Injection.MemberFilters.Types, DestinationModule = context.Module, EnclosingType = context };
                    row.HasSelectedParameter = false;
                    row.Selected += Row_Selected;
                    return row;
                }).ToArray();
        }
Exemplo n.º 21
0
 public void RemoveGenericParameterRange(IGenericParameterProvider owner)
 {
     GenericParameters.Remove(owner.MetadataToken);
 }
Exemplo n.º 22
0
 internal GenericParameterCollection(IGenericParameterProvider owner, int capacity)
     : base(capacity)
 {
     this.owner = owner;
 }
Exemplo n.º 23
0
 /// <summary>
 /// Clones a collection of SecurityDeclarations
 /// </summary>
 public void CopySecurityDeclarations(Collection <SecurityDeclaration> input, Collection <SecurityDeclaration> output, IGenericParameterProvider context)
 {
     foreach (SecurityDeclaration sec in input)
     {
         SecurityDeclaration newSec = null;
         if (PermissionsetHelper.IsXmlPermissionSet(sec))
         {
             newSec = PermissionsetHelper.Xml2PermissionSet(sec, _repackContext.TargetAssemblyMainModule);
         }
         if (newSec == null)
         {
             newSec = new SecurityDeclaration(sec.Action);
             foreach (SecurityAttribute sa in sec.SecurityAttributes)
             {
                 SecurityAttribute newSa = new SecurityAttribute(Import(sa.AttributeType, context));
                 if (sa.HasFields)
                 {
                     foreach (CustomAttributeNamedArgument cana in sa.Fields)
                     {
                         newSa.Fields.Add(Copy(cana, context));
                     }
                 }
                 if (sa.HasProperties)
                 {
                     foreach (CustomAttributeNamedArgument cana in sa.Properties)
                     {
                         newSa.Properties.Add(Copy(cana, context));
                     }
                 }
                 newSec.SecurityAttributes.Add(newSa);
             }
         }
         output.Add(newSec);
     }
 }
Exemplo n.º 24
0
        public ImportGenericContext(IGenericParameterProvider provider)
        {
            stack = null;

            Push(provider);
        }
Exemplo n.º 25
0
        public void CopyCustomAttributes(Collection <CustomAttribute> input, Collection <CustomAttribute> output, bool allowMultiple, IGenericParameterProvider context)
        {
            var reflectionHelper = _repackContext.ReflectionHelper;

            foreach (CustomAttribute ca in input)
            {
                var caType            = ca.AttributeType;
                var similarAttributes = output.Where(attr => reflectionHelper.AreSame(attr.AttributeType, caType)).ToList();
                if (similarAttributes.Count != 0)
                {
                    if (!allowMultiple)
                    {
                        continue;
                    }
                    if (!CustomAttributeTypeAllowsMultiple(caType))
                    {
                        continue;
                    }
                    if (similarAttributes.Any(x =>
                                              reflectionHelper.AreSame(x.ConstructorArguments, ca.ConstructorArguments) &&
                                              reflectionHelper.AreSame(x.Fields, ca.Fields) &&
                                              reflectionHelper.AreSame(x.Properties, ca.Properties)
                                              ))
                    {
                        continue;
                    }
                }
                output.Add(Copy(ca, context));
            }
        }
Exemplo n.º 26
0
 public ImportContext(IImporter importer, IGenericParameterProvider provider)
 {
     m_importer   = importer;
     m_genContext = new GenericContext(provider);
 }
Exemplo n.º 27
0
 public FieldReference Import(FieldReference field, IGenericParameterProvider context)
 {
     return(ImportReference(field, context));
 }
Exemplo n.º 28
0
 public virtual MethodReference ImportReference(MethodReference method, IGenericParameterProvider context)
 {
     Mixin.CheckMethod(method);
     return(ImportMethod(method, ImportGenericContext.For(context)));
 }
 public static bool GetHasGenericParameters(
     this IGenericParameterProvider self,
     ModuleDefinition module)
 {
     return(module.HasImage() && module.Read(self, (provider, reader) => reader.HasGenericParameters(provider)));
 }
Exemplo n.º 30
0
 public virtual FieldReference ImportReference(FieldReference field, IGenericParameterProvider context)
 {
     Mixin.CheckField(field);
     return(ImportField(field, ImportGenericContext.For(context)));
 }
Exemplo n.º 31
0
 public virtual TypeReference ImportReference(TypeReference type, IGenericParameterProvider context)
 {
     Mixin.CheckType(type);
     return(ImportType(type, ImportGenericContext.For(context)));
 }
Exemplo n.º 32
0
 public CustomAttributeNamedArgument Copy(CustomAttributeNamedArgument namedArg, IGenericParameterProvider context)
 {
     return(new CustomAttributeNamedArgument(namedArg.Name, Copy(namedArg.Argument, context)));
 }
Exemplo n.º 33
0
 private GenericParameter FixPlatformVersion(GenericParameter gp, IGenericParameterProvider gpp)
 {
     GenericParameter ngp = new GenericParameter(gp.Name, gpp);
     ngp.Attributes = gp.Attributes;
     foreach (TypeReference tr in gp.Constraints)
         ngp.Constraints.Add(FixPlatformVersion(tr));
     foreach (CustomAttribute ca in gp.CustomAttributes)
         ngp.CustomAttributes.Add(FixPlatformVersion(ca));
     if (gp.DeclaringType != null )
         ngp.DeclaringType = FixPlatformVersion(gp.DeclaringType);
     foreach (GenericParameter gp1 in gp.GenericParameters)
         ngp.GenericParameters.Add(FixPlatformVersion(gp1, ngp));
     return ngp;
 }
Exemplo n.º 34
0
 public GenericParameter(IGenericParameterProvider owner)
     : this(string.Empty, owner)
 {
 }
Exemplo n.º 35
0
 public CustomAttributeArgument Copy(CustomAttributeArgument arg, IGenericParameterProvider context)
 {
     return(new CustomAttributeArgument(Import(arg.Type, context), ImportCustomAttributeValue(arg.Value, context)));
 }
Exemplo n.º 36
0
 bool AddMethodArgType(IGenericParameterProvider gpp, Parameter methodParam, ITypeDefOrRef type)
 {
     return(AddMethodArgType(gpp, methodParam, type.ToTypeSig()));
 }
Exemplo n.º 37
0
 public MethodReference Import(MethodReference method, IGenericParameterProvider context)
 {
     return(ImportReference(method, context));
 }
Exemplo n.º 38
0
        protected virtual bool IsValidType(IGenericParameterProvider gpp, TypeSig type)
        {
            if (type == null)
            {
                return(false);
            }
            if (type.ElementType == ElementType.Void)
            {
                return(false);
            }

            while (type != null)
            {
                switch (type.ElementType)
                {
                case ElementType.GenericInst:
                    foreach (var ga in ((GenericInstSig)type).GenericArguments)
                    {
                        if (!IsValidType(gpp, ga))
                        {
                            return(false);
                        }
                    }
                    break;

                case ElementType.SZArray:
                case ElementType.Array:
                case ElementType.Ptr:
                case ElementType.Class:
                case ElementType.ValueType:
                case ElementType.Void:
                case ElementType.Boolean:
                case ElementType.Char:
                case ElementType.I1:
                case ElementType.U1:
                case ElementType.I2:
                case ElementType.U2:
                case ElementType.I4:
                case ElementType.U4:
                case ElementType.I8:
                case ElementType.U8:
                case ElementType.R4:
                case ElementType.R8:
                case ElementType.TypedByRef:
                case ElementType.I:
                case ElementType.U:
                case ElementType.String:
                case ElementType.Object:
                    break;

                case ElementType.Var:
                case ElementType.MVar:
                    // TODO: Return false for now. We don't know whether the Var is a Var in
                    // this type or from some other type.
                    return(false);

                case ElementType.ByRef:
                case ElementType.FnPtr:
                case ElementType.CModOpt:
                case ElementType.CModReqd:
                case ElementType.Pinned:
                case ElementType.Sentinel:
                case ElementType.ValueArray:
                case ElementType.R:
                case ElementType.End:
                case ElementType.Internal:
                case ElementType.Module:
                default:
                    return(false);
                }

                if (type.Next == null)
                {
                    break;
                }
                type = type.Next;
            }

            return(type != null);
        }
Exemplo n.º 39
0
 public TypeReference Import(Type type, IGenericParameterProvider context)
 {
     return(ImportReference(type, context));
 }
Exemplo n.º 40
0
 //--- Constructors ---
 public ParameterBuilder(IGenericParameterProvider genericParameterProvider, Func<Type, ReflectedTypeInfo> getType) {
     _genericParameterProvider = genericParameterProvider;
     _getType = getType;
 }
Exemplo n.º 41
0
 public void CopyCustomAttributes(Collection <CustomAttribute> input, Collection <CustomAttribute> output, IGenericParameterProvider context)
 {
     CopyCustomAttributes(input, output, true, context);
 }
Exemplo n.º 42
0
		public static void OutputGenericParameters (XmlDocument document, XmlNode nclass, IGenericParameterProvider provider)
		{
			if (provider.GenericParameters.Count == 0)
				return;

			var gparameters = provider.GenericParameters;

			XmlElement ngeneric = document.CreateElement (string.Format ("generic-parameters"));
			nclass.AppendChild (ngeneric);

			foreach (GenericParameter gp in gparameters) {
				XmlElement nparam = document.CreateElement (string.Format ("generic-parameter"));
				nparam.SetAttribute ("name", gp.Name);
				nparam.SetAttribute ("attributes", ((int) gp.Attributes).ToString ());

				AttributeData.OutputAttributes (document, nparam, gp.CustomAttributes);

				ngeneric.AppendChild (nparam);

				var constraints = gp.Constraints;
				if (constraints.Count == 0)
					continue;

				XmlElement nconstraint = document.CreateElement ("generic-parameter-constraints");

				foreach (TypeReference constraint in constraints) {
					XmlElement ncons = document.CreateElement ("generic-parameter-constraint");
					ncons.SetAttribute ("name", Utils.CleanupTypeName (constraint));
					nconstraint.AppendChild (ncons);
				}

				nparam.AppendChild (nconstraint);
			}
		}
Exemplo n.º 43
0
        public void CopyGenericParameters(Collection <GenericParameter> input, Collection <GenericParameter> output, IGenericParameterProvider nt)
        {
            foreach (GenericParameter gp in input)
            {
                GenericParameter ngp = new GenericParameter(gp.Name, nt);

                ngp.Attributes = gp.Attributes;
                output.Add(ngp);
            }
            // delay copy to ensure all generics parameters are already present
            Copy(input, output, (gp, ngp) => CopyTypeReferences(gp.Constraints, ngp.Constraints, nt));
            Copy(input, output, (gp, ngp) => CopyCustomAttributes(gp.CustomAttributes, ngp.CustomAttributes, nt));
        }
Exemplo n.º 44
0
 /// <summary>
 /// Format the generic parameters of given provider.
 /// </summary>
 private static string GetGenericParameters(IGenericParameterProvider provider)
 {
     if (!provider.HasGenericParameters) return string.Empty;
     return "<" + string.Join(", ", provider.GenericParameters.Select(x => x.Name)) + ">";
 }
Exemplo n.º 45
0
        public FieldReference Import(FieldReference reference, IGenericParameterProvider context)
        {
            _repackContext.PlatformFixer.FixPlatformVersion(reference);

            return(_repackContext.TargetAssemblyMainModule.ImportReference(reference, context));
        }
Exemplo n.º 46
0
 internal GenericParameter(int pos, IGenericParameterProvider owner)
     : base(string.Empty, string.Empty)
 {
     m_position = pos;
     m_owner = owner;
 }
Exemplo n.º 47
0
 internal GenericParameterCollection(IGenericParameterProvider owner)
 {
     this.owner = owner;
 }
Exemplo n.º 48
0
 public bool TryGetGenericParameterRanges(IGenericParameterProvider owner, out Range [] ranges)
 {
     return(GenericParameters.TryGetValue(owner.MetadataToken, out ranges));
 }
Exemplo n.º 49
0
        public ImportGenericContext(IGenericParameterProvider provider)
        {
            stack = null;

            Push (provider);
        }
Exemplo n.º 50
0
 private GenericParameter CreateGenericParameter(Il2CppGenericParameter param, IGenericParameterProvider iGenericParameterProvider)
 {
     if (!genericParameterDic.TryGetValue(param, out var genericParameter))
     {
         var genericName = metadata.GetStringFromIndex(param.nameIndex);
         genericParameter            = new GenericParameter(genericName, iGenericParameterProvider);
         genericParameter.Attributes = (GenericParameterAttributes)param.flags;
         genericParameterDic.Add(param, genericParameter);
         for (int i = 0; i < param.constraintsCount; ++i)
         {
             var il2CppType = il2Cpp.types[metadata.constraintIndices[param.constraintsStart + i]];
             genericParameter.Constraints.Add(new GenericParameterConstraint(GetTypeReference((MemberReference)iGenericParameterProvider, il2CppType)));
         }
     }
     return(genericParameter);
 }
Exemplo n.º 51
0
		static void ImportGenericParameters (IGenericParameterProvider provider, Type [] arguments)
		{
			var provider_parameters = provider.GenericParameters;

			for (int i = 0; i < arguments.Length; i++)
				provider_parameters.Add (new GenericParameter (arguments [i].Name, provider));
		}
Exemplo n.º 52
0
 public void CopyTypeReferences(Collection <TypeReference> input, Collection <TypeReference> output, IGenericParameterProvider context)
 {
     foreach (TypeReference ta in input)
     {
         output.Add(Import(ta, context));
     }
 }
		private void WriteGenericParametersToDefinition(IGenericParameterProvider genericDefinition, Action<GenericParameter> writeParamConstraints, bool renameInvalidCharacters)
		{
			int i = 0;

			if (genericDefinition is TypeDefinition)
			{
				TypeDefinition nestedType = genericDefinition as TypeDefinition;
				TypeDefinition parentType = nestedType.DeclaringType;
				if (parentType != null && parentType.HasGenericParameters)
				{
					i = parentType.GenericParameters.Count;
				}
			}
			if (i < genericDefinition.GenericParameters.Count)
			{
				WriteToken(GenericLeftBracket);
				for (; i < genericDefinition.GenericParameters.Count; i++)
				{
					GenericParameter currentParameter = genericDefinition.GenericParameters[i];
					if (currentParameter.IsCovariant)
					{
						WriteKeyword(KeyWordWriter.Covariant);
						WriteSpace();
					}
					if (currentParameter.IsContravariant)
					{
						WriteKeyword(KeyWordWriter.Contravariant);
						WriteSpace();
					}
					WriteReference(renameInvalidCharacters ? GenericHelper.ReplaceInvalidCharactersName(Language, currentParameter.Name) : currentParameter.Name, null);
					if (currentParameter.HasConstraints || currentParameter.HasDefaultConstructorConstraint ||
						currentParameter.HasReferenceTypeConstraint || currentParameter.HasNotNullableValueTypeConstraint)
					{
						if (writeParamConstraints != null)
						{
							writeParamConstraints(currentParameter);
						}
						//WriteGenericParameterConstraints(currentParameter);
					}
					if (i != genericDefinition.GenericParameters.Count - 1)
					{
						WriteToken(",");
						WriteSpace();
					}
				}
				WriteToken(GenericRightBracket);
			}
		}
Exemplo n.º 54
0
        public void CopyTypeReferences(GenericParameter genericParameter, GenericParameter nonGenericParameter, IGenericParameterProvider provider)
        {
            ICollection <TypeReference> genericParametersCollection =
                genericParameter.Constraints
                .Select(item => item.ConstraintType)
                .ToList();

            ICollection <TypeReference> nonGenericParametersCollection =
                nonGenericParameter.Constraints
                .Select(item => item.ConstraintType)
                .ToList();

            CopyTypeReferences(
                new Collection <TypeReference>(genericParametersCollection),
                new Collection <TypeReference>(nonGenericParametersCollection),
                provider);
        }
Exemplo n.º 55
0
        internal static IGenericInstanceForm GetForm(IGenericParameterProvider provider, IGenericParameterProvider context)
        {
            if (provider == null)
            {
                return(null);
            }

            if (!provider.HasGenericParameters)
            {
                return(null);
            }

            if (provider is MethodReference)
            {
                return(new GenericInstanceMethodForm(provider, context));
            }

            if (provider is TypeReference)
            {
                return(new GenericInstanceTypeForm(provider, context));
            }

            return(null);
        }
Exemplo n.º 56
0
 static ImportGenericContext GenericContextFor(IGenericParameterProvider context)
 {
     return(context != null ? new ImportGenericContext(context) : default(ImportGenericContext));
 }
Exemplo n.º 57
0
 public GenericParameter(string name, IGenericParameterProvider owner)
     : base(string.Empty, string.Empty)
 {
     m_name = name;
     m_owner = owner;
 }
Exemplo n.º 58
0
        private TypeReference ProcessTypeReference(TypeReference type, IGenericParameterProvider owner)
        {
            if (type == null)
            {
                return(null);
            }

            // ref types
            if (type is ByReferenceType)
            {
                var elementType = ProcessTypeReference(type.GetElementType(), owner);
                if (elementType != type.GetElementType())
                {
                    type = new ByReferenceType(elementType);
                }
                return(type);
            }

            // Generic MVar/Var
            if (type is GenericParameter)
            {
                var genericParameter = (GenericParameter)type;
                if ((genericParameter.MetadataType == MetadataType.MVar ||
                     genericParameter.MetadataType == MetadataType.Var) && genericParameter.Owner is MethodReference)
                {
                    if (genericParameter.Owner != null && owner != null)
                    {
                        return(owner.GenericParameters.Concat(genericParameter.Owner.GenericParameters).First(x => x.Name == type.Name));
                    }
                }
                return(type);
            }

            // Is it an async-related type?
            var asyncBridgeType = asyncBridgeAssembly.MainModule.GetTypeResolved(type.Namespace, type.Name);

            if (asyncBridgeType == null)
            {
                return(type);
            }

            // First work on inner TypeReference if there is a GenericInstanceType around it.
            var genericInstanceType = type as GenericInstanceType;

            if (genericInstanceType != null)
            {
                type = genericInstanceType.ElementType;
            }

            var newType = assembly.MainModule.ImportReference(new TypeReference(type.Namespace, type.Name, asyncBridgeAssembly.MainModule, asyncBridgeAssembly.Name, type.IsValueType));

            for (int i = 0; i < type.GenericParameters.Count; ++i)
            {
                newType.GenericParameters.Add(new GenericParameter(type.GenericParameters[i].Name, newType));
                foreach (var constraint in type.GenericParameters[i].Constraints)
                {
                    newType.GenericParameters[i].Constraints.Add(new GenericParameterConstraint(ProcessTypeReference(constraint.ConstraintType, newType)));
                }
            }

            if (genericInstanceType != null)
            {
                var newGenericType = new GenericInstanceType(newType);
                foreach (var genericArgument in genericInstanceType.GenericArguments)
                {
                    newGenericType.GenericArguments.Add(ProcessTypeReference(genericArgument, newGenericType));
                }
                newType = newGenericType;
            }

            return(newType);
        }
Exemplo n.º 59
0
		void MarkGenericParameterProvider (IGenericParameterProvider provider)
		{
			if (!provider.HasGenericParameters)
				return;

			foreach (GenericParameter parameter in provider.GenericParameters)
				MarkGenericParameter (parameter);
		}
Exemplo n.º 60
0
        private static void ImportGenericParameters(IGenericParameterProvider imported, IGenericParameterProvider original)
        {
            Collection <GenericParameter> genericParameters  = original.GenericParameters;
            Collection <GenericParameter> genericParameters1 = imported.GenericParameters;

            for (int i = 0; i < genericParameters.Count; i++)
            {
                genericParameters1.Add(new GenericParameter(genericParameters[i].Name, imported));
            }
        }