Inheritance: CodeObject
コード例 #1
0
ファイル: VBCodeProviderCas.cs プロジェクト: nlhepler/mono
		public void Deny_Unrestricted ()
		{
			VBCodeProvider vbprov = new VBCodeProvider ();
			Assert.AreEqual ("vb", vbprov.FileExtension, "FileExtension");
			Assert.AreEqual (LanguageOptions.CaseInsensitive, vbprov.LanguageOptions, "LanguageOptions");
			Assert.IsNotNull (vbprov.CreateCompiler (), "CreateCompiler");
			Assert.IsNotNull (vbprov.CreateGenerator (), "CreateGenerator");
			try {
				Assert.IsNotNull (vbprov.GetConverter (typeof (string)), "GetConverter");
			}
			catch (NotImplementedException) {
				// mono
			}
#if NET_2_0
			CodeTypeMember ctm = new CodeTypeMember ();
			StringWriter sw = new StringWriter ();
			CodeGeneratorOptions cgo = new CodeGeneratorOptions ();
			try {
				vbprov.GenerateCodeFromMember (ctm, sw, cgo);
			}
			catch (NotImplementedException) {
				// mono
			}
#endif
		}
コード例 #2
0
ファイル: Utils.cs プロジェクト: brian-2447/jni4net
 public static CodeAttributeDeclaration AddAttribute(CodeTypeMember tgtMethodCLR, string attr)
 {
     var declaration =
         new CodeAttributeDeclaration(new CodeTypeReference(attr, CodeTypeReferenceOptions.GlobalReference));
     tgtMethodCLR.CustomAttributes.Add(declaration);
     return declaration;
 }
コード例 #3
0
ファイル: MethodInfo.cs プロジェクト: divyang4481/lextudio
		/// <summary>
		/// Creation method.
		/// </summary>
		/// <param name="className">Class name</param>
		/// <param name="isGet">isGet flag</param>
		/// <param name="member">Member</param>
		/// <param name="statement">Statement</param>
		/// <returns></returns>
		/// <remarks>For properties.</remarks>
		public static MethodInfo CreateProperty(string className,
		                                        bool isGet,
												CodeTypeMember member,
		                                        CodeStatement statement)
		{
			return new MethodInfo(member, className, true, isGet, statement);
		}
コード例 #4
0
        protected void AddDescription(CodeTypeMember type, IEntityDescription description)
        {
            if (String.IsNullOrWhiteSpace(description.Description))
                return;

            AddAttribute(type, "Description", description.Description);
        }
 /// <summary>
 /// Creates a new instance of CodeTypeMemberExtension class.
 /// </summary>
 /// <param name="extendObject">An object to be decorated by this instance.</param>
 public CodeTypeMemberExtension(CodeTypeMember extendedObject, CodeTypeExtension parent) 
     : base(extendedObject)
 {                                  
     if (typeof(CodeMemberField) == extendedObject.GetType())
     {
         this.kind = CodeTypeMemberKind.Field;
     }
     else if (typeof(CodeMemberMethod) == extendedObject.GetType())
     {
         this.kind = CodeTypeMemberKind.Method;
     }
     else if (typeof(CodeMemberProperty) == extendedObject.GetType())
     {
         this.kind = CodeTypeMemberKind.Property;
     }
     else if (typeof(CodeMemberEvent) == extendedObject.GetType())
     {
         this.kind = CodeTypeMemberKind.Event;
     }
     else if (typeof(CodeSnippetTypeMember) == extendedObject.GetType())
     {
         this.kind = CodeTypeMemberKind.Snippet;
     }
     else if (typeof(CodeConstructor) == extendedObject.GetType())
     {
         this.kind = CodeTypeMemberKind.Constructor;
     }
     else if (typeof(CodeTypeConstructor) == extendedObject.GetType())
     {
         this.kind = CodeTypeMemberKind.StaticConstructor;
     }
     this.parent = parent;
 }
