Inheritance: System.Collections.CollectionBase
		public void Constructor1_NullItem ()
		{
			CodeTypeParameter[] typeParams = new CodeTypeParameter[] { 
				new CodeTypeParameter (), null };

			CodeTypeParameterCollection coll = new CodeTypeParameterCollection (
				typeParams);
		}
		public void Constructor0 ()
		{
			CodeTypeParameterCollection coll = new CodeTypeParameterCollection ();
			Assert.IsFalse (((IList) coll).IsFixedSize, "#1");
			Assert.IsFalse (((IList) coll).IsReadOnly, "#2");
			Assert.AreEqual (0, coll.Count, "#3");
			Assert.IsFalse (((ICollection) coll).IsSynchronized, "#4");
		}
 public void AddRange(CodeTypeParameterCollection value) {
     if (value == null) {
         throw new ArgumentNullException("value");
     }
     int currentCount = value.Count;
     for (int i = 0; i < currentCount; i = ((i) + (1))) {
         this.Add(value[i]);
     }
 }
 internal static CodeMemberMethod GenerateDeserializer(string name, string typeName, CodeTypeParameterCollection genericTypeParams = null)
 {
     var deserializer = new CodeMemberMethod { Name = name };
     deserializer.Attributes = (deserializer.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
     deserializer.Attributes = (deserializer.Attributes & ~MemberAttributes.ScopeMask) | MemberAttributes.Static;
     deserializer.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(DeserializerMethodAttribute), CodeTypeReferenceOptions.GlobalReference)));
     deserializer.ReturnType = new CodeTypeReference(typeof(object));
     deserializer.Parameters.Add(new CodeParameterDeclarationExpression(typeof(Type), "expected"));
     deserializer.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(BinaryTokenStreamReader), CodeTypeReferenceOptions.GlobalReference), "stream"));
     return deserializer;
 }
 internal static CodeMemberMethod GenerateCopier(string name, string typeName, CodeTypeParameterCollection genericTypeParams = null)
 {
     var copier = new CodeMemberMethod { Name = name };
     copier.Attributes = (copier.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
     copier.Attributes = (copier.Attributes & ~MemberAttributes.ScopeMask) | MemberAttributes.Static;
     copier.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(CopierMethodAttribute), CodeTypeReferenceOptions.GlobalReference)));
     copier.ReturnType = new CodeTypeReference(typeof(object));
     copier.Parameters.Add(new CodeParameterDeclarationExpression(typeof(object), "original"));
     copier.Statements.Add(new CodeVariableDeclarationStatement(typeName, "input", new CodeCastExpression(typeName, new CodeArgumentReferenceExpression("original"))));
     return copier;
 }
		public void AddRange (CodeTypeParameterCollection value)
		{
			if (value == null) {
				throw new ArgumentNullException ("value");
			}

			int count = value.Count;
			for (int i = 0; i < count; i++) {
				Add (value[i]);
			}
		}
 internal static CodeMemberMethod GenerateSerializer(string name, string typeName, CodeTypeParameterCollection genericTypeParams = null)
 {
     var serializer = new CodeMemberMethod { Name = name };
     serializer.Attributes = (serializer.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
     serializer.Attributes = (serializer.Attributes & ~MemberAttributes.ScopeMask) | MemberAttributes.Static;
     serializer.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(SerializerMethodAttribute), CodeTypeReferenceOptions.GlobalReference)));
     serializer.ReturnType = new CodeTypeReference(typeof(void));
     serializer.Parameters.Add(new CodeParameterDeclarationExpression(typeof(object), "original"));
     serializer.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(BinaryTokenStreamWriter), CodeTypeReferenceOptions.GlobalReference), "stream"));
     serializer.Parameters.Add(new CodeParameterDeclarationExpression(typeof(Type), "expected"));
     serializer.Statements.Add(new CodeVariableDeclarationStatement(typeName, "input", new CodeCastExpression(typeName, new CodeArgumentReferenceExpression("original"))));
     return serializer;
 }
		public void Constructor1 ()
		{
			CodeTypeParameter tp1 = new CodeTypeParameter ();
			CodeTypeParameter tp2 = new CodeTypeParameter ();

			CodeTypeParameter[] typeParams = new CodeTypeParameter[] { tp1, tp2 };
			CodeTypeParameterCollection coll = new CodeTypeParameterCollection (
				typeParams);

			Assert.AreEqual (2, coll.Count, "#1");
			Assert.AreEqual (0, coll.IndexOf (tp1), "#2");
			Assert.AreEqual (1, coll.IndexOf (tp2), "#3");
		}
