本文整理汇总了C#中System.CodeDom.CodeMemberProperty类的典型用法代码示例。如果您正苦于以下问题:C# CodeMemberProperty类的具体用法?C# CodeMemberProperty怎么用?C# CodeMemberProperty使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CodeMemberProperty类属于System.CodeDom命名空间,在下文中一共展示了CodeMemberProperty类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddCommentsToFieldProperty
private static void AddCommentsToFieldProperty(CodeMemberProperty property, ITemplateFieldInfo field)
{
if (!string.IsNullOrEmpty(field.HelpText))
property.Comments.Add(new CodeCommentStatement("<summary>" + field.HelpText + "</summary>", true));
else
property.Comments.Add(new CodeCommentStatement(string.Format("<summary>Represents the {0} field</summary>", field.DisplayName), true));
}
示例2: DecorateProperty
public void DecorateProperty(CodeMemberProperty propertyDefinition, KeyValuePair<string, JsonSchema> propertyPair)
{
propertyDefinition.ThrowIfNull("propertyDefinition");
propertyPair.ThrowIfNull("propertyPair");
propertyDefinition.Comments.AddRange(CreateComment(propertyPair.Value));
}
示例3: CreateAttributeConstForProperty
private static void CreateAttributeConstForProperty(CodeTypeDeclaration type, CodeMemberProperty prop, HashSet<string> attributes)
{
var attributeLogicalName = (from CodeAttributeDeclaration att in prop.CustomAttributes
where att.AttributeType.BaseType == XrmAttributeLogicalName || HasAttributeAndRelationship(prop, att)
select new
{
FieldName = ((CodePrimitiveExpression)att.Arguments[0].Value).Value.ToString(),
Order = att.AttributeType.BaseType == XrmRelationshipSchemaName ? 0 : 1
}).
OrderBy(a => a.Order).
FirstOrDefault()?.FieldName;
if (attributes.Contains(prop.Name) || attributeLogicalName == null) return;
attributes.Add(prop.Name);
type.Members.Add(new CodeMemberField
{
// ReSharper disable once BitwiseOperatorOnEnumWithoutFlags
Attributes = System.CodeDom.MemberAttributes.Public | System.CodeDom.MemberAttributes.Const,
Name = prop.Name,
Type = new CodeTypeReference(typeof (string)),
InitExpression = new CodePrimitiveExpression(attributeLogicalName)
});
}
示例4: GenerateProperty
public static CodeMemberProperty GenerateProperty(string propertyName, string propertyType, List<CodeStatement> getStatements = null, List<CodeStatement> setStatements = null)
{
CodeMemberProperty property = new CodeMemberProperty
{
Attributes = MemberAttributes.Family | MemberAttributes.Final,
Name = propertyName,
Type = GetTypeReferenceFromName(propertyType),
HasGet = (getStatements != null && getStatements.Any()),
HasSet = (setStatements != null && setStatements.Any())
};
if (property.HasGet && getStatements != null)
{
foreach (CodeStatement statement in getStatements)
{
property.GetStatements.Add(statement);
}
}
if (property.HasSet && setStatements != null)
{
foreach (CodeStatement statement in setStatements)
{
property.SetStatements.Add(statement);
}
}
return property;
}
示例5: EmitImplementationCode
public void EmitImplementationCode (CodeTypeDeclaration ctd)
{
byte[] bytes = Hash;
int hash = 0;
for (int i = 0; bytes.Length - i > 3; i += 4)
hash ^= BitConverter.ToInt32 (bytes, i);
// Insane Clown Property
CodeMemberProperty icp = new CodeMemberProperty ();
icp.Name = "ImplementationCode";
icp.Attributes = MemberAttributes.Family | MemberAttributes.Override;
icp.Type = new CodeTypeReference (typeof (int));
icp.HasGet = true;
icp.HasSet = false;
// get { return base.ImplementationCode ^ [number] }
// becomes:
// get { return LameCodeDomXor (base.ImplementationCode, [number]); }
CodeMethodInvokeExpression invoke = new CodeMethodInvokeExpression ();
invoke.Method = new CodeMethodReferenceExpression (CDH.This, "LameCodeDomXor");
invoke.Parameters.Add (new CodePropertyReferenceExpression (CDH.Base, "ImplementationCode"));
invoke.Parameters.Add (new CodePrimitiveExpression (hash));
icp.GetStatements.Add (new CodeMethodReturnStatement (invoke));
ctd.Members.Add (icp);
}
示例6: AddProperties
public ClassCreator AddProperties(string propertyName, Type propertyType)
{
var backingField = new CodeMemberField(propertyType, "_" + propertyName);
_targetClass.Members.Add(backingField);
// Declare the read-only Width property.
var memberProperty = new CodeMemberProperty
{
Attributes = MemberAttributes.Public | MemberAttributes.Final,
Name = propertyName,
HasGet = true,
HasSet = true,
Type = new CodeTypeReference(propertyType)
};
memberProperty.GetStatements.Add(new CodeMethodReturnStatement(
new CodeFieldReferenceExpression(
new CodeThisReferenceExpression(), "_" + propertyName)));
memberProperty.SetStatements.Add(
new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_" + propertyName),
new CodePropertySetValueReferenceExpression())
);
_targetClass.Members.Add(memberProperty);
return this;
}
示例7: CreateMethods
protected internal override void CreateMethods ()
{
CodeMemberField fld;
CodeMemberProperty prop;
/* override the following abstract PageTheme properties:
protected abstract string AppRelativeTemplateSourceDirectory { get; }
protected abstract IDictionary ControlSkins { get; }
protected abstract string[] LinkedStyleSheets { get; }
*/
/* ControlSkins */
fld = new CodeMemberField (typeof (HybridDictionary), "__controlSkins");
fld.Attributes = MemberAttributes.Private;
fld.InitExpression = new CodeObjectCreateExpression (typeof (HybridDictionary));
mainClass.Members.Add (fld);
prop = new CodeMemberProperty ();
prop.Name = "ControlSkins";
prop.Attributes = MemberAttributes.Family | MemberAttributes.Override;
prop.Type = new CodeTypeReference (typeof (IDictionary));
prop.GetStatements.Add (new CodeMethodReturnStatement (new CodeVariableReferenceExpression ("__controlSkins")));
mainClass.Members.Add (prop);
/* LinkedStyleSheets */
fld = new CodeMemberField (typeof (string[]), "__linkedStyleSheets");
fld.Attributes = MemberAttributes.Private;
fld.InitExpression = CreateLinkedStyleSheets ();
mainClass.Members.Add (fld);
prop = new CodeMemberProperty ();
prop.Name = "LinkedStyleSheets";
prop.Attributes = MemberAttributes.Family | MemberAttributes.Override;
prop.Type = new CodeTypeReference (typeof (string[]));
prop.GetStatements.Add (new CodeMethodReturnStatement (new CodeVariableReferenceExpression ("__linkedStyleSheets")));
mainClass.Members.Add (prop);
/* AppRelativeTemplateSourceDirectory */
prop = new CodeMemberProperty ();
prop.Name = "AppRelativeTemplateSourceDirectory";
prop.Attributes = MemberAttributes.Family | MemberAttributes.Override;
prop.Type = new CodeTypeReference (typeof (string));
prop.GetStatements.Add (new CodeMethodReturnStatement (
new CodePrimitiveExpression (
VirtualPathUtility.ToAbsolute (parser.BaseVirtualDir))));
mainClass.Members.Add (prop);
ControlBuilder builder = parser.RootBuilder;
if (builder.Children != null) {
foreach (object o in builder.Children) {
if (! (o is ControlBuilder))
continue;
if (o is CodeRenderBuilder)
continue;
ControlBuilder b = (ControlBuilder) o;
CreateControlSkinMethod (b);
}
}
}
示例8: OnProcessGeneratedCode
public override void OnProcessGeneratedCode(ControlBuilder controlBuilder, CodeCompileUnit codeCompileUnit, CodeTypeDeclaration baseType, CodeTypeDeclaration derivedType, CodeMemberMethod buildMethod, CodeMemberMethod dataBindingMethod, System.Collections.IDictionary additionalState)
{
// only run this once during page compilation, and only use this one builder (so that we don't get master pages, etc.)
if (controlBuilder.GetType() == typeof(FileLevelPageControlBuilder))
{
// the page will only contain one namespace and one type
var ns = codeCompileUnit.Namespaces.Cast<CodeNamespace>().FirstOrDefault();
if (ns != null)
{
var type = ns.Types.Cast<CodeTypeDeclaration>().FirstOrDefault();
if (type != null)
{
/* When this is output, it will inject this into every page:
*
* protected override PageStatePersister PageStatePersister {
* get { return new CompressedHiddenFieldPageStatePersister(this); }
* }
*
*/
CodeMemberProperty property = new CodeMemberProperty()
{
Name = "PageStatePersister",
HasGet = true,
Attributes = MemberAttributes.Override | MemberAttributes.Family,
Type = new CodeTypeReference(typeof(PageStatePersister))
};
var newObj = new CodeObjectCreateExpression(typeof(CompressedHiddenFieldPageStatePersister), new CodeThisReferenceExpression());
property.GetStatements.Add(new CodeMethodReturnStatement(newObj));
type.Members.Add(property);
}
}
}
base.OnProcessGeneratedCode(controlBuilder, codeCompileUnit, baseType, derivedType, buildMethod, dataBindingMethod, additionalState);
}
开发者ID:GrabYourPitchforks,项目名称:viewstate-compression,代码行数:35,代码来源:ViewStateCompressorControlBuilderInterceptor.cs
示例9: IsNullableIntPropery
// If using the Xrm Client, OptionSets are converted to nullable Ints
private static bool IsNullableIntPropery(CodeMemberProperty property)
{
return property.Type.BaseType == "System.Nullable`1" &&
property.Type.TypeArguments != null &&
property.Type.TypeArguments.Count == 1 &&
property.Type.TypeArguments[0].BaseType == "System.Int32";
}
示例10: Process
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);
}
}
}
}
}
示例11: AddProperty
public CodeMemberProperty AddProperty(string name, CodeTypeReference propType)
{
var property = new CodeMemberProperty();
property.Attributes = (MemberAttributes)24578; //Public Final
property.HasGet = true;
property.HasSet = true;
property.Name = name;
property.Type = propType;
var memberName = char.ToLower(property.Name[0]) + property.Name.Substring(1);
memberName = memberName.Insert(0, "_");
var field = new CodeMemberField() {
Name = memberName,
Type = propType,
Attributes = MemberAttributes.Private
};
property.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), memberName)));
property.SetStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), memberName), new CodePropertySetValueReferenceExpression()));
_base.Members.Add(field);
_base.Members.Add(property);
return property;
}
示例12: InsideCodeTypeDeclaration
protected internal override object InsideCodeTypeDeclaration(CodeTypeDeclaration decl)
{
// if getter is omitted, just output the setter like a method
if (decl.IsInterface || Getter == null) {
if (Getter != null)
Getter.Visit (decl);
if (Setter != null)
Setter.Visit (decl);
return null;
} else if (!decl.IsClass)
return null;
var prop = new CodeMemberProperty {
Name = this.Name,
// FIXME: For now, no properties will be virtual... change this at some point?
Attributes = MemberAttributes.Public | MemberAttributes.Final,
Type = Getter.ReturnTypeReference
};
Getter.Visit (prop.GetStatements);
if (Setter != null)
Setter.Visit (prop.SetStatements);
decl.Members.Add (prop);
return prop;
}
示例13: Visit
public void Visit(ProxyList statement)
{
var property = new CodeMemberProperty();
property.Attributes = MemberAttributes.Override | MemberAttributes.Family;
property.Name = "Proxies";
property.HasSet = false;
property.Type = new CodeTypeReference(typeof(string[]));
property.GetStatements.Add(new CodeVariableDeclarationStatement(new CodeTypeReference(typeof(string[])), "proxies",
new CodeArrayCreateExpression(new CodeTypeReference(typeof(string[])), new CodePrimitiveExpression(statement.Proxies.Length)))
);
for (int x = 0; x < statement.Proxies.Length; x++ )
{
if (!Proxy.TryParse(statement.Proxies[x].Value))
Errors.Add(new BadProxyFormat(new Semantic.LineInfo(statement.Proxies[x].Line.Line, statement.Proxies[x].Line.CharacterPosition)));
property.GetStatements.Add(new CodeAssignStatement(new CodeArrayIndexerExpression(new CodeVariableReferenceExpression("proxies"),
new CodePrimitiveExpression(x)), new CodePrimitiveExpression(statement.Proxies[x].Value))
);
}
property.GetStatements.Add(new CodeMethodReturnStatement(new CodeVariableReferenceExpression("proxies")));
_mainType.Type.Members.Add(property);
}
示例14: AddPropertyGroup
private void AddPropertyGroup(AssemblyBuilder assemblyBuilder, string groupName, string propertyNames, Hashtable properties, CodeTypeDeclaration type, CodeNamespace ns)
{
CodeMemberProperty property = new CodeMemberProperty {
Name = groupName,
Attributes = MemberAttributes.Public,
HasGet = true,
Type = new CodeTypeReference("ProfileGroup" + groupName)
};
CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression {
Method = { TargetObject = new CodeThisReferenceExpression(), MethodName = "GetProfileGroup" }
};
expression.Parameters.Add(new CodePrimitiveExpression(property.Name));
CodeMethodReturnStatement statement = new CodeMethodReturnStatement(new CodeCastExpression(property.Type, expression));
property.GetStatements.Add(statement);
type.Members.Add(property);
CodeTypeDeclaration declaration = new CodeTypeDeclaration {
Name = "ProfileGroup" + groupName
};
declaration.BaseTypes.Add(new CodeTypeReference(typeof(ProfileGroupBase)));
foreach (string str in propertyNames.Split(new char[] { ';' }))
{
this.CreateCodeForProperty(assemblyBuilder, declaration, (ProfileNameTypeStruct) properties[str]);
}
ns.Types.Add(declaration);
}
示例15: ProcessProperty
protected override void ProcessProperty(CodeTypeDeclaration type, CodeMemberField field, CodeMemberProperty property)
{
if (property.Type.ArrayElementType == null) return; // Is array?
if (property.Name == "Items" || property.Name == "ItemsElementName") return;
CodeTypeReference genericType = new CodeTypeReference("System.Collections.Generic.List", new CodeTypeReference(property.Type.BaseType));
property.Type = genericType;
if (field != null) {
field.Type = genericType;
property.GetStatements.Insert(0,
// if
new CodeConditionStatement(
// field == null
new CodeBinaryOperatorExpression(
new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), field.Name),
CodeBinaryOperatorType.IdentityEquality,
new CodePrimitiveExpression(null)),
// field = new List<T>();
new CodeAssignStatement(
new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), field.Name),
new CodeObjectCreateExpression(genericType))));
}
}