当前位置: 首页>>代码示例>>C#>>正文


C# CodeDom.CodeSnippetTypeMember类代码示例

本文整理汇总了C#中System.CodeDom.CodeSnippetTypeMember的典型用法代码示例。如果您正苦于以下问题:C# CodeSnippetTypeMember类的具体用法?C# CodeSnippetTypeMember怎么用?C# CodeSnippetTypeMember使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CodeSnippetTypeMember类属于System.CodeDom命名空间,在下文中一共展示了CodeSnippetTypeMember类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CompileDirectives

		//construct, given the code provider being used.
		public CompileDirectives(CodeDomProvider codeProvider)
		{
			this.codeProvider = codeProvider;

			if (codeProvider.FileExtension == "cs")
			{
				readonlySnip = new CodeSnippetTypeMember("readonly ");
				isCSharp = true;
			}
			if (codeProvider.FileExtension == "vb")
				readonlySnip = new CodeSnippetTypeMember("ReadOnly ");


			//try and load the directives from the user config.
			try
			{
				//GenericType
				string defaultDiretive = Properties.Settings.Default.DefaultCompilerDirectives.Trim();
				if (defaultDiretive.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).Length == 3)
					directives = defaultDiretive.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

				System.Reflection.PropertyInfo[] properties = Properties.Settings.Default.GetType().GetProperties();

				foreach (System.Reflection.PropertyInfo property in properties)
				{
					if (property.PropertyType == typeof(string) && property.Name.EndsWith("CompilerDirectives", StringComparison.InvariantCultureIgnoreCase))
					{
						string directive = property.GetValue(Properties.Settings.Default, null) as string;

						if (directive != null)
						{
							string[] lines = directive.Trim().Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
							if (lines.Length == 4)
							{
								if (("*." + codeProvider.FileExtension).Equals(lines[0].Trim(), StringComparison.InvariantCultureIgnoreCase))
								{
									for (int i = 0; i < 3; i++)
									{
										directives[i] = lines[i + 1];
									}
								}
							}
						}
					}
				}

				for (int i = 0; i < directives.Length; i++)
				{
					directives[i] = directives[i].Trim();
				}

				if (directives[0].Contains("{0}") == false)
					throw new Exception("Could not find {0} in directive 0");

			}
			catch (Exception e)
			{
				throw new Exception("Error in user.config file", e);
			}
		}
开发者ID:shadarath,项目名称:Wirtualna-rzeczywistosc,代码行数:61,代码来源:Directives.cs

示例2: TypescriptSnippetTypeMember

 public TypescriptSnippetTypeMember(
     CodeSnippetTypeMember member,
     CodeGeneratorOptions options)
 {
     _member = member;
     _options = options;
 }
开发者ID:s2quake,项目名称:TypescriptCodeDom,代码行数:7,代码来源:TypescriptSnippetTypeMember.cs