Exemple #9
0
        public static CodeTypeParameterCollection GenericTypeParameters(Type t)
        {
            if (!t.IsGenericType) return null; 

            var p = new CodeTypeParameterCollection();
            foreach (var genericParameter in t.GetGenericTypeDefinition().GetGenericArguments())
            {
                var param = new CodeTypeParameter(genericParameter.Name);
                if ((genericParameter.GenericParameterAttributes &
                     GenericParameterAttributes.ReferenceTypeConstraint) != GenericParameterAttributes.None)
                {
                    param.Constraints.Add(" class");
                }
                if ((genericParameter.GenericParameterAttributes &
                     GenericParameterAttributes.NotNullableValueTypeConstraint) != GenericParameterAttributes.None)
                {
                    param.Constraints.Add(" struct");
                }
                var constraints = genericParameter.GetGenericParameterConstraints();
                foreach (var constraintType in constraints)
                {
                    param.Constraints.Add(
                        new CodeTypeReference(TypeUtils.GetParameterizedTemplateName(constraintType, false,
                            x => true)));
                }
                if ((genericParameter.GenericParameterAttributes &
                     GenericParameterAttributes.DefaultConstructorConstraint) != GenericParameterAttributes.None)
                {
                    param.HasConstructorConstraint = true;
                }
                p.Add(param);
            }
            return p;
        }
Exemple #10
0
		void OutputTypeParameters (CodeTypeParameterCollection parameters)
		{
			int count = parameters.Count;
			if (count == 0)
				return;

			Output.Write ("(Of ");
			for (int i = 0; i < count; ++i) {
				if (i > 0)
					Output.Write (", ");
				CodeTypeParameter p = parameters [i];
				Output.Write (p.Name);
				OutputTypeParameterConstraints (p);
			}
			Output.Write (')');
		}
        private void OutputTypeParameterConstraints(CodeTypeParameterCollection typeParameters) {            
            if( typeParameters.Count == 0) {
                return;
            }

            for(int i = 0; i < typeParameters.Count; i++) {
                // generating something like: "where KeyType: IComparable, IEnumerable"

                Output.WriteLine();
                Indent++;

                bool first = true;
                if( typeParameters[i].Constraints.Count > 0) {
                    foreach (CodeTypeReference typeRef in typeParameters[i].Constraints) {
                        if (first) {
                            Output.Write("where ");
                            Output.Write(typeParameters[i].Name);                                
                            Output.Write(" : ");
                            first = false;
                        }
                        else {
                            Output.Write(", ");
                        }                 
                        OutputType(typeRef);
                    }
                }
                
                if( typeParameters[i].HasConstructorConstraint) {
                    if( first) {
                        Output.Write("where ");
                        Output.Write(typeParameters[i].Name);                                
                        Output.Write(" : new()");
                    }
                    else {
                        Output.Write(", new ()");                    
                    }
                }

                Indent--;
            }
        }
		public void Constructor2 ()
		{
			CodeTypeParameter tp1 = new CodeTypeParameter ();
			CodeTypeParameter tp2 = new CodeTypeParameter ();

			CodeTypeParameterCollection c = new CodeTypeParameterCollection ();
			c.Add (tp1);
			c.Add (tp2);

			CodeTypeParameterCollection coll = new CodeTypeParameterCollection (c);
			Assert.AreEqual (2, coll.Count, "#1");
			Assert.AreEqual (0, coll.IndexOf (tp1), "#2");
			Assert.AreEqual (1, coll.IndexOf (tp2), "#3");
		}
		public void Remove_NotInCollection ()
		{
			CodeTypeParameterCollection coll = new CodeTypeParameterCollection ();
			coll.Remove (new CodeTypeParameter ());
		}
Exemple #14
0
		void GenerateGenericsConstraints (CodeTypeParameterCollection parameters)
		{
			int count = parameters.Count;
			if (count == 0)
				return;

			bool indented = false;
			
			for (int i = 0; i < count; i++) {
				CodeTypeParameter p = parameters [i];
				bool hasConstraints = (p.Constraints.Count != 0);
				Output.WriteLine ();
				if (!hasConstraints && !p.HasConstructorConstraint)
					continue;

				if (!indented) {
					++Indent;
					indented = true;
				}

				Output.Write ("where ");
				Output.Write (p.Name);
				Output.Write (" : ");

				for (int j = 0; j < p.Constraints.Count; j++) {
					if (j > 0)
						Output.Write (", ");
					OutputType (p.Constraints [j]);
				}

				if (p.HasConstructorConstraint) {
					if (hasConstraints)
						Output.Write (", ");
					Output.Write ("new");
					if (hasConstraints)
						Output.Write (" ");
					Output.Write ("()");
				}
			}

			if (indented)
				--Indent;
		}
