Пример #1
0
        public DomCecilType(TypeDefinition typeDefinition, bool loadInternal)
        {
            this.typeDefinition = typeDefinition;
            this.loadInternal   = loadInternal;
            this.classType      = GetClassType(typeDefinition);

            this.Name      = DomCecilType.RemoveGenericParamSuffix(typeDefinition.Name);
            this.Namespace = typeDefinition.Namespace;

            this.Modifiers = GetModifiers(typeDefinition.Attributes);

            if (typeDefinition.BaseType != null)
            {
                this.baseType = DomCecilMethod.GetReturnType(typeDefinition.BaseType);
            }
            DomCecilMethod.AddAttributes(this, typeDefinition.CustomAttributes);

            foreach (TypeReference interfaceReference in typeDefinition.Interfaces)
            {
                this.AddInterfaceImplementation(DomCecilMethod.GetReturnType(interfaceReference));
            }
            foreach (GenericParameter parameter in typeDefinition.GenericParameters)
            {
                TypeParameter tp = new TypeParameter(parameter.FullName);
                tp.Variance = (TypeParameterVariance)(((uint)parameter.Attributes) & 3);
                foreach (TypeReference tr in parameter.Constraints)
                {
                    tp.AddConstraint(DomCecilMethod.GetReturnType(tr));
                }
                AddTypeParameter(tp);
            }
        }
Пример #2
0
        public DomCecilMethod(MethodDefinition methodDefinition)
        {
            this.methodDefinition = methodDefinition;
            this.name             = methodDefinition.Name;
            if (methodDefinition.Name == ".ctor")
            {
                MethodModifier |= MethodModifier.IsConstructor;
            }

            foreach (GenericParameter param in methodDefinition.GenericParameters)
            {
                TypeParameter tp = new TypeParameter(param.FullName);
                tp.Variance = (TypeParameterVariance)(((uint)param.Attributes) & 3);

                if (param.HasDefaultConstructorConstraint)
                {
                    tp.TypeParameterModifier |= TypeParameterModifier.HasDefaultConstructorConstraint;
                }

                foreach (TypeReference tr in param.Constraints)
                {
                    tp.AddConstraint(DomCecilMethod.GetReturnType(tr));
                }
                AddTypeParameter(tp);
            }

            AddAttributes(this, methodDefinition.CustomAttributes);
            base.Modifiers  = DomCecilType.GetModifiers(methodDefinition);
            base.ReturnType = DomCecilMethod.GetReturnType(methodDefinition.ReturnType);
            foreach (ParameterDefinition paramDef in methodDefinition.Parameters)
            {
                Add(new DomCecilParameter(paramDef));
            }

            if (this.IsStatic)
            {
                foreach (IAttribute attr in this.Attributes)
                {
                    if (attr.Name == "System.Runtime.CompilerServices.ExtensionAttribute")
                    {
                        MethodModifier |= MethodModifier.IsExtension;
                        break;
                    }
                }
            }

            foreach (MethodReference overrideRef in methodDefinition.Overrides)
            {
                if (overrideRef.Name == this.name && IsPublic)
                {
                    continue;
                }
                AddExplicitInterface(GetReturnType(overrideRef.DeclaringType));
            }
        }
Пример #3
0
        protected virtual ITypeParameter Visit(ITypeParameter type, T data)
        {
            TypeParameter tp = new TypeParameter(type.Name);

            tp.TypeParameterModifier = type.TypeParameterModifier;
            foreach (IAttribute attr in type.Attributes)
            {
                tp.AddAttribute((IAttribute)attr.AcceptVisitor(this, data));
            }
            foreach (IReturnType rt in type.Constraints)
            {
                tp.AddConstraint((IReturnType)rt.AcceptVisitor(this, data));
            }
            return(tp);
        }
Пример #4
0
        protected virtual ITypeParameter Visit(ITypeParameter type, T data)
        {
            TypeParameter tp = new TypeParameter(type.Name);

            tp.ClassRequired       = type.ClassRequired;
            tp.ValueTypeRequired   = type.ValueTypeRequired;
            tp.ConstructorRequired = type.ConstructorRequired;
            foreach (IAttribute attr in type.Attributes)
            {
                tp.AddAttribute((IAttribute)attr.AcceptVisitor(this, data));
            }
            foreach (IReturnType rt in type.Constraints)
            {
                tp.AddConstraint((IReturnType)rt.AcceptVisitor(this, data));
            }
            return(tp);
        }