コード例 #6
0
ファイル: CodeValidator.cs プロジェクト: uQr/referencesource
        private void ValidateTypeMember(CodeTypeMember e) {
            ValidateCommentStatements(e.Comments);
            ValidateCodeDirectives(e.StartDirectives);
            ValidateCodeDirectives(e.EndDirectives);
            if (e.LinePragma != null) ValidateLinePragmaStart(e.LinePragma);

            if (e is CodeMemberEvent) {
                ValidateEvent((CodeMemberEvent)e);
            } 
            else if (e is CodeMemberField) {
                ValidateField((CodeMemberField)e);
            } 
            else if (e is CodeMemberMethod) {
                ValidateMemberMethod((CodeMemberMethod)e);
            } 
            else if (e is CodeMemberProperty) {
                ValidateProperty((CodeMemberProperty)e);
            } 
            else if (e is CodeSnippetTypeMember) {
                ValidateSnippetMember((CodeSnippetTypeMember)e);
            } 
            else if (e is CodeTypeDeclaration) {
                ValidateTypeDeclaration((CodeTypeDeclaration)e);
            } 
            else {
                throw new ArgumentException(SR.GetString(SR.InvalidElementType, e.GetType().FullName), "e");
            }
        }
コード例 #7
0
        public void Process(CodeNamespace code, System.Xml.Schema.XmlSchema schema)
        {
            foreach (CodeTypeDeclaration type in code.Types)
            {
                if (type.IsClass || type.IsStruct)
                {
                    // Copy the colletion to an array for safety. We will be
                    // changing this collection.
                    CodeTypeMember[] members = new CodeTypeMember[type.Members.Count];
                    type.Members.CopyTo(members, 0);

                    foreach (CodeTypeMember member in members)
                    {
                        // Process fields only.
                        if (member is CodeMemberField)
                        {
                            CodeMemberProperty prop = new CodeMemberProperty();
                            prop.Name = member.Name;

                            prop.Attributes = member.Attributes;
                            prop.Type = ((CodeMemberField)member).Type;

                            // Copy attributes from field to the property.
                            prop.CustomAttributes.AddRange(member.CustomAttributes);
                            member.CustomAttributes.Clear();

                            // Copy comments from field to the property.
                            prop.Comments.AddRange(member.Comments);
                            member.Comments.Clear();

                            // Modify the field.
                            member.Attributes = MemberAttributes.Private;
                            Char[] letters = member.Name.ToCharArray();
                            letters[0] = Char.ToLower(letters[0]);
                            member.Name = String.Concat("_", new string(letters));

                            prop.HasGet = true;
                            prop.HasSet = true;

                            // Add get/set statements pointing to field. Generates:
                            // return this._fieldname;
                            prop.GetStatements.Add(
                                new CodeMethodReturnStatement(
                                new CodeFieldReferenceExpression(new CodeThisReferenceExpression(),
                                member.Name)));
                            // Generates:
                            // this._fieldname = value;
                            prop.SetStatements.Add(
                                new CodeAssignStatement(
                                new CodeFieldReferenceExpression(new CodeThisReferenceExpression(),
                                member.Name),
                                new CodeArgumentReferenceExpression("value")));

                            // Finally add the property to the type
                            type.Members.Add(prop);
                        }
                    }
                }
            }
        }
