private void GenerateCS() { using (Microsoft.CSharp.CSharpCodeProvider provider = new Microsoft.CSharp.CSharpCodeProvider()) { CodeGeneratorOptions opts = new CodeGeneratorOptions(); StringWriter sw = new StringWriter(); List <CodeTypeReference> implTypes = new List <CodeTypeReference>(); if (_property.ImplementationTypes != null) { var arr = new CodeTypeReference[_property.ImplementationTypes.Count]; _property.ImplementationTypes.CopyTo(arr, 0); _property.ImplementationTypes.Clear(); _property.PrivateImplementationType = null; implTypes.AddRange(arr); } provider.GenerateCodeFromMember(_property, sw, opts); foreach (CodeTypeReference tr in implTypes) { _property.ImplementationTypes.Add(tr); } //StringReader sr = new StringReader(sw.GetStringBuilder().ToString()); //string line = sr.ReadLine(); //while (string.IsNullOrEmpty(line) || line.StartsWith("/") || line.StartsWith("[")) // line = sr.ReadLine(); StringBuilder sb = new StringBuilder(); if (InterfaceProperties != null) { foreach (CodeTypeReference tr in implTypes) { string prop; if (InterfaceProperties.TryGetValue(tr, out prop)) { var newProp = Define.Property(_property.Type, MemberAttributes.Private, prop).Implements(tr); if (_property.HasGet) { newProp.GetStatements.Add(Emit.@return(() => [email protected](_property.Name))); newProp.HasGet = true; } if (_property.HasSet) { newProp.SetStatements.Add(Emit.assignProperty(_property.Name, () => CodeDom.VarRef("value"))); newProp.HasSet = true; } StringWriter swNew = new StringWriter(); provider.GenerateCodeFromMember(CodeDomTreeProcessor.ProcessMember(newProp, CodeDomGenerator.Language.CSharp), swNew, opts); sb.Append(swNew.ToString()); } } if (sb.Length > 0) { sb.Insert(0, Environment.NewLine); } } Text = sw.GetStringBuilder().ToString() + sb.ToString(); } }
public MethodCaller GetPropertyAllCall(string iface) { PropertyDictionary calls; if (!Properties.TryGetValue(iface, out calls)) { Properties [iface] = calls = new PropertyDictionary(); } if (null == calls.All) { Type it = Mapper.GetInterfaceType(ObjectType, iface); calls.All = TypeImplementer.GenGetAllCall(it); } return(calls.All); }
private void GenerateVB() { using (Microsoft.VisualBasic.VBCodeProvider provider = new Microsoft.VisualBasic.VBCodeProvider()) { CodeGeneratorOptions opts = new CodeGeneratorOptions(); StringWriter sw = new StringWriter(); List <CodeTypeReference> implTypes = new List <CodeTypeReference>(); if (_property.ImplementationTypes != null) { var arr = new CodeTypeReference[_property.ImplementationTypes.Count]; _property.ImplementationTypes.CopyTo(arr, 0); _property.ImplementationTypes.Clear(); implTypes.AddRange(arr); } provider.GenerateCodeFromMember(_property, sw, opts); foreach (CodeTypeReference tr in implTypes) { _property.ImplementationTypes.Add(tr); } StringReader sr = new StringReader(sw.GetStringBuilder().ToString()); string line = sr.ReadLine(); while (string.IsNullOrEmpty(line) || line.StartsWith("'") || line.StartsWith("<")) { line = sr.ReadLine(); } StringBuilder sb = new StringBuilder(); sb.Append(line); if (InterfaceProperties != null) { sb.Append(" Implements "); foreach (CodeTypeReference tr in implTypes) { string prop; if (InterfaceProperties.TryGetValue(tr, out prop)) { sb.Append(provider.GetTypeOutput(tr)).Append(".").Append(prop).Append(", "); } } sb.Length -= 2; } Text = sw.GetStringBuilder().Replace(line, sb.ToString()).ToString(); } }