Exemple #15
0
		void GenerateGenericsParameters (CodeTypeParameterCollection parameters)
		{
			int count = parameters.Count;
			if (count == 0)
				return;

			Output.Write ('<');
			for (int i = 0; i < count - 1; ++i) {
				Output.Write (parameters [i].Name);
				Output.Write (", ");
			}
			Output.Write (parameters [count - 1].Name);
			Output.Write ('>');
		}
Exemple #16
0
        /// <summary>
        /// Outputs type parameter declaration (part of generic type and generic method declaration).
        /// </summary>
        /// <remarks></remarks>
        private void OutputTypeParameters(CodeTypeParameterCollection typeParams)
        {
            int count;
            if (typeParams != null && (count = typeParams.Count) > 0)
            {
                Output.Write(Tokens.GenericBracketLeft);

                Output.Write(typeParams[0].Name);
                for (int i = 1; i < count; i++)
                {
                    Output.Write(Tokens.Comma + WhiteSpace.Space);
                    Output.Write(typeParams[i].Name);
                }

                Output.Write(Tokens.GenericBracketRight);
            }
        }
		public void Remove ()
		{
			CodeTypeParameter ctp1 = new CodeTypeParameter ();
			CodeTypeParameter ctp2 = new CodeTypeParameter ();

			CodeTypeParameterCollection coll = new CodeTypeParameterCollection ();
			coll.Add (ctp1);
			coll.Add (ctp2);
			Assert.AreEqual (2, coll.Count, "#1");
			Assert.AreEqual (0, coll.IndexOf (ctp1), "#2");
			Assert.AreEqual (1, coll.IndexOf (ctp2), "#3");
			coll.Remove (ctp1);
			Assert.AreEqual (1, coll.Count, "#4");
			Assert.AreEqual (-1, coll.IndexOf (ctp1), "#5");
			Assert.AreEqual (0, coll.IndexOf (ctp2), "#6");
		}