示例3: ProcessGeneratedCode

        public override void ProcessGeneratedCode(CodeCompileUnit codeCompileUnit,
                                                  CodeNamespace generatedNamespace,
                                                  CodeTypeDeclaration generatedClass,
                                                  CodeMemberMethod executeMethod)
        {
            base.ProcessGeneratedCode(codeCompileUnit, generatedNamespace, generatedClass, executeMethod);


            // Create the Href wrapper
            CodeTypeMember hrefMethod = new CodeSnippetTypeMember(@"
                // Resolve package relative syntax
                // Also, if it comes from a static embedded resource, change the path accordingly
                public override string Href(string virtualPath, params object[] pathParts) {
                    virtualPath = ApplicationPart.ProcessVirtualPath(GetType().Assembly, VirtualPath, virtualPath);
                    return base.Href(virtualPath, pathParts);
                }");

            generatedClass.Members.Add(hrefMethod);

            Debug.Assert(generatedClass.Name.Length > 0);
            if (!(Char.IsLetter(generatedClass.Name[0]) || generatedClass.Name[0] == '_'))
            {
                generatedClass.Name = '_' + generatedClass.Name;
            }

            // If the generatedClass starts with an underscore, add a ClsCompliant(false) attribute.
            if (generatedClass.Name[0] == '_')
            {
                generatedClass.CustomAttributes.Add(new CodeAttributeDeclaration(typeof(CLSCompliantAttribute).FullName,
                                                        new CodeAttributeArgument(new CodePrimitiveExpression(false))));
            }
        }
开发者ID:HansS,项目名称:ServiceStack,代码行数:32,代码来源:WebPagesTransformer.cs

示例4: GenerateCode

        public CodeCompileUnit GenerateCode(string typeName, string codeBody,
            StringCollection imports,
            string prefix)
        {
            var compileUnit = new CodeCompileUnit();

            var typeDecl = new CodeTypeDeclaration(typeName);
            typeDecl.IsClass = true;
            typeDecl.TypeAttributes = TypeAttributes.Public;

            // create constructor
            var constructMember = new CodeConstructor {Attributes = MemberAttributes.Public};
            typeDecl.Members.Add(constructMember);

            // pump in the user specified code as a snippet
            var literalMember =
                new CodeSnippetTypeMember(codeBody);
            typeDecl.Members.Add(literalMember);

            var nspace = new CodeNamespace();

            ////Add default imports
            //foreach (string nameSpace in ScriptExecuter._namespaces)
            //{
            //    nspace.Imports.Add(new CodeNamespaceImport(nameSpace));
            //}
            foreach (string nameSpace in imports)
            {
                nspace.Imports.Add(new CodeNamespaceImport(nameSpace));
            }
            compileUnit.Namespaces.Add(nspace);
            nspace.Types.Add(typeDecl);

            return compileUnit;
        }
开发者ID:hiriumi,项目名称:EasyReporting,代码行数:35,代码来源:CompilerInfo.cs

示例5: GenerateActionPartialMethod

        /// <summary>
        /// Generates the partial method for an action.
        /// </summary>
        /// <param name = "message">The message.</param>
        /// <param name = "argumentType">Type of the argument.</param>
        /// <returns>The type member.</returns>
        protected override CodeTypeMember GenerateActionPartialMethod(string message, IType argumentType)
        {
            String selector = message;
            String name = GenerateMethodName (selector);

            // Partial method are only possible by using a snippet of code as CodeDom does not handle them
            CodeSnippetTypeMember method = new CodeSnippetTypeMember ("partial void " + name + "(" + argumentType.Name + " sender);" + Environment.NewLine);

            return method;
        }
开发者ID:Monobjc,项目名称:monobjc-monodevelop,代码行数:16,代码来源:CSharpCodeBehindGenerator.cs

示例6: GenerateActionPartialMethod

        /// <summary>
        ///   Generates the partial method for an action.
        /// </summary>
        /// <param name = "message">The message.</param>
        /// <param name = "argumentType">Type of the argument.</param>
        /// <returns>The type member.</returns>
        protected override CodeTypeMember GenerateActionPartialMethod(string message, IType argumentType)
        {
            String selector = message;
            String name = GenerateMethodName (selector);

            // Partial method are only possible by using a snippet of code as CodeDom does not handle them
            String content = String.Format ("Partial Private Sub {0}({1} sender){2}End Sub{2}", name, argumentType.Name, Environment.NewLine);
            CodeSnippetTypeMember method = new CodeSnippetTypeMember (content);

            return method;
        }
开发者ID:Monobjc,项目名称:monobjc-monodevelop,代码行数:17,代码来源:VBNetCodeBehindGenerator.cs

示例7: AddScriptBlock

        public void AddScriptBlock(string source, string uriString, int lineNumber, Location end) {
            CodeSnippetTypeMember scriptSnippet = new CodeSnippetTypeMember(source);
            string fileName = SourceLineInfo.GetFileName(uriString);
            if (lineNumber > 0) {
                scriptSnippet.LinePragma = new CodeLinePragma(fileName, lineNumber);
                scriptUris[fileName] = uriString;
            }
            typeDecl.Members.Add(scriptSnippet);

            this.endUri = uriString;
            this.endLoc = end;
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:12,代码来源:Scripts.cs

示例8: AddScriptBlock

        public void AddScriptBlock(string source, string uriString, int lineNumber, int endLine, int endPos) {
            CodeSnippetTypeMember scriptSnippet = new CodeSnippetTypeMember(source);
            string fileName = SourceLineInfo.GetFileName(uriString);
            if (lineNumber > 0) {
                scriptSnippet.LinePragma = new CodeLinePragma(fileName, lineNumber);
                scriptFiles.Add(fileName);
            }
            typeDecl.Members.Add(scriptSnippet);

            this.endFileName  = fileName;
            this.endLine      = endLine;
            this.endPos       = endPos;
        }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:13,代码来源:scripts.cs

示例9: CreatePropertyCode

        public static CodeTypeMember CreatePropertyCode(this SAPDataParameter p)
        {
            CodeSnippetTypeMember snippet = new CodeSnippetTypeMember();

            if (p.Comment != null)
            {
                snippet.Comments.Add(new CodeCommentStatement(p.Comment, true));
            }

            snippet.Text = string.Format("public {0} {1} {{get;set;}}", p.Type.ToString(), p.Name);

            return snippet;
        }
开发者ID:xneo123,项目名称:SAPGuiAutomationLib,代码行数:13,代码来源:SAPDataParameter.cs

示例10: CraeteCodeInterfaceDeclaration

		private static CodeTypeDeclaration CraeteCodeInterfaceDeclaration(XpidlInterface xpidlInterface, out CodeTypeDeclaration codeConstClassDeclaration)
		{
			// Create interface declaration
			var codeInterfaceDeclaration =
				new CodeTypeDeclaration(xpidlInterface.Name)
				{
					IsInterface = true,
					TypeAttributes = TypeAttributes.Interface | TypeAttributes.NotPublic
				};

			// Set base interface (except of nsISupports)
			if (!String.IsNullOrEmpty(xpidlInterface.BaseName) && !String.Equals(xpidlInterface.BaseName, XpidlType.nsISupports))
			{
				codeInterfaceDeclaration.BaseTypes.Add(xpidlInterface.BaseName);

				var baseInterfaceMembers = new CodeSnippetTypeMember();
				baseInterfaceMembers.Comments.Add(
					new CodeCommentStatement(new CodeComment(String.Format("TODO: declare {0} members here", xpidlInterface.BaseName), false)));

				baseInterfaceMembers.StartDirectives.Add(
					new CodeRegionDirective(CodeRegionMode.Start, String.Format("{0} Members", xpidlInterface.BaseName)));
				baseInterfaceMembers.EndDirectives.Add(
					new CodeRegionDirective(CodeRegionMode.End, null));

				codeInterfaceDeclaration.Members.Add(baseInterfaceMembers);
			}

			// Add [ComImport] attribute
			var comImportAttributeDeclaration =
				new CodeAttributeDeclaration(
					new CodeTypeReference(typeof(ComImportAttribute)));
			codeInterfaceDeclaration.CustomAttributes.Add(comImportAttributeDeclaration);

			// Add [Guid] attribute
			var guidAttributeDeclaration =
				new CodeAttributeDeclaration(
					new CodeTypeReference(typeof(GuidAttribute)),
					new CodeAttributeArgument(new CodePrimitiveExpression(xpidlInterface.Uuid.ToString())));
			codeInterfaceDeclaration.CustomAttributes.Add(guidAttributeDeclaration);

			// Add [InterfaceType] attribute
			var interfaceTypeAttributeDeclaration =
				new CodeAttributeDeclaration(
					new CodeTypeReference(typeof(InterfaceTypeAttribute)),
					new CodeAttributeArgument(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(ComInterfaceType)), ComInterfaceType.InterfaceIsIUnknown.ToString())));
			codeInterfaceDeclaration.CustomAttributes.Add(interfaceTypeAttributeDeclaration);

			// Create interface members and get separate class for interface constants
			codeConstClassDeclaration = BuildCodeInterfaceDeclaration(codeInterfaceDeclaration, xpidlInterface);
			return codeInterfaceDeclaration;
		}