コード例 #8
0
		public static IMember GetCompatibleMemberInClass (ProjectDom ctx, IType cls, CodeTypeMember member)
		{
			//check for identical property names
			foreach (IProperty prop in cls.Properties) {
				if (string.Compare (prop.Name, member.Name, StringComparison.OrdinalIgnoreCase) == 0) {
					EnsureClassExists (ctx, prop.ReturnType.FullName, GetValidRegion (prop));
					CodeMemberProperty memProp = member as CodeMemberProperty;
					if (memProp == null || !IsTypeCompatible (ctx, prop.ReturnType.FullName, memProp.Type.BaseType))
						throw new MemberExistsException (cls.FullName, MemberType.Property, member, GetValidRegion (prop), cls.CompilationUnit.FileName);
					return prop;
				}
			}
				
			//check for identical method names
			foreach (IMethod meth in cls.Methods) {
				if (string.Compare (meth.Name, member.Name, StringComparison.OrdinalIgnoreCase) == 0) {
					EnsureClassExists (ctx, meth.ReturnType.FullName, GetValidRegion (meth));
					CodeMemberMethod memMeth = member as CodeMemberMethod;
					if (memMeth == null || !IsTypeCompatible (ctx, meth.ReturnType.FullName, memMeth.ReturnType.BaseType))
						throw new MemberExistsException (cls.FullName, MemberType.Method, member, GetValidRegion (meth), cls.CompilationUnit.FileName);
					return meth;
				}
			}
			
			//check for identical event names
			foreach (IEvent ev in cls.Events) {
				if (string.Compare (ev.Name, member.Name, StringComparison.OrdinalIgnoreCase) == 0) {
					EnsureClassExists (ctx, ev.ReturnType.FullName, GetValidRegion (ev));
					CodeMemberEvent memEv = member as CodeMemberEvent;
					if (memEv == null || !IsTypeCompatible (ctx, ev.ReturnType.FullName, memEv.Type.BaseType))
						throw new MemberExistsException (cls.FullName, MemberType.Event, member, GetValidRegion (ev), cls.CompilationUnit.FileName);
					return ev;
				}
			}
				
			//check for identical field names
			foreach (IField field in cls.Fields) {
				if (string.Compare (field.Name, member.Name, StringComparison.OrdinalIgnoreCase) == 0) {
					EnsureClassExists (ctx, field.ReturnType.FullName, GetValidRegion (field));
					CodeMemberField memField = member as CodeMemberField;
					if (memField == null || !IsTypeCompatible (ctx, field.ReturnType.FullName, memField.Type.BaseType))
						throw new MemberExistsException (cls.FullName, MemberType.Field, member, GetValidRegion (field), cls.CompilationUnit.FileName);
					return field;
				}
			}
			
			//walk down into base classes, if any
			foreach (IReturnType baseType in cls.BaseTypes) {
				IType c = ctx.GetType (baseType);
				if (c == null)
					throw new TypeNotFoundException (baseType.FullName, cls.BodyRegion, cls.CompilationUnit.FileName);
				IMember mem = GetCompatibleMemberInClass (ctx, c, member);
				if (mem != null)
					return mem;
			}
			
			//return null if no match
			return null;
		}
コード例 #9
0
 /// <devdoc>
 /// <para>Copies the elements of an array to the end of the <see cref='System.CodeDom.CodeTypeMemberCollection'/>.</para>
 /// </devdoc>
 public void AddRange(CodeTypeMember[] value) {
     if (value == null) {
         throw new ArgumentNullException("value");
     }
     for (int i = 0; ((i) < (value.Length)); i = ((i) + (1))) {
         this.Add(value[i]);
     }
 }
コード例 #10
0
 protected static void AddDisplayNameIfDifferent(CodeTypeMember type, IEntityDescription description)
 {
     var name = description.Name;
     if (String.Compare(name, description.Alias, IgnoreCase) == 0 ||
         String.Compare(name, description.Alias.SplitPascalCase(), IgnoreCase) == 0)
         return;
     AddAttribute(type, "DisplayName", name);
 }
コード例 #11
0
		public void Constructor1_NullItem ()
		{
			CodeTypeMember[] typeMembers = new CodeTypeMember[] { 
				new CodeTypeMember (), null };

			CodeTypeMemberCollection coll = new CodeTypeMemberCollection (
				typeMembers);
		}
コード例 #12
0
 public TemplateMemberResult(ITemplateClassGenerator templateClass, MemberInfo memberInfo, GenerateMember memberAttribute, CodeTypeMember memberOutput, CodeTypeDeclaration decleration)
 {
     Decleration = decleration;
     TemplateClass = templateClass;
     MemberInfo = memberInfo;
     MemberAttribute = memberAttribute;
     MemberOutput = memberOutput;
 }
コード例 #13
0
ファイル: CompilerService.cs プロジェクト: brendanhay/Shared
        public void AddAttribute(CodeTypeMember member, string attributeType,
            string expression = null)
        {
            // Add [attributeType(expression)]
            var argument = new CodeAttributeArgument(new CodeSnippetExpression(expression));
            var attribute = new CodeAttributeDeclaration(attributeType, argument);

            member.CustomAttributes.Add(attribute);
        }