Пример #5
0
		public DomCecilMethod (MethodDefinition methodDefinition)
		{
			this.methodDefinition = methodDefinition;
			this.name = methodDefinition.Name;
			if (methodDefinition.Name == ".ctor") {
				MethodModifier |= MethodModifier.IsConstructor;
			}
			
			foreach (GenericParameter param in methodDefinition.GenericParameters) {
				TypeParameter tp = new TypeParameter (param.FullName);
				tp.Variance = (TypeParameterVariance)(((uint)param.Attributes) & 3);
				
				if (param.HasDefaultConstructorConstraint)
					tp.TypeParameterModifier |= TypeParameterModifier.HasDefaultConstructorConstraint;
				
				foreach (TypeReference tr in param.Constraints)
					tp.AddConstraint (DomCecilMethod.GetReturnType (tr));
				AddTypeParameter (tp);
			}
				
			AddAttributes (this, methodDefinition.CustomAttributes);
			base.Modifiers  = DomCecilType.GetModifiers (methodDefinition);
			base.ReturnType = DomCecilMethod.GetReturnType (methodDefinition.ReturnType);
			foreach (ParameterDefinition paramDef in methodDefinition.Parameters) {
				Add (new DomCecilParameter (paramDef));
			}
			
			if (this.IsStatic) {
				foreach (IAttribute attr in this.Attributes) {
					if (attr.Name == "System.Runtime.CompilerServices.ExtensionAttribute") {
						MethodModifier |= MethodModifier.IsExtension;
						break;
					}
				}
			}
			
			foreach (MethodReference overrideRef in methodDefinition.Overrides) {
				if (overrideRef.Name == this.name && IsPublic) 
					continue; 
				AddExplicitInterface (GetReturnType (overrideRef.DeclaringType));
			}
		}
Пример #6
0
			MonoDevelop.Projects.Dom.TypeParameter ConvertTemplateDefinition (Mono.CSharp.TypeParameter parameter)
			{
				var result = new MonoDevelop.Projects.Dom.TypeParameter (parameter.Name);
				if (parameter.Constraints != null) {
					foreach (var constraintExpr in parameter.Constraints.ConstraintExpressions) {
						if (constraintExpr is SpecialContraintExpr) {
							var sce = (SpecialContraintExpr)constraintExpr;
							if (sce.Constraint == SpecialConstraint.Struct)
								result.AddConstraint (DomReturnType.ValueType);
							if (sce.Constraint == SpecialConstraint.Class)
								result.AddConstraint (DomReturnType.Object);
							if (sce.Constraint == SpecialConstraint.Constructor)
								result.TypeParameterModifier |= TypeParameterModifier.HasDefaultConstructorConstraint;
						} else {
							result.AddConstraint (ConvertReturnType (constraintExpr));
						}
					}
				}
				return result;
			}
Пример #7
0
		public DomCecilType (TypeDefinition typeDefinition, bool loadInternal)
		{
			this.typeDefinition = typeDefinition;
			this.loadInternal   = loadInternal;
			this.classType      = GetClassType (typeDefinition);
			
			this.Name           = DomCecilType.RemoveGenericParamSuffix (typeDefinition.Name);
			this.Namespace      = typeDefinition.Namespace;
			
			this.Modifiers      = GetModifiers (typeDefinition.Attributes);
			
			if (typeDefinition.BaseType != null)
				this.baseType = DomCecilMethod.GetReturnType (typeDefinition.BaseType);
			DomCecilMethod.AddAttributes (this, typeDefinition.CustomAttributes);
			
			foreach (TypeReference interfaceReference in typeDefinition.Interfaces) {
				this.AddInterfaceImplementation (DomCecilMethod.GetReturnType (interfaceReference));
			}
			foreach (GenericParameter parameter in typeDefinition.GenericParameters) {
				TypeParameter tp = new TypeParameter (parameter.FullName);
				tp.Variance = (TypeParameterVariance)(((uint)parameter.Attributes) & 3);
				if (parameter.HasDefaultConstructorConstraint)
					tp.TypeParameterModifier |= TypeParameterModifier.HasDefaultConstructorConstraint;
				System.Console.WriteLine (parameter.FullName + "/" + tp.TypeParameterModifier);
				foreach (TypeReference tr in parameter.Constraints) {
					tp.AddConstraint (DomCecilMethod.GetReturnType (tr));
				}
				AddTypeParameter (tp);
			}
		}
Пример #8
0
			TypeParameter ConvertTemplateDefinition (ICSharpCode.NRefactory.Ast.TemplateDefinition template)
			{
				TypeParameter parameter = new TypeParameter (template.Name);
				foreach (ICSharpCode.NRefactory.Ast.TypeReference typeRef in template.Bases) {
					if (typeRef.Type == "constraint: struct")
						parameter.ValueTypeRequired = true; else if (typeRef.Type == "constraint: class")
						parameter.ClassRequired = true; else if (typeRef.Type == "constraint: new")
						parameter.ConstructorRequired = true; else {
						DomReturnType rt = ConvertReturnType (typeRef);
						parameter.AddConstraint (rt);
					}
				}
				return parameter;
			}