本文整理汇总了C#中System.CodeDom.CodeMemberMethod类的典型用法代码示例。如果您正苦于以下问题:C# CodeMemberMethod类的具体用法?C# CodeMemberMethod怎么用?C# CodeMemberMethod使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CodeMemberMethod类属于System.CodeDom命名空间,在下文中一共展示了CodeMemberMethod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Generate
/// <summary>
/// Generates control fields
/// </summary>
/// <param name="source">The source.</param>
/// <param name="classType">Type of the class.</param>
/// <param name="method">The initialize method.</param>
/// <param name="generateField">if set to <c>true</c> [generate field].</param>
/// <returns></returns>
public override CodeExpression Generate(DependencyObject source, CodeTypeDeclaration classType, CodeMemberMethod method, bool generateField)
{
CodeExpression fieldReference = new CodeThisReferenceExpression();
CodeComHelper.GenerateBrushField(method, fieldReference, source, Control.BackgroundProperty);
CodeComHelper.GenerateBrushField(method, fieldReference, source, Control.BorderBrushProperty);
CodeComHelper.GenerateThicknessField(method, fieldReference, source, Control.BorderThicknessProperty);
CodeComHelper.GenerateThicknessField(method, fieldReference, source, Control.PaddingProperty);
CodeComHelper.GenerateBrushField(method, fieldReference, source, Control.ForegroundProperty);
CodeComHelper.GenerateField<bool>(method, fieldReference, source, UIRoot.IsTabNavigationEnabledProperty);
CodeComHelper.GenerateColorField(method, fieldReference, source, UIRoot.MessageBoxOverlayProperty);
CodeComHelper.GenerateTemplateStyleField(classType, method, fieldReference, source, FrameworkElement.StyleProperty);
Control control = source as Control;
if (!CodeComHelper.IsDefaultValue(source, Control.FontFamilyProperty) ||
!CodeComHelper.IsDefaultValue(source, Control.FontSizeProperty) ||
!CodeComHelper.IsDefaultValue(source, Control.FontStyleProperty) ||
!CodeComHelper.IsDefaultValue(source, Control.FontWeightProperty))
{
FontGenerator.Instance.AddFont(control.FontFamily, control.FontSize, control.FontStyle, control.FontWeight, method);
}
CodeComHelper.GenerateFontFamilyField(method, fieldReference, source, Control.FontFamilyProperty);
CodeComHelper.GenerateFieldDoubleToFloat(method, fieldReference, source, Control.FontSizeProperty);
CodeComHelper.GenerateFontStyleField(method, fieldReference, source, Control.FontStyleProperty, Control.FontWeightProperty);
return fieldReference;
}
示例2: ProcessGeneratedCode
public override void ProcessGeneratedCode(CodeCompileUnit codeCompileUnit, CodeTypeDeclaration baseType, CodeTypeDeclaration derivedType, CodeMemberMethod buildMethod, CodeMemberMethod dataBindingMethod)
{
if (!String.IsNullOrWhiteSpace(Inherits))
{
derivedType.BaseTypes[0] = new CodeTypeReference(Inherits);
}
}
示例3: AddCustomAttributesToMethod
private void AddCustomAttributesToMethod(CodeMemberMethod dbMethod)
{
if (base.methodSource.EnableWebMethods)
{
CodeAttributeDeclaration declaration = new CodeAttributeDeclaration("System.Web.Services.WebMethod");
declaration.Arguments.Add(new CodeAttributeArgument("Description", CodeGenHelper.Str(base.methodSource.WebMethodDescription)));
dbMethod.CustomAttributes.Add(declaration);
}
DataObjectMethodType select = DataObjectMethodType.Select;
if (base.methodSource.CommandOperation == CommandOperation.Update)
{
select = DataObjectMethodType.Update;
}
else if (base.methodSource.CommandOperation == CommandOperation.Delete)
{
select = DataObjectMethodType.Delete;
}
else if (base.methodSource.CommandOperation == CommandOperation.Insert)
{
select = DataObjectMethodType.Insert;
}
if (select != DataObjectMethodType.Select)
{
dbMethod.CustomAttributes.Add(new CodeAttributeDeclaration(CodeGenHelper.GlobalType(typeof(DataObjectMethodAttribute)), new CodeAttributeArgument[] { new CodeAttributeArgument(CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DataObjectMethodType)), select.ToString())), new CodeAttributeArgument(CodeGenHelper.Primitive(false)) }));
}
}
示例4: PostProcessGeneratedCodeAddsApplicationInstanceProperty
public void PostProcessGeneratedCodeAddsApplicationInstanceProperty() {
const string expectedPropertyCode = @"
protected Foo.Bar ApplicationInstance {
get {
return ((Foo.Bar)(Context.ApplicationInstance));
}
}
";
// Arrange
CodeCompileUnit generatedCode = new CodeCompileUnit();
CodeNamespace generatedNamespace = new CodeNamespace();
CodeTypeDeclaration generatedClass = new CodeTypeDeclaration();
CodeMemberMethod executeMethod = new CodeMemberMethod();
WebPageRazorHost host = new WebPageRazorHost("Foo.cshtml") {
GlobalAsaxTypeName = "Foo.Bar"
};
// Act
host.PostProcessGeneratedCode(generatedCode, generatedNamespace, generatedClass, executeMethod);
// Assert
CodeMemberProperty property = generatedClass.Members[0] as CodeMemberProperty;
Assert.IsNotNull(property);
CSharpCodeProvider provider = new CSharpCodeProvider();
StringBuilder builder = new StringBuilder();
using(StringWriter writer = new StringWriter(builder)) {
provider.GenerateCodeFromMember(property, writer, new CodeDom.Compiler.CodeGeneratorOptions());
}
Assert.AreEqual(expectedPropertyCode, builder.ToString());
}
示例5: SuggestedHandlerCompletionData
public SuggestedHandlerCompletionData (MonoDevelop.Projects.Project project, CodeMemberMethod methodInfo, INamedTypeSymbol codeBehindClass, Location codeBehindClassLocation)
{
this.project = project;
this.methodInfo = methodInfo;
this.codeBehindClass = codeBehindClass;
this.codeBehindClassLocation = codeBehindClassLocation;
}
示例6: WriteFunctionDefinition
protected override void WriteFunctionDefinition(CodeMemberMethod func) {
Writer.Write("def ");
Writer.Write(func.Name);
Writer.Write("(");
for (int i = 0; i < func.Parameters.Count; ++i) {
if (i != 0) {
Writer.Write(",");
}
Writer.Write(func.Parameters[i].Name);
}
Writer.Write("):\n");
int baseIndent = _indents.Peek();
_generatedIndent += 4;
foreach (CodeStatement stmt in func.Statements) {
WriteStatement(stmt);
}
_generatedIndent -= 4;
while (_indents.Peek() > baseIndent) {
_indents.Pop();
}
}
示例7: CodeLocalVariableBinder
/// <summary>
/// Initializes a new instance of the <see cref="CodeLocalVariableBinder"/> class
/// with a local variable declaration.
/// </summary>
/// <param name="method">The method to add a <see cref="CodeTypeReference"/> to.</param>
/// <param name="variableDeclaration">The variable declaration to add.</param>
internal CodeLocalVariableBinder(CodeMemberMethod method, CodeVariableDeclarationStatement variableDeclaration)
{
Guard.NotNull(() => method, method);
Guard.NotNull(() => variableDeclaration, variableDeclaration);
this.method = method;
this.variableDeclaration = variableDeclaration;
}
示例8: AddMethods
internal void AddMethods(CodeTypeDeclaration dataSourceClass)
{
this.AddSchemaSerializationModeMembers(dataSourceClass);
this.initExpressionsMethod = this.InitExpressionsMethod();
dataSourceClass.Members.Add(this.PublicConstructor());
dataSourceClass.Members.Add(this.DeserializingConstructor());
dataSourceClass.Members.Add(this.InitializeDerivedDataSet());
dataSourceClass.Members.Add(this.CloneMethod(this.initExpressionsMethod));
dataSourceClass.Members.Add(this.ShouldSerializeTablesMethod());
dataSourceClass.Members.Add(this.ShouldSerializeRelationsMethod());
dataSourceClass.Members.Add(this.ReadXmlSerializableMethod());
dataSourceClass.Members.Add(this.GetSchemaSerializableMethod());
dataSourceClass.Members.Add(this.InitVarsParamLess());
CodeMemberMethod initClassMethod = null;
CodeMemberMethod initVarsMethod = null;
this.InitClassAndInitVarsMethods(out initClassMethod, out initVarsMethod);
dataSourceClass.Members.Add(initVarsMethod);
dataSourceClass.Members.Add(initClassMethod);
this.AddShouldSerializeSingleTableMethods(dataSourceClass);
dataSourceClass.Members.Add(this.SchemaChangedMethod());
dataSourceClass.Members.Add(this.GetTypedDataSetSchema());
dataSourceClass.Members.Add(this.TablesProperty());
dataSourceClass.Members.Add(this.RelationsProperty());
if (this.initExpressionsMethod != null)
{
dataSourceClass.Members.Add(this.initExpressionsMethod);
}
}
示例9: RegisterClasspath
private void RegisterClasspath(CodeMemberMethod composeMethod, XmlElement classpathElement, IList assemblies)
{
XmlNodeList children = classpathElement.ChildNodes;
for (int i = 0; i < children.Count ; i++)
{
if (children[i] is XmlElement)
{
XmlElement childElement = (XmlElement) children[i];
string fileName = childElement.GetAttribute(FILE);
string urlSpec = childElement.GetAttribute(URL);
UriBuilder url = null;
if (urlSpec != null && urlSpec.Length > 0)
{
url = new UriBuilder(urlSpec);
assemblies.Add(url.ToString());
}
else
{
if (!File.Exists(fileName))
{
throw new IOException(Environment.CurrentDirectory + Path.DirectorySeparatorChar + fileName + " doesn't exist");
}
assemblies.Add(fileName);
}
}
}
}
示例10: ExampleDependencyInjectionLogic
public static void ExampleDependencyInjectionLogic(CodeMemberMethod buildMethod)
{
// Non file based controls are different than file based controls.
// Non file based controls are instantiated with "new" inside of a method and returned.
// They are declared in the first statement.
CodeVariableDeclarationStatement declaration = (CodeVariableDeclarationStatement)buildMethod.Statements[0];
// Use the type of the declaration to get the type of the control.
Type type = Type.GetType(declaration.Type.BaseType);
// Standard reflection to get all of the properties. You could also look for fields.
PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
foreach(PropertyInfo property in properties) {
// See if the property has the specific attribute we care about.
object[] injectDeps = property.GetCustomAttributes(typeof(InjectDepAttribute), true);
if(injectDeps.Length == 1) {
// Create the code dom to perform the injection.
// In this example, set the property to the literal the attribute was given.
CodeStatement setProperty = new CodeAssignStatement(
new CodePropertyReferenceExpression(new CodeVariableReferenceExpression(declaration.Name), property.Name),
new CodePrimitiveExpression((injectDeps[0] as InjectDepAttribute).Name + " (the builder method this is set in is '" + buildMethod.Name + "')")
);
// Add the statement to the list of statements that make up the builder method.
// The last statement is the return statement that returns the control.
// So we insert out injection statement(s) right before it.
buildMethod.Statements.Insert(buildMethod.Statements.Count - 1, setProperty);
}
}
}
示例11: ProcessGeneratedCode
public override void ProcessGeneratedCode(
CodeCompileUnit codeCompileUnit, CodeTypeDeclaration baseType,
CodeTypeDeclaration derivedType, CodeMemberMethod buildMethod, CodeMemberMethod dataBindingMethod)
{
ExampleDependencyInjectionLogic(buildMethod);
base.ProcessGeneratedCode(codeCompileUnit, baseType, derivedType, buildMethod, dataBindingMethod);
}
示例12: BuildAddContentPlaceHolderNames
private void BuildAddContentPlaceHolderNames(CodeMemberMethod method, string placeHolderID) {
CodePropertyReferenceExpression propertyExpr = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "ContentPlaceHolders");
CodeExpressionStatement stmt = new CodeExpressionStatement();
stmt.Expression = new CodeMethodInvokeExpression(propertyExpr, "Add", new CodePrimitiveExpression(placeHolderID.ToLower(CultureInfo.InvariantCulture)));
method.Statements.Add(stmt);
}
示例13: GenerateWidgetCode
static void GenerateWidgetCode(SteticCompilationUnit globalUnit, CodeNamespace globalNs, GenerationOptions options, List<SteticCompilationUnit> units, Gtk.Widget w, ArrayList warnings)
{
// Generate the build method
CodeTypeDeclaration type = CreatePartialClass (globalUnit, units, options, w.Name);
CodeMemberMethod met = new CodeMemberMethod ();
met.Name = "Build";
type.Members.Add (met);
met.ReturnType = new CodeTypeReference (typeof(void));
met.Attributes = MemberAttributes.Family;
if (options.GenerateEmptyBuildMethod) {
GenerateWrapperFields (type, Wrapper.Widget.Lookup (w));
return;
}
met.Statements.Add (
new CodeMethodInvokeExpression (
new CodeTypeReferenceExpression (globalNs.Name + ".Gui"),
"Initialize",
new CodeThisReferenceExpression ()
)
);
Stetic.Wrapper.Widget wwidget = Stetic.Wrapper.Widget.Lookup (w);
if (wwidget.GeneratePublic)
type.TypeAttributes = TypeAttributes.Public;
else
type.TypeAttributes = TypeAttributes.NotPublic;
Stetic.WidgetMap map = Stetic.CodeGenerator.GenerateCreationCode (globalNs, type, w, new CodeThisReferenceExpression (), met.Statements, options, warnings);
CodeGenerator.BindSignalHandlers (new CodeThisReferenceExpression (), wwidget, map, met.Statements, options);
}
示例14: AddCustomAttributesToMethod
private void AddCustomAttributesToMethod(CodeMemberMethod dbMethod)
{
DataObjectMethodType update = DataObjectMethodType.Update;
if (base.methodSource.EnableWebMethods)
{
CodeAttributeDeclaration declaration = new CodeAttributeDeclaration("System.Web.Services.WebMethod");
declaration.Arguments.Add(new CodeAttributeArgument("Description", CodeGenHelper.Str(base.methodSource.WebMethodDescription)));
dbMethod.CustomAttributes.Add(declaration);
}
if (base.MethodType != MethodTypeEnum.GenericUpdate)
{
if (base.activeCommand == base.methodSource.DeleteCommand)
{
update = DataObjectMethodType.Delete;
}
else if (base.activeCommand == base.methodSource.InsertCommand)
{
update = DataObjectMethodType.Insert;
}
else if (base.activeCommand == base.methodSource.UpdateCommand)
{
update = DataObjectMethodType.Update;
}
dbMethod.CustomAttributes.Add(new CodeAttributeDeclaration(CodeGenHelper.GlobalType(typeof(DataObjectMethodAttribute)), new CodeAttributeArgument[] { new CodeAttributeArgument(CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DataObjectMethodType)), update.ToString())), new CodeAttributeArgument(CodeGenHelper.Primitive(true)) }));
}
}
示例15: SetTestMethodCategories
public override void SetTestMethodCategories(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, IEnumerable<string> scenarioCategories)
{
IEnumerable<string> tags = scenarioCategories.ToList();
IEnumerable<string> ownerTags = tags.Where(t => t.StartsWith(OWNER_TAG, StringComparison.InvariantCultureIgnoreCase)).Select(t => t);
if(ownerTags.Any())
{
string ownerName = ownerTags.Select(t => t.Substring(OWNER_TAG.Length).Trim('\"')).FirstOrDefault();
if(!String.IsNullOrEmpty(ownerName))
{
CodeDomHelper.AddAttribute(testMethod, OWNER_ATTR, ownerName);
}
}
IEnumerable<string> workitemTags = tags.Where(t => t.StartsWith(WORKITEM_TAG, StringComparison.InvariantCultureIgnoreCase)).Select(t => t);
if(workitemTags.Any())
{
int temp;
IEnumerable<string> workitemsAsStrings = workitemTags.Select(t => t.Substring(WORKITEM_TAG.Length).Trim('\"'));
IEnumerable<int> workitems = workitemsAsStrings.Where(t => int.TryParse(t, out temp)).Select(t => int.Parse(t));
foreach(int workitem in workitems)
{
CodeDomHelper.AddAttribute(testMethod, WORKITEM_ATTR, workitem);
}
}
CodeDomHelper.AddAttributeForEachValue(testMethod, CATEGORY_ATTR, GetNonMSTestSpecificTags(tags));
}