コード例 #14
0
        private static void AddXmlEnumAttribute(CodeTypeMember member)
        {
            CodeTypeReference attributeType = new CodeTypeReference(typeof (XmlEnumAttribute));
            CodePrimitiveExpression argumentValue = new CodePrimitiveExpression(member.Name);
            CodeAttributeArgument argument = new CodeAttributeArgument(argumentValue);
            CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(attributeType, argument);

            member.CustomAttributes.Add(attribute);
        }
コード例 #15
0
        public virtual void Add(CodeTypeMember refAdd)
        {
            CodeTypeDeclaration typedeclAdd = refAdd as CodeTypeDeclaration;
            if (this.ns == null)
            {
                this.ns = CreateNamespace();
            }

            this.ns.Types.Add(typedeclAdd);
        }
コード例 #16
0
		public void AddRange (CodeTypeMember [] value )
		{
			if (value == null) {
				throw new ArgumentNullException ("value");
			}

			for (int i = 0; i < value.Length; i++) {
				Add (value[i]);
			}
		}
コード例 #17
0
 private static void AddRootElementName(CodeTypeMember type)
 {
     foreach (CodeAttributeDeclaration attribute in type.CustomAttributes)
         if (attribute.Name == typeof (XmlRootAttribute).FullName)
         {
             CodePrimitiveExpression value = new CodePrimitiveExpression(type.Name);
             CodeAttributeArgument argument = new CodeAttributeArgument("", value);
             attribute.Arguments.Insert(0, argument);
         }
 }
コード例 #18
0
        private static string GetRootElementName(CodeTypeMember type)
        {
            foreach (CodeAttributeDeclaration attribute in type.CustomAttributes)
                if (attribute.Name == typeof (XmlRootAttribute).FullName)
                    foreach (CodeAttributeArgument argument in attribute.Arguments)
                        if (argument.Name == "")
                            return ((CodePrimitiveExpression) argument.Value).Value.ToString();

            return null;
        }
コード例 #19
0
        public static bool IsMetaDataGeneratable(CodeTypeMember member)
        {
            foreach (CodeAttributeDeclaration attribute in member.CustomAttributes)
            {
                if (attribute.Name == "PrimaryKey" || attribute.Name == "KeyProperty" || attribute.Name == "Field" || attribute.Name == "Property" || attribute.Name == "Version" || attribute.Name == "Timestamp")
                    return true;
            }

            return false;
        }
コード例 #20
0
ファイル: CodeDomUtils.cs プロジェクト: anukat2015/sones
 private static QualifiedName GetUniqueName(CodeTypeMember member, QualifiedName parentName)
 {
     if (member is CodeTypeDeclaration)
     {
         return new QualifiedName(GetUniqueName((CodeTypeDeclaration)member), null);
     }
     else
     {
         return new QualifiedName(GetUniqueName(member), parentName);
     }
 }
 private static void AddGeneratedCodeAttributeforMember(CodeTypeMember typeMember)
 {
     CodeAttributeDeclaration declaration = new CodeAttributeDeclaration(new CodeTypeReference(typeof(GeneratedCodeAttribute))) {
         AttributeType = { Options = CodeTypeReferenceOptions.GlobalReference }
     };
     CodeAttributeArgument argument = new CodeAttributeArgument(new CodePrimitiveExpression(typeof(StronglyTypedResourceBuilder).FullName));
     CodeAttributeArgument argument2 = new CodeAttributeArgument(new CodePrimitiveExpression("4.0.0.0"));
     declaration.Arguments.Add(argument);
     declaration.Arguments.Add(argument2);
     typeMember.CustomAttributes.Add(declaration);
 }
コード例 #22
0
ファイル: PropertyBuilderTest.cs プロジェクト: Jedzia/NStub
        public void BuildArgumentContextOfWrongTypeMemberShouldThrow()
        {
            var typeMember = new CodeTypeMember() { Name = "TestTypeMember" };
            var propData = mocks.Stub<IBuilderData>();
            Expect.Call(buildcontext.TypeMember).Return(typeMember);
            mocks.ReplayAll();

            Assert.Throws<ArgumentOutOfRangeException>(() => testObject.Build(this.buildcontext));

            mocks.VerifyAll();
        }