开发者ID:Happy-Ferret,项目名称:dotgecko,代码行数:51,代码来源:CodeDomXpidlFormatter.Transform.cs

示例11: ObjectFactoryCodeDomTreeGenerator

 internal ObjectFactoryCodeDomTreeGenerator(string outputAssemblyName)
 {
     CodeConstructor constructor;
     this._codeCompileUnit = new System.CodeDom.CodeCompileUnit();
     CodeNamespace namespace2 = new CodeNamespace("__ASP");
     this._codeCompileUnit.Namespaces.Add(namespace2);
     string name = "FastObjectFactory_" + Util.MakeValidTypeNameFromString(outputAssemblyName).ToLower(CultureInfo.InvariantCulture);
     this._factoryClass = new CodeTypeDeclaration(name);
     this._factoryClass.TypeAttributes &= ~TypeAttributes.Public;
     CodeSnippetTypeMember member = new CodeSnippetTypeMember(string.Empty) {
         LinePragma = new CodeLinePragma(@"c:\\dummy.txt", 1)
     };
     this._factoryClass.Members.Add(member);
     constructor = new CodeConstructor {
         Attributes = constructor.Attributes | MemberAttributes.Private
     };
     this._factoryClass.Members.Add(constructor);
     namespace2.Types.Add(this._factoryClass);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:19,代码来源:ObjectFactoryCodeDomTreeGenerator.cs

示例12: Constructor0

		public void Constructor0 ()
		{
			CodeSnippetTypeMember cstm = new CodeSnippetTypeMember ();

			Assert.AreEqual (MemberAttributes.Private | MemberAttributes.Final,
				cstm.Attributes, "#1");

			Assert.IsNotNull (cstm.Comments, "#2");
			Assert.AreEqual (0, cstm.Comments.Count, "#3");

			Assert.IsNotNull (cstm.CustomAttributes, "#4");
			Assert.AreEqual (0, cstm.CustomAttributes.Count, "#5");

#if NET_2_0
			Assert.IsNotNull (cstm.StartDirectives, "#6");
			Assert.AreEqual (0, cstm.StartDirectives.Count, "#7");

			Assert.IsNotNull (cstm.EndDirectives, "#8");
			Assert.AreEqual (0, cstm.EndDirectives.Count, "#9");
#endif

			Assert.IsNotNull (cstm.Text, "#10");
			Assert.AreEqual (string.Empty, cstm.Text, "#11");

			Assert.IsNull (cstm.LinePragma, "#12");

			Assert.IsNotNull (cstm.Name, "#13");
			Assert.AreEqual (string.Empty, cstm.Name, "#14");

			Assert.IsNotNull (cstm.UserData, "#15");
			Assert.AreEqual (typeof(ListDictionary), cstm.UserData.GetType (), "#16");
			Assert.AreEqual (0, cstm.UserData.Count, "#17");

			cstm.Name = null;
			Assert.IsNotNull (cstm.Name, "#18");
			Assert.AreEqual (string.Empty, cstm.Name, "#19");

			CodeLinePragma clp = new CodeLinePragma ("mono", 10);
			cstm.LinePragma = clp;
			Assert.IsNotNull (cstm.LinePragma, "#20");
			Assert.AreSame (clp, cstm.LinePragma, "#21");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:42,代码来源:CodeSnippetTypeMemberTest.cs

示例13: ObjectFactoryCodeDomTreeGenerator

    internal ObjectFactoryCodeDomTreeGenerator(string outputAssemblyName) {

        _codeCompileUnit = new CodeCompileUnit();

        CodeNamespace sourceDataNamespace = new CodeNamespace(
            BaseCodeDomTreeGenerator.internalAspNamespace);
        _codeCompileUnit.Namespaces.Add(sourceDataNamespace);

        // Make the class name vary based on the assembly (VSWhidbey 363214)
        string factoryClassName = factoryClassNameBase +
            Util.MakeValidTypeNameFromString(outputAssemblyName).ToLower(CultureInfo.InvariantCulture);

        // Create a single class, in which a method will be added for each
        // type that needs to be fast created in this assembly
        _factoryClass = new CodeTypeDeclaration(factoryClassName);

        // Make the class internal (VSWhidbey 363214)
        _factoryClass.TypeAttributes &= ~TypeAttributes.Public;

        // We generate a dummy line pragma, just so it will end with a '#line hidden'
        // and prevent the following generated code from ever being treated as user
        // code.  We need to use this hack because CodeDOM doesn't allow simply generating
        // a '#line hidden'. (VSWhidbey 199384)
        CodeSnippetTypeMember dummySnippet = new CodeSnippetTypeMember(String.Empty);
#if !PLATFORM_UNIX /// Unix file system
        // CORIOLISTODO: Unix file system
        dummySnippet.LinePragma = new CodeLinePragma(@"c:\\dummy.txt", 1);
#else // !PLATFORM_UNIX
        dummySnippet.LinePragma = new CodeLinePragma(@"/dummy.txt", 1);
#endif // !PLATFORM_UNIX
        _factoryClass.Members.Add(dummySnippet);

        // Add a private default ctor to make the class non-instantiatable (VSWhidbey 340829)
        CodeConstructor ctor = new CodeConstructor();
        ctor.Attributes |= MemberAttributes.Private;
        _factoryClass.Members.Add(ctor);

        sourceDataNamespace.Types.Add(_factoryClass);
    }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:39,代码来源:ObjectFactoryCodeDomTreeGenerator.cs

示例14: AddCreateObjectReferenceMethods

        protected override void AddCreateObjectReferenceMethods(GrainInterfaceData grainInterfaceData, CodeTypeDeclaration factoryClass)
        {
            var fieldImpl = @"
        private static global::Orleans.CodeGeneration.IGrainMethodInvoker methodInvoker;";
            var invokerField = new CodeSnippetTypeMember(fieldImpl);
            factoryClass.Members.Add(invokerField);

            var methodImpl = String.Format(@"
        public async static System.Threading.Tasks.Task<{0}> CreateObjectReference({0} obj)
        {{
            if (methodInvoker == null) methodInvoker = new {2}();
            return {1}.Cast(await global::Orleans.Runtime.GrainReference.CreateObjectReference(obj, methodInvoker));
        }}", grainInterfaceData.TypeName, grainInterfaceData.FactoryClassName, grainInterfaceData.InvokerClassName);
            var createObjectReferenceMethod = new CodeSnippetTypeMember(methodImpl);
            factoryClass.Members.Add(createObjectReferenceMethod);

            methodImpl = String.Format(@"
        public static System.Threading.Tasks.Task DeleteObjectReference({0} reference)
        {{
            return global::Orleans.Runtime.GrainReference.DeleteObjectReference(reference);
        }}",
            grainInterfaceData.TypeName);
            var deleteObjectReferenceMethod = new CodeSnippetTypeMember(methodImpl);
            factoryClass.Members.Add(deleteObjectReferenceMethod);
        }
开发者ID:stanroze,项目名称:orleans,代码行数:25,代码来源:CSharpCodeGenerator.cs

示例15: GenerateCode

            public CodeCompileUnit GenerateCode(string typeName, string codeBody,
                                       StringCollection imports,
                                       string prefix)
            {
                CodeCompileUnit compileUnit = new CodeCompileUnit();

                CodeTypeDeclaration typeDecl = new CodeTypeDeclaration(typeName);
                typeDecl.IsClass = true;
                typeDecl.TypeAttributes = TypeAttributes.Public;

                // create constructor
                CodeConstructor constructMember = new CodeConstructor();
                constructMember.Attributes = MemberAttributes.Public;
                constructMember.Parameters.Add(new CodeParameterDeclarationExpression("NAnt.Core.Project", "project"));
                constructMember.Parameters.Add(new CodeParameterDeclarationExpression("NAnt.Core.PropertyDictionary", "propDict"));

                constructMember.BaseConstructorArgs.Add(new CodeVariableReferenceExpression("project"));
                constructMember.BaseConstructorArgs.Add(new CodeVariableReferenceExpression ("propDict"));
                typeDecl.Members.Add(constructMember);

                typeDecl.BaseTypes.Add(typeof(FunctionSetBase));

                // add FunctionSet attribute
                CodeAttributeDeclaration attrDecl = new CodeAttributeDeclaration("FunctionSet");
                attrDecl.Arguments.Add(new CodeAttributeArgument(
                    new CodeVariableReferenceExpression("\"" + prefix + "\"")));
                attrDecl.Arguments.Add(new CodeAttributeArgument(
                    new CodeVariableReferenceExpression("\"" + prefix + "\"")));

                typeDecl.CustomAttributes.Add(attrDecl);

                // pump in the user specified code as a snippet
                CodeSnippetTypeMember literalMember =
                    new CodeSnippetTypeMember(codeBody);
                typeDecl.Members.Add( literalMember );

                CodeNamespace nspace = new CodeNamespace();

                //Add default imports
                foreach (string nameSpace in ScriptTask._defaultNamespaces) {
                    nspace.Imports.Add(new CodeNamespaceImport(nameSpace));
                }
                foreach (string nameSpace in imports) {
                    nspace.Imports.Add(new CodeNamespaceImport(nameSpace));
                }
                compileUnit.Namespaces.Add( nspace );
                nspace.Types.Add(typeDecl);

                return compileUnit;
            }
开发者ID:smaclell,项目名称:NAnt,代码行数:50,代码来源:ScriptTask.cs


注:本文中的System.CodeDom.CodeSnippetTypeMember类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。