public static CodeMemberMethod Method(this CodeTypeDeclaration decleration, MemberAttributes attributes, Type returnType, string name) { var method = new CodeMemberMethod() {Name = name, Attributes = attributes}; decleration.Members.Add(method); return method; }
internal static MethodAttributes ConvertToMethodAttributes(MemberAttributes memberAttributes) { MethodAttributes methodAttributes = MethodAttributes.ReuseSlot; // convert access attributes if ((memberAttributes & MemberAttributes.AccessMask) == MemberAttributes.Assembly) methodAttributes |= MethodAttributes.Assembly; else if ((memberAttributes & MemberAttributes.AccessMask) == MemberAttributes.Family) methodAttributes |= MethodAttributes.Family; else if ((memberAttributes & MemberAttributes.AccessMask) == MemberAttributes.FamilyAndAssembly) methodAttributes |= MethodAttributes.FamANDAssem; else if ((memberAttributes & MemberAttributes.AccessMask) == MemberAttributes.FamilyOrAssembly) methodAttributes |= MethodAttributes.FamORAssem; else if ((memberAttributes & MemberAttributes.AccessMask) == MemberAttributes.Private) methodAttributes |= MethodAttributes.Private; else if ((memberAttributes & MemberAttributes.AccessMask) == MemberAttributes.Public) methodAttributes |= MethodAttributes.Public; // covert scope attributes if ((memberAttributes & MemberAttributes.ScopeMask) == MemberAttributes.Abstract) methodAttributes |= MethodAttributes.Abstract; else if ((memberAttributes & MemberAttributes.ScopeMask) == MemberAttributes.Final) methodAttributes |= MethodAttributes.Final; else if ((memberAttributes & MemberAttributes.ScopeMask) == MemberAttributes.Static) methodAttributes |= MethodAttributes.Static; //else if ((memberAttributes & MemberAttributes.ScopeMask) == MemberAttributes.Override) // methodAttributes |= MethodAttributes.ReuseSlot;// // convert vtable slot if ((memberAttributes & MemberAttributes.VTableMask) == MemberAttributes.New) methodAttributes |= MethodAttributes.NewSlot; //if ((memberAttributes & MemberAttributes.VTableMask) == MemberAttributes.Overloaded) // methodAttributes |= MethodAttributes.HideBySig; // return methodAttributes; }
public static CodeMemberProperty AddProperty(this CodeTypeMember member, string propertyType, MemberAttributes ma, string name) { var classCode = member.GetDeclaration(); return classCode.AddProperty(propertyType, ma, name); }
/// <summary> /// Checks the class. /// </summary> /// <param name="codeType">The code type.</param> /// <param name="name">The class name.</param> /// <param name="modifiers">The class modifiers.</param> /// <param name="members">The count of members in the <paramref name="codeType"/>.</param> /// <param name="baseTypes">The class base types.</param> public static void CheckClass(CodeTypeDeclaration codeType, string name, MemberAttributes modifiers, int members, params string[] baseTypes) { Assert.IsTrue(codeType.IsClass, String.Format(CultureInfo.CurrentCulture, Settings.Default.IsNotClass, codeType.Name)); Assert.AreEqual(name, codeType.Name, Settings.Default.InvalidName); Assert.AreEqual(modifiers, codeType.Attributes, String.Format(CultureInfo.CurrentCulture, Settings.Default.InvalidAccessModifier, name)); if (baseTypes != null) { Assert.AreEqual(baseTypes.Length, codeType.BaseTypes.Count, String.Format(CultureInfo.CurrentCulture, Settings.Default.WrongNumberBaseTypes, name)); for (int i = 0; i < baseTypes.Length; i++) { Assert.AreEqual(baseTypes[i], codeType.BaseTypes[i].BaseType, String.Format(CultureInfo.CurrentCulture, Settings.Default.InvalidBaseType, name)); } } else { Assert.AreEqual(0, codeType.BaseTypes.Count, String.Format(CultureInfo.CurrentCulture, Settings.Default.WrongNumberBaseTypes, name)); } Assert.AreEqual(members, codeType.Members.Count, String.Format(CultureInfo.CurrentCulture, Settings.Default.WrongNumberMembers, name)); }
internal static CodeMemberField AddFieldDeclaration(CodeTypeDeclaration type, MemberAttributes memberAttribute, string fieldType, string fieldName) { CodeMemberField cmf = new CodeMemberField(fieldType, fieldName); cmf.Attributes = memberAttribute; type.Members.Add(cmf); return cmf; }
public static CodeMemberEvent AddEvent(this CodeTypeMember member, Type delegateType, MemberAttributes ma, string name) { var classCode = member.GetDeclaration(); return classCode.AddEvent(delegateType, ma, name); }
public static CodeTypeDeclaration CreateInterface (string name, MemberAttributes attribute) { CodeTypeDeclaration ct = new CodeTypeDeclaration (name); ct.Attributes = attribute; ct.IsInterface = true; return ct; }
MemberAttributes ConvModifiers(TypeMemberModifiers modifier, MemberAttributes defaultVisibility) { MemberAttributes attr = 0; if ((modifier & TypeMemberModifiers.Abstract) == TypeMemberModifiers.Abstract) attr |= MemberAttributes.Abstract; if ((modifier & TypeMemberModifiers.Final) == TypeMemberModifiers.Final) attr |= MemberAttributes.Const; if ((modifier & TypeMemberModifiers.Internal) == TypeMemberModifiers.Internal) attr |= MemberAttributes.Assembly; if ((modifier & TypeMemberModifiers.Override) == TypeMemberModifiers.Override) attr |= MemberAttributes.Override; if ((modifier & TypeMemberModifiers.Private) == TypeMemberModifiers.Private) attr |= MemberAttributes.Private; if ((modifier & TypeMemberModifiers.Protected) == TypeMemberModifiers.Protected) attr |= MemberAttributes.Family; if ((modifier & TypeMemberModifiers.Public) == TypeMemberModifiers.Public) attr |= MemberAttributes.Public; if ((modifier & TypeMemberModifiers.Static) == TypeMemberModifiers.Static) attr |= MemberAttributes.Static; if ((modifier & TypeMemberModifiers.Virtual) != TypeMemberModifiers.Virtual) attr |= MemberAttributes.Final; if ((modifier & TypeMemberModifiers.VisibilityMask) == TypeMemberModifiers.None) attr |= defaultVisibility; return attr; }
public static CodeTypeDeclaration Struct(string structName, MemberAttributes attributes) { return new CodeTypeDeclaration(structName) { Attributes = attributes, IsStruct = true }; }
public DesignConnection(string connectionName, System.Data.Design.ConnectionString cs, string provider) { this.properties = new HybridDictionary(); this.modifier = MemberAttributes.Assembly; this.name = connectionName; this.connectionStringObject = cs; this.provider = provider; }
public static CodeMemberProperty AddGetProperty(this CodeTypeMember member, string propertyType, MemberAttributes ma, string name, params CodeStatement[] statements) { var classCode = member.GetDeclaration(); return classCode.AddGetProperty(propertyType, ma, name, statements); }
public static CodeTypeDeclaration Interface(string interfaceName, MemberAttributes attributes) { return new CodeTypeDeclaration(interfaceName) { Attributes = attributes, IsInterface = true }; }
public virtual void DrawType(XBaseWindow window) { XBaseWindow.DoButton("Type", ()=> { XCodeTypeTemplate.SelectType(x => type = x); }); memberAttribute = (MemberAttributes)XBaseWindow.CreateEnumPopup( memberAttribute ); }
public static CodeTypeDeclaration Enum(string enumName, MemberAttributes attributes) { return new CodeTypeDeclaration(enumName) { Attributes = attributes, IsEnum = true }; }
public static CodeTypeDeclaration CreateClass (string name, MemberAttributes attribute, CodeTypeReference[] baseTypes) { CodeTypeDeclaration ct = new CodeTypeDeclaration (name); ct.Attributes = attribute; ct.BaseTypes.AddRange (baseTypes); ct.IsClass = true; return ct; }
public static CodeTypeDeclaration CreateClass (string name, MemberAttributes attribute, TypeAttributes typeAttr) { CodeTypeDeclaration ct = new CodeTypeDeclaration (name); ct.Attributes = attribute; ct.TypeAttributes = typeAttr; ct.IsClass = true; return ct; }
public static CodeMemberProperty AddProperty(this CodeTypeDeclaration classCode, string propertyType, MemberAttributes ma, string name, string fieldName) { var prop = Define.Property(propertyType, CorrectAttributes(classCode, ma), name, fieldName); classCode.Members_Add(prop); return prop; }
public static CodeMemberProperty AddGetProperty(this CodeTypeDeclaration classCode, CodeTypeReference propertyType, MemberAttributes ma, string name, params CodeStatement[] statements) { var prop = Define.GetProperty(propertyType, CorrectAttributes(classCode, ma), name, statements); classCode.Members_Add(prop); return prop; }
public String GetModifier(MemberAttributes memberAttributes) { switch (memberAttributes & MemberAttributes.ScopeMask) { case MemberAttributes.Final: return ""; case MemberAttributes.Abstract: return "abstract "; case MemberAttributes.Override: return "override "; default: return "virtual "; } }
/// <summary> /// 字段 /// <para>eg. public Dictionary<string,string> TestDic = new Dictionary<string,string>();</para> /// </summary> /// <param name="inLeft">字段类型</param> /// <param name="inFieldName"></param> /// <param name="inRight"></param> public ItemField(string inLeft, string inFieldName, string inRight = "", MemberAttributes inAtt = MemberAttributes.Private) { field = new CodeMemberField(inLeft, inFieldName); if (inRight != "") { CodeVariableReferenceExpression right = new CodeVariableReferenceExpression(inRight); field.InitExpression = right; } field.Attributes = inAtt; }
public void GenerateField(String name,Type type ,MemberAttributes MemberAttributes = MemberAttributes.Public) { if (CodeCompileUnit == null) throw new Exception("Call Generate Class Before"); CodeMemberField CodeMemberField = new CodeMemberField(); CodeMemberField.Attributes = MemberAttributes; CodeMemberField.Type = new CodeTypeReference(type); CodeMemberField.Name = name; derived.Members.Add(CodeMemberField); }
protected override MemberAttributes ModifyMemberAttributes(MemberAttributes memberAttributes) { // Methods are usually virtual ... var result = base.ModifyMemberAttributes(memberAttributes) & ~MemberAttributes.Final; // ... and override on derived types if (this.m.ObjectClass != this.dt) result = result | MemberAttributes.Override; return result; }
public static CodeMemberEvent Event(CodeTypeReference delegateType, MemberAttributes ma, string name) { var c = new CodeMemberEvent { Name = name, Attributes = ma, Type = delegateType, }; return c; }
public static CodeTypeDeclaration Struct(string structName, MemberAttributes attributes, bool partial) { var c = new CodeTypeDeclaration(structName) { Attributes = attributes, IsPartial = partial, IsStruct = true }; return c; }
/// <summary>Initializes the extension</summary> /// <param name="parameters">Initialization parameters: This class expects following parameters: /// <list type="table"><listheader><term>Parameter</term><description>Description</description> /// <item><term><c>PropertyName</c></term><description>Name of the property</description>. Required.</item> /// <item><term><c>TypeName</c></term><description>Name of type property <c>PropertyName</c> is property of. Required.</description></item> /// <item><term><c>NewName</c></term><description>Specified a new name of the property. Optional.</description></item> /// <item><term><c>OrAttributes</c></term><description>Represents attributes of the property as <see cref="MemberAttributes"/> value. These new attribuets are OR-ed with exising property attributes. Must be string representation of integer value in invariant culture. Optional.</description></item> /// <item><term><c>AndAttributes</c></term><description>Represents attributes of the property as <see cref="MemberAttributes"/> value. These new attributes are AND-ed with exising property attributes. Must be string representation of integer value in invariant culture. Optional.</description></item> /// <item><term><c>NewType</c></term><description>Change type of the property. Recognizes last character ? as <see cref="Nullable{T}"/>. Optional.</description></item> /// <item><term><c>FieldName</c></term><description>Only used with <c>NewType</c>. Name of backing field. Optional.</description></item> /// </listheader></list></param> /// <exception cref="KeyNotFoundException">A required parameter is not present in the <paramref name="parameters"/> dictionary.</exception> /// <exception cref="FormatException">Value for <c>AndAttributes</c> or <c>OrAttributes</c> cannot be parsed as integer in invariant culture.</exception> /// <exception cref="OverflowException">Value for <c>AndAttributes</c> or <c>OrAttributes</c> does not fall to range of <see cref="int"/>.</exception> public void Initialize(System.Collections.Generic.IDictionary<string, string> parameters) { propertyName = parameters["PropertyName"]; typeName = parameters["TypeName"]; if (parameters.ContainsKey("NewName")) newName = parameters["NewName"]; if (parameters.ContainsKey("OrAttributes")) orAttributes = (MemberAttributes)int.Parse(parameters["OrAttributes"], System.Globalization.CultureInfo.InvariantCulture); if (parameters.ContainsKey("AndAttributes")) andAttributes = (MemberAttributes)int.Parse(parameters["AndAttributes"], System.Globalization.CultureInfo.InvariantCulture); if (parameters.ContainsKey("NewType")) newPropertyType = parameters["NewType"]; if (parameters.ContainsKey("NewRank")) newArrayRank = int.Parse(parameters["NewRank"]); if (parameters.ContainsKey("FieldName")) backingField = parameters["FieldName"];//Only to change type if property type changes }
public ClassBuilder(string namespc, string className, MemberAttributes attributes) { _compUnit = new CodeCompileUnit(); _assemblies = new List<Assembly>(); _namespace = new CodeNamespace(namespc); _class = new CodeTypeDeclaration(className) {Attributes = attributes}; _compUnit.Namespaces.Add(_namespace); _namespace.Types.Add(_class); }
public ItemMethod(string inName, MemberAttributes inAtt, List<string> inParameters) { method = new CodeMemberMethod(); method.Name = inName; method.Attributes = inAtt; for (int i = 0; i < inParameters.Count; i++) { method.Parameters.Add(new CodeParameterDeclarationExpression(inParameters[i], "inArg" + i)); } statement = new CodeConditionStatement(); }
public static CodeCustomEvent Event(CodeTypeReference delegateType, MemberAttributes ma, string name, CodeMemberProperty add, CodeMemberProperty remove, CodeMemberMethod raise) { var c = new CodeMemberEvent { Name = name, Attributes = ma, Type = delegateType, }; return new CodeCustomEvent(c, add, remove, raise); }
public DesignConnection(string connectionName, IDbConnection conn) { this.properties = new HybridDictionary(); this.modifier = MemberAttributes.Assembly; if (conn == null) { throw new ArgumentNullException("conn"); } this.name = connectionName; DbProviderFactory factoryFromType = ProviderManager.GetFactoryFromType(conn.GetType(), ProviderManager.ProviderSupportedClasses.DbConnection); this.provider = ProviderManager.GetInvariantProviderName(factoryFromType); this.connectionStringObject = new System.Data.Design.ConnectionString(this.provider, conn.ConnectionString); }
/// <summary> /// /// </summary> /// <param name="member"></param> /// <param name="inner"></param> /// <param name="attrs"></param> /// <returns></returns> public CodeTypeMember CreateMember(MemberInfo member, CodeFieldReferenceExpression inner, MemberAttributes attrs) { Debug.Assert(member is MethodInfo); MethodInfo method = member as MethodInfo; CodeMemberMethod codeMethod = new CodeMemberMethod(); codeMethod.Name = method.Name; codeMethod.ReturnType = new CodeTypeReference(method.ReturnType); codeMethod.Attributes = attrs; // try CodeTryCatchFinallyStatement tryCode = new CodeTryCatchFinallyStatement(); // decleare parameters List<CodeArgumentReferenceExpression> codeParamiteRefrs = new List<CodeArgumentReferenceExpression>(); foreach (ParameterInfo codeParameter in method.GetParameters()) { CodeParameterDeclarationExpression codeParameterDeclare = new CodeParameterDeclarationExpression(codeParameter.ParameterType, codeParameter.Name); codeMethod.Parameters.Add(codeParameterDeclare); codeParamiteRefrs.Add(new CodeArgumentReferenceExpression(codeParameter.Name)); } // invoke CodeMethodInvokeExpression invokeMethod = new CodeMethodInvokeExpression( inner, method.Name, codeParamiteRefrs.ToArray()); if (method.ReturnType.Name.ToLower() == "void") { tryCode.TryStatements.Add(invokeMethod); } else { CodeVariableDeclarationStatement var = new CodeVariableDeclarationStatement(method.ReturnType, "returnObject", invokeMethod); //CodeAssignStatement assign = new CodeAssignStatement(var, invokeMethod); tryCode.TryStatements.Add(var); CodeCommentStatement todo = new CodeCommentStatement("TODO: your code", false); tryCode.TryStatements.Add(todo); CodeVariableReferenceExpression varRef = new CodeVariableReferenceExpression("returnObject"); CodeMethodReturnStatement codeReturn = new CodeMethodReturnStatement(varRef); tryCode.TryStatements.Add(codeReturn); } // catch CodeTypeReference codeTypeRef = new CodeTypeReference(typeof(Exception)); CodeCatchClause catchClause = new CodeCatchClause("ex", codeTypeRef); catchClause.Statements.Add(new CodeThrowExceptionStatement()); tryCode.CatchClauses.Add(catchClause); codeMethod.Statements.Add(tryCode); return codeMethod; }