コード例 #23
0
ファイル: NoEmptyRemarks.cs プロジェクト: wskplho/Tools
 private void ClearMember(CodeTypeMember member)
 {
     List<CodeCommentStatement> delcomm = new List<CodeCommentStatement>();
     foreach (CodeCommentStatement cmnt in member.Comments)
         if (cmnt.Comment.DocComment && cmnt.Comment.Text == "<remarks/>")
             delcomm.Add(cmnt);
     foreach (CodeCommentStatement delcom in delcomm)
         member.Comments.Remove(delcom);
     if (member is CodeTypeDeclaration)
         foreach (CodeTypeMember membermember in ((CodeTypeDeclaration)member).Members)
             ClearMember(membermember);
 }
コード例 #24
0
 private static string GetXmlEnumValue(CodeTypeMember member)
 {
     if (member.CustomAttributes.Count == 1)
     {
         CodeAttributeArgument argument = member.CustomAttributes[0].Arguments[0];
         return ((CodePrimitiveExpression) argument.Value).Value.ToString();
     }
     else
     {
         AddXmlEnumAttribute(member);
         return null;
     }
 }
コード例 #25
0
		public void Constructor1 ()
		{
			CodeTypeMember tm1 = new CodeTypeMember ();
			CodeTypeMember tm2 = new CodeTypeMember ();

			CodeTypeMember[] typeMembers = new CodeTypeMember[] { tm1, tm2 };
			CodeTypeMemberCollection coll = new CodeTypeMemberCollection (
				typeMembers);

			Assert.AreEqual (2, coll.Count, "#1");
			Assert.AreEqual (0, coll.IndexOf (tm1), "#2");
			Assert.AreEqual (1, coll.IndexOf (tm2), "#3");
		}
コード例 #26
0
ファイル: CodeDomUtils.cs プロジェクト: anukat2015/sones
 private static void EnumerareCodeMembers(CodeTypeMember member, QualifiedName parentName, Dictionary<string, CodeTypeMember> members)
 {
     QualifiedName memberName = GetUniqueName(member, parentName);
     members[memberName.ToString()] = member;
     CodeTypeDeclaration decl = member as CodeTypeDeclaration;
     if (decl != null)
     {
         foreach (CodeTypeMember subMember in decl.Members)
         {
             EnumerareCodeMembers(subMember, memberName, members);
         }
     }
 }
コード例 #27
0
ファイル: FieldInfo.cs プロジェクト: divyang4481/lextudio
		/// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="tag"></param>
		/// <param name="className"></param>
		public FieldInfo(CodeTypeMember tag, string className)
			: base(tag, className)
		{
			System.Diagnostics.Trace.Assert(tag != null);
			name = tag.Name;
			lineNumber = tag.LinePragma.LineNumber;
            CodeMemberProperty pro = tag as CodeMemberProperty;
			isProperty = pro != null;
			if (isProperty) {
				returnType = pro.Type.BaseType;
			} else {
				returnType = (tag as CodeMemberField).Type.BaseType;
			}
		}
コード例 #28
0
		public void Constructor2 ()
		{
			CodeTypeMember tm1 = new CodeTypeMember ();
			CodeTypeMember tm2 = new CodeTypeMember ();

			CodeTypeMemberCollection c = new CodeTypeMemberCollection ();
			c.Add (tm1);
			c.Add (tm2);

			CodeTypeMemberCollection coll = new CodeTypeMemberCollection (c);
			Assert.AreEqual (2, coll.Count, "#1");
			Assert.AreEqual (0, coll.IndexOf (tm1), "#2");
			Assert.AreEqual (1, coll.IndexOf (tm2), "#3");
		}
