Raghu Vempati

Hi,

I have a question regarding the use of the AttributeInfo[] that is passed as an argument to the CreateProperty Method of the MemberCreationService of the WorkflowDesignerControl.

I want to create a dependency property which should be decorated with the following attributes i.e.

DesignerSerializationVisibility = Visible

Browsable = true

Now I am unable to understand how to pass these attribute info using the AttributeInfo[] arrary.

Please help me in this regard. Any sample code or directions to a right resource would be of a great help.

Thanks,

Kishore




Re: Windows Workflow Foundation Using the AttibuteInfo[] in the CreateProperty(..) Method - MemberCreationService --> WorkflowDesignerControl

Tom Lake - MSFT

You will not be able to use the CreateProperty method to add attributes to your property because the constructor for AttributeInfo is internal. Instead you will need to use CodeDom to create the property and any associated variable, for more information on CodeDom go to .

I am assuming you are using the Workflow Designer Control sample, found at http://msdn2.microsoft.com/en-us/library/aa480213.aspx. First you need to get a hold of the CodeTypeDeclaration associated with your class in the workflow designer control so add the following to WorkflowDesignerControl.cs:

public CodeTypeDeclaration GetCodeTypeDeclaration(string className)

{

MemberCreationService memCreateService = GetService(typeof(IMemberCreationService)) as MemberCreationService;

return memCreateService.GetCodeTypeDeclaration(this.nameSpace, className);

}

You will also need get the root activity and be able to flush the loader once the property is added so add the following methods to the same file.

public Activity GetWorkflow()

{

IDesignerHost designerHost = GetService(typeof(IDesignerHost)) as IDesignerHost;

return (Activity)designerHost.RootComponent;

}

public void FlushLoader()

{

this.loader.Flush();

}

Finally in WindowsFormApp.cs add the following code to add the property and associated variable:

private void AddProperty(object sender, EventArgs e)

{

Activity workflow = this.workflowDesignerControl1.GetWorkflow();

string className = workflow.QualifiedName;

CodeTypeDeclaration ctd = this.workflowDesignerControl1.GetCodeTypeDeclaration(className);

// Create and add variable.

CodeMemberField variable = new CodeMemberField(typeof(string), "variable");

ctd.Members.Add(variable);

// Create and add property

CodeMemberProperty prop = new CodeMemberProperty();

prop.Name = "PropertyName";

prop.Attributes = MemberAttributes.Public | MemberAttributes.Final;

prop.Type = new CodeTypeReference(typeof(string));

prop.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(DesignerSerializationVisibilityAttribute)), new CodeAttributeArgument(new CodePropertyReferenceExpression(new CodeTypeReferenceExpression(typeof(DesignerSerializationVisibility)), "Visible"))));

prop.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(BrowsableAttribute)), new CodeAttributeArgument(new CodePrimitiveExpression(true))));

prop.GetStatements.Add(new CodeMethodReturnStatement(new CodeVariableReferenceExpression(variable.Name)));

prop.SetStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression(variable.Name), new CodeVariableReferenceExpression("value")));

ctd.Members.Add(prop);

this.workflowDesignerControl1.FlushLoader();

}

The result will be the following:

private string variable;

[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]

[System.ComponentModel.BrowsableAttribute(true)]

public string PropertyName

{

get

{

return variable;

}

set

{

variable = value;

}

}






Re: Windows Workflow Foundation Using the AttibuteInfo[] in the CreateProperty(..) Method - MemberCreationService --> WorkflowDesignerControl

R.Kishore

Thanks for the help Tom.

~Kishore