Exemple #18
0
 private void ValidateTypeParameters(CodeTypeParameterCollection parameters) {
     for (int i=0; i<parameters.Count; i++) {
         ValidateTypeParameter(parameters[i]);
     }
 }
		public void Remove_Null ()
		{
			CodeTypeParameterCollection coll = new CodeTypeParameterCollection ();
			coll.Remove ((CodeTypeParameter) null);
		}
 /// <summary>
 /// Generates a wrapper method that takes arguments of the original method.
 /// </summary>
 protected override CodeTypeMember GetBasicReferenceMethod(MethodInfo methodInfo, CodeTypeParameterCollection genericTypeParam, bool isObserver)
 {
     throw new NotImplementedException("GetBasicReferenceMethod");
 }
		public void Add_Null () {
			CodeTypeParameterCollection coll = new CodeTypeParameterCollection ();
			coll.Add ((CodeTypeParameter) null);
		}
		public void Insert ()
		{
			CodeTypeParameter tp1 = new CodeTypeParameter ();
			CodeTypeParameter tp2 = new CodeTypeParameter ();

			CodeTypeParameterCollection coll = new CodeTypeParameterCollection ();
			coll.Add (tp1);
			Assert.AreEqual (1, coll.Count, "#1");
			Assert.AreEqual (0, coll.IndexOf (tp1), "#2");
			coll.Insert (0, tp2);
			Assert.AreEqual (2, coll.Count, "#3");
			Assert.AreEqual (1, coll.IndexOf (tp1), "#4");
			Assert.AreEqual (0, coll.IndexOf (tp2), "#5");
		}
		public void Constructor1_Null () {
			CodeTypeParameterCollection coll = new CodeTypeParameterCollection (
				(CodeTypeParameter[]) null);
		}
		public void Insert_Null ()
		{
			CodeTypeParameterCollection coll = new CodeTypeParameterCollection ();
			coll.Insert (0, (CodeTypeParameter) null);
		}
        private void OutputTypeParameters(CodeTypeParameterCollection typeParameters) {            
            if( typeParameters.Count == 0) {
                return;
            }

            Output.Write('<');
            bool first = true;
            for(int i = 0; i < typeParameters.Count; i++) {
                if( first) {
                    first = false;
                }
                else {
                    Output.Write(", ");
                }

                if (typeParameters[i].CustomAttributes.Count > 0) {
                    GenerateAttributes(typeParameters[i].CustomAttributes, null, true);
                    Output.Write(' ');
                }

                Output.Write(typeParameters[i].Name);
            }

            Output.Write('>');
        }
		public void AddRange ()
		{
			CodeTypeParameter tp1 = new CodeTypeParameter ();
			CodeTypeParameter tp2 = new CodeTypeParameter ();
			CodeTypeParameter tp3 = new CodeTypeParameter ();

			CodeTypeParameterCollection coll1 = new CodeTypeParameterCollection ();
			coll1.Add (tp1);
			coll1.Add (tp2);

			CodeTypeParameterCollection coll2 = new CodeTypeParameterCollection ();
			coll2.Add (tp3);
			coll2.AddRange (coll1);
			Assert.AreEqual (3, coll2.Count, "#1");
			Assert.AreEqual (1, coll2.IndexOf (tp1), "#2");
			Assert.AreEqual (2, coll2.IndexOf (tp2), "#3");
			Assert.AreEqual (0, coll2.IndexOf (tp3), "#4");

			CodeTypeParameterCollection coll3 = new CodeTypeParameterCollection ();
			coll3.Add (tp3);
			coll3.AddRange (new CodeTypeParameter[] { tp1, tp2 });
			Assert.AreEqual (3, coll2.Count, "#5");
			Assert.AreEqual (1, coll2.IndexOf (tp1), "#6");
			Assert.AreEqual (2, coll2.IndexOf (tp2), "#7");
			Assert.AreEqual (0, coll2.IndexOf (tp3), "#8");
		}
        private static void PopulateGenericParameters(IGenericParameterProvider publicType, CodeTypeParameterCollection parameters)
        {
            foreach (var parameter in publicType.GenericParameters)
            {
                if (parameter.HasCustomAttributes)
                    throw new NotImplementedException("Attributes on type parameters is not supported. And weird");

                // A little hacky. Means we get "in" and "out" prefixed on any constraints, but it's either that
                // or add it as a custom attribute, which looks even weirder
                var name = parameter.Name;
                if (parameter.IsCovariant)
                    name = "out " + name;
                if (parameter.IsContravariant)
                    name = "in " + name;

                var typeParameter = new CodeTypeParameter(name)
                {
                    HasConstructorConstraint =
                        parameter.HasDefaultConstructorConstraint && !parameter.HasNotNullableValueTypeConstraint
                };
                if (parameter.HasNotNullableValueTypeConstraint)
                    typeParameter.Constraints.Add(" struct"); // Extra space is a hack!
                if (parameter.HasReferenceTypeConstraint)
                    typeParameter.Constraints.Add(" class");
                foreach (var constraint in parameter.Constraints.Where(t => t.FullName != "System.ValueType"))
                {
                    typeParameter.Constraints.Add(CreateCodeTypeReference(constraint.GetElementType()));
                }
                parameters.Add(typeParameter);
            }
        }
		public void AddRange_Null_Collection ()
		{
			CodeTypeParameterCollection coll = new CodeTypeParameterCollection ();
			coll.AddRange ((CodeTypeParameterCollection) null);
		}
 private void OutputTypeParameters(CodeTypeParameterCollection typeParameters)
 {
     if (typeParameters.Count != 0)
     {
         base.Output.Write("(Of ");
         bool flag = true;
         for (int i = 0; i < typeParameters.Count; i++)
         {
             if (flag)
             {
                 flag = false;
             }
             else
             {
                 base.Output.Write(", ");
             }
             base.Output.Write(typeParameters[i].Name);
             this.OutputTypeParameterConstraints(typeParameters[i]);
         }
         base.Output.Write(')');
     }
 }
		public void AddRange_Self ()
		{
			CodeTypeParameterCollection coll = new CodeTypeParameterCollection ();
			coll.Add (new CodeTypeParameter ());
			Assert.AreEqual (1, coll.Count, "#1");
			coll.AddRange (coll);
			Assert.AreEqual (2, coll.Count, "#2");
		}
 public CodeTypeParameterCollection(CodeTypeParameterCollection value)
 {
     AddRange(value);
 }
 public void AddRange(CodeTypeParameterCollection value)
 {
     throw new NotImplementedException();
 }