コード例 #29
0
ファイル: CodeTypeMemberCas.cs プロジェクト: Profit0004/mono
		public void Constructor0_Deny_Unrestricted ()
		{
			CodeTypeMember ctm = new CodeTypeMember ();
			Assert.AreEqual (MemberAttributes.Private | MemberAttributes.Final, ctm.Attributes, "Attributes");
			ctm.Attributes = MemberAttributes.Public;
			Assert.AreEqual (0, ctm.Comments.Count, "Comments");
			Assert.AreEqual (0, ctm.CustomAttributes.Count, "CustomAttributes");
			ctm.CustomAttributes = new CodeAttributeDeclarationCollection ();
			Assert.IsNull (ctm.LinePragma, "LinePragma");
			ctm.LinePragma = new CodeLinePragma (String.Empty, Int32.MaxValue);
			Assert.AreEqual (String.Empty, ctm.Name, "Name");
			ctm.Name = "mono";
			Assert.AreEqual (0, ctm.StartDirectives.Count, "StartDirectives");
			Assert.AreEqual (0, ctm.EndDirectives.Count, "EndDirectives");
		}
コード例 #30
0
ファイル: MemberBuildContext.cs プロジェクト: Jedzia/NStub
 /// <summary>
 /// Initializes a new instance of the <see cref="MemberBuildContext"/> class.
 /// </summary>
 /// <param name="codeNamespace">The code namespace of the test.</param>
 /// <param name="testClassDeclaration">The test class declaration.( early testObject ).</param>
 /// <param name="typeMember">The current type to create a test method for.</param>
 /// <param name="buildData">The additional build data lookup.</param>
 /// <param name="setUpTearDownContext">Contains data specific to SetUp and TearDown test-methods.</param>
 /// <param name="baseKey">The base string of the <see cref="MemberBuildContextBase.TestKey"/>. Is amended by the
 /// <paramref name="codeNamespace"/> identifier, normalized and fixed by a <see cref="KeynameFixer"/>.</param>
 public MemberBuildContext(
     CodeNamespace codeNamespace,
     CodeTypeDeclaration testClassDeclaration,
     CodeTypeMember typeMember,
     BuildDataDictionary buildData,
     ISetupAndTearDownContext setUpTearDownContext,
     string baseKey)
     : base(codeNamespace,
         testClassDeclaration,
         typeMember,
         buildData,
         setUpTearDownContext,
         baseKey)
 {
 }
コード例 #31
0
 /// <devdoc>
 /// <para>Inserts a <see cref='System.CodeDom.CodeTypeMember'/> into the <see cref='System.CodeDom.CodeTypeMemberCollection'/> at the specified index.</para>
 /// </devdoc>
 public void Insert(int index, CodeTypeMember value)
 {
     List.Insert(index, value);
 }
コード例 #32
0
 /// <devdoc>
 ///    <para>Returns the index of a <see cref='System.CodeDom.CodeTypeMember'/> in
 ///       the <see cref='System.CodeDom.CodeTypeMemberCollection'/> .</para>
 /// </devdoc>
 public int IndexOf(CodeTypeMember value)
 {
     return(List.IndexOf(value));
 }
コード例 #33
0
 /// <devdoc>
 /// <para>Gets a value indicating whether the
 ///    <see cref='System.CodeDom.CodeTypeMemberCollection'/> contains the specified <see cref='System.CodeDom.CodeTypeMember'/>.</para>
 /// </devdoc>
 public bool Contains(CodeTypeMember value)
 {
     return(List.Contains(value));
 }
コード例 #34
0
 public int Add(CodeTypeMember value) => List.Add(value);
コード例 #35
0
 /// <devdoc>
 ///    <para> Removes a specific <see cref='System.CodeDom.CodeTypeMember'/> from the
 ///    <see cref='System.CodeDom.CodeTypeMemberCollection'/> .</para>
 /// </devdoc>
 public void Remove(CodeTypeMember value)
 {
     List.Remove(value);
 }
コード例 #36
0
 public int IndexOf(CodeTypeMember value) => List.IndexOf(value);
コード例 #37
0
 public bool Contains(CodeTypeMember value) => List.Contains(value);
コード例 #38
0
 /// <devdoc>
 ///    <para>Adds a <see cref='System.CodeDom.CodeTypeMember'/> with the specified value to the
 ///    <see cref='System.CodeDom.CodeTypeMemberCollection'/> .</para>
 /// </devdoc>
 public int Add(CodeTypeMember value)
 {
     return(List.Add(value));
 }