protected string PrintEntity(PropertyEntity propertyEntity) { string str = string.Empty; //print domain //if (propertyEntity.Domain != null) //{ // str += NewLine + @"<rdfs:domain rdf:resource=""" + propertyEntity.Domain.Identity + @""" />"; //} //print range if (propertyEntity.Range != null) { str += NewLine + @"<rdfs:range rdf:resource=""" + propertyEntity.Range.Name + @""" />"; } //print header string sHeaderBegin = @"<owl:ObjectProperty rdf:ID=""" + propertyEntity.Identity.Replace(' ', '_'); //if body os empty print "/>", else print full footer("</...>"). if (str != string.Empty) { str = sHeaderBegin + @""">" + str; //print footer str += NewLine + @"</owl:ObjectProperty>"; } else { str = sHeaderBegin + @"""/>"; } return(str); }
/// <summary> /// /// </summary> /// <param name="info"></param> /// <returns></returns> /// <remarks>Need to change returned UnknownEntity's Value.</remarks> private IEntity CreateOrdinalEntity(string word, FullLemmaInfo info) { if (!this.GramTable.ContainsKey(info.CommonMF.Gramcode)) { throw new Exception("Gramcode error"); } if (info == FullLemmaInfo.Unknown) { return(null); } IEntity result = null; PartOfSpeech pos = this.GramTable[info.CommonMF.Gramcode].PartOfSpeech; if (pos == PartOfSpeech.Noun) { result = new ClassEntity(info.CommonLemma); } else if (pos == PartOfSpeech.Adjective || pos == PartOfSpeech.AdjectiveFull || pos == PartOfSpeech.AdjectiveShort) { result = new PropertyEntity(info.CommonLemma); } else { result = new UnknownEntity(info.CommonLemma); } result.PartOfSpeech = pos; return(result); }
private bool IndexersHaveDifferentLength(CompareParms parms, PropertyEntity info, int indexerCount1, int indexerCount2) { if (info == null) { throw new ArgumentNullException("info"); } if (indexerCount1 != indexerCount2) { string currentCrumb = AddBreadCrumb(parms.Config, parms.BreadCrumb, info.Name); Difference difference = new Difference { ParentObject1 = parms.ParentObject1, ParentObject2 = parms.ParentObject2, PropertyName = currentCrumb, Object1Value = indexerCount1.ToString(CultureInfo.InvariantCulture), Object2Value = indexerCount2.ToString(CultureInfo.InvariantCulture), ChildPropertyName = "Count", Object1 = parms.Object1, Object2 = parms.Object2 }; AddDifference(parms.Result, difference); return(true); } return(false); }
public bool Post(PropertyModel model) { var entity = new PropertyEntity { PropertyName = model.PropertyName, Adduser = (UserBase)_workContext.CurrentUser, Addtime = DateTime.Now, UpdUser = (UserBase)_workContext.CurrentUser, UpdTime = DateTime.Now, // Value = model.Value, Category = _categoryService.GetCategoryById(model.Category.Id) }; if (_propertyService.Create(entity).Id > 0) { return(true); } return(false); }
public async Task <Property> CreatePropertyAsync(Property property) { var entity = PropertyEntity.MapFrom(property); _dbContext.Properties.Add(entity); await _dbContext.SaveChangesAsync(); return(PropertyEntity.MapTo(entity)); }
public static void dbCreateHistoryLevel(CommandContext commandContext) { ProcessEngineConfigurationImpl processEngineConfiguration = Context.ProcessEngineConfiguration; HistoryLevel configuredHistoryLevel = processEngineConfiguration.HistoryLevel; PropertyEntity property = new PropertyEntity("historyLevel", Convert.ToString(configuredHistoryLevel.Id)); commandContext.getSession(typeof(DbEntityManager)).insert(property); LOG.creatingHistoryLevelPropertyInDatabase(configuredHistoryLevel); }
public static void DbCreateHistoryLevel(CommandContext entityManager) { var processEngineConfiguration = context.Impl.Context.ProcessEngineConfiguration; var configuredHistoryLevel = processEngineConfiguration.HistoryLevel; PropertyEntity property = new PropertyEntity("historyLevel", Convert.ToString(configuredHistoryLevel.Id)); entityManager.PropertyManager.Add(property); Log.CreatingHistoryLevelPropertyInDatabase(configuredHistoryLevel); }
public virtual void checkDeploymentLockExists(CommandContext commandContext) { PropertyEntity deploymentLockProperty = commandContext.PropertyManager.findPropertyById("deployment.lock"); if (deploymentLockProperty == null) { LOG.noDeploymentLockPropertyFound(); } }
public virtual void checkHistoryCleanupLockExists(CommandContext commandContext) { PropertyEntity historyCleanupLockProperty = commandContext.PropertyManager.findPropertyById("history.cleanup.job.lock"); if (historyCleanupLockProperty == null) { LOG.noHistoryCleanupLockPropertyFound(); } }
protected internal void checkStartupLockExists(CommandContext commandContext) { PropertyEntity historyStartupProperty = commandContext.PropertyManager.findPropertyById("startup.lock"); if (historyStartupProperty == null) { LOG.noStartupLockPropertyFound(); } }
/// <summary> /// Appends the documentation. /// </summary> private void AppendDocumentation(PropertyEntity propertyEntity) { this.Writer.WriteLineFormat(2, "/// <summary>"); foreach (String line in propertyEntity.Summary) { this.Writer.WriteLineFormat(2, "/// <para>{0}</para>", line.EscapeAll()); } this.Writer.WriteLineFormat(2, "/// <para>Original signature is '{0}'</para>", propertyEntity.Getter.Signature.EscapeAll()); this.AppendAvailability(2, propertyEntity); this.Writer.WriteLineFormat(2, "/// </summary>"); }
/// <summary> /// 保存表单(新增、修改) /// </summary> /// <param name="keyValue">主键值</param> /// <param name="entity">实体对象</param> /// <returns></returns> public void SaveForm(string keyValue, PropertyEntity entity) { try { service.SaveForm(keyValue, entity); } catch (Exception) { throw; } }
public object execute(CommandContext commandContext) { DbEntityManager dbEntityManager = commandContext.DbEntityManager; PropertyEntity historyLevelProperty = dbEntityManager.selectById(typeof(PropertyEntity), "historyLevel"); if (historyLevelProperty != null) { dbEntityManager.delete(historyLevelProperty); } return(null); }
/// <summary> /// Parses the specified entity. /// </summary> /// <param name = "entity">The entity.</param> /// <param name = "reader">The reader.</param> public override void Parse(BaseEntity entity, TextReader reader) { ClassEntity classEntity = (ClassEntity)entity; if (classEntity == null) { throw new ArgumentException ("ClassEntity expected", "entity"); } using (XmlTextReader xmlTextReader = new XmlTextReader(reader)) { XElement root = XElement.Load (xmlTextReader); // Get the spec box XElement specElement = (from el in root.Descendants ("div") where el.Attribute ("class").Contains("spec_sheet_info_box") select el).FirstOrDefault (); if (specElement != null) { // Availability XElement availabilityElement = (from el in specElement.Descendants ("td") let prev = el.ElementsBeforeSelf ("td").FirstOrDefault () where prev != null && prev.Value.TrimAll () == "Availability" select el).FirstOrDefault (); if (availabilityElement != null) { entity.MinAvailability = CommentHelper.ExtractAvailability (availabilityElement.TrimAll ()); } // Inherits XElement inheritElement = (from el in specElement.Descendants ("td") let prev = el.ElementsBeforeSelf ("td").FirstOrDefault () where prev != null && prev.Value.TrimAll () == "Inherits from" select el).FirstOrDefault (); if (inheritElement != null) { string hierarchy = inheritElement.TrimAll (); string[] parents = hierarchy.Split (new[] {':'}, StringSplitOptions.RemoveEmptyEntries); classEntity.BaseType = parents [0].Trim (); } // Conforms To XElement conformsElements = (from el in specElement.Descendants ("td") let prev = el.ElementsBeforeSelf ("td").FirstOrDefault () where prev != null && prev.Value.TrimAll () == "Conforms to" select el).FirstOrDefault (); if (conformsElements != null) { List<String> protocols = new List<string> (); foreach (XElement conformsElement in conformsElements.Descendants("span")) { String protocol = conformsElement.TrimAll (); if (protocol.Contains ("(NSObject)") || protocol.Contains ("(NSProxy)")) { continue; } int pos = protocol.IndexOf ('('); if (pos != -1) { protocol = protocol.Substring (0, pos).Trim (); } protocols.Add (protocol); } classEntity.ConformsTo = String.Join (",", protocols.Distinct ().ToArray ()); } } // Class Methods this.ExtractClassMethods (classEntity, root); // Instance Methods this.ExtractInstanceMethods (classEntity, root); // Delegate Methods this.ExtractDelegateMethods (classEntity, root); // Properties this.ExtractProperties (classEntity, root); // Constants this.ExtractConstants (classEntity, root); // Notifications this.ExtractNotifications (classEntity, root); // Functions this.ExtractFunctions (classEntity, root); } // Extract getter and search for setter List<String> notGetterMethods = this.Settings ["NotGetterMethods"].Split (new []{','}, StringSplitOptions.RemoveEmptyEntries).ToList (); List<MethodEntity> methodModels = new List<MethodEntity> (classEntity.Methods); foreach (MethodEntity methodModel in methodModels) { if (notGetterMethods.Contains (methodModel.Name) || !methodModel.IsGetter) { continue; } classEntity.Methods.Remove (methodModel); MethodEntity getter = methodModel; // TODO: Refactor to use the IsSetterFor with an optional parameter to strip the prefix MethodEntity setter = classEntity.Methods.Find (m => String.Equals ("Set" + getter.Name, m.Name) && String.Equals (m.ReturnType, "void") && m.Parameters.Count == 1 && m.Static == getter.Static); if (setter == null) { setter = classEntity.Methods.Find (m => m.IsSetterFor (getter)); } if (setter != null) { classEntity.Methods.Remove (setter); } PropertyEntity property = new PropertyEntity (); property.Name = getter.Name; property.Type = getter.ReturnType; property.Summary = getter.Summary; property.MinAvailability = getter.MinAvailability; property.Static = getter.Static; property.Getter = getter; property.Setter = setter; classEntity.Properties.Add (property); } // Ensure that availability is set on entity. entity.AdjustAvailability (); }
/// <summary> /// Parses the specified entity. /// </summary> /// <param name = "entity">The entity.</param> /// <param name = "reader">The reader.</param> public override void Parse(BaseEntity entity, TextReader reader) { ClassEntity classEntity = (ClassEntity)entity; if (classEntity == null) { throw new ArgumentException ("ClassEntity expected", "entity"); } using (XmlTextReader xmlTextReader = new XmlTextReader(reader)) { XElement root = XElement.Load (xmlTextReader); // Extract inheritance IEnumerable<String> conformsElements = (from el in root.Descendants ("basecompoundref") select el.TrimAll ()); List<String> protocols = new List<string> (); foreach (string conformsElement in conformsElements) { if (conformsElement.StartsWith ("<")) { String protocol = conformsElement.Trim ('<', '>'); if (protocol.EndsWith ("-p")) { protocol = protocol.Replace ("-p", String.Empty); } protocols.Add (protocol); } else { classEntity.BaseType = conformsElement.Trim (); } } if (!(classEntity is ProtocolEntity) && String.IsNullOrEmpty (classEntity.BaseType)) { classEntity.BaseType = "NSObject"; } classEntity.ConformsTo = String.Join (",", protocols.Distinct ().ToArray ()); // Functions this.ExtractFunctions (classEntity, root); // Methods this.ExtractMethods (classEntity, root); // Properties this.ExtractProperties (classEntity, root); // Constants this.ExtractConstants (classEntity, root); // Enumerations this.ExtractEnumerations (classEntity, root); } // Extract getter and search for setter List<String> notGetterMethods = this.Settings ["NotGetterMethods"].Split (new []{','}, StringSplitOptions.RemoveEmptyEntries).ToList (); List<MethodEntity> methodModels = new List<MethodEntity> (classEntity.Methods); foreach (MethodEntity methodModel in methodModels) { if (notGetterMethods.Contains (methodModel.Name) || !methodModel.IsGetter) { continue; } classEntity.Methods.Remove (methodModel); MethodEntity getter = methodModel; MethodEntity setter = classEntity.Methods.Find (m => String.Equals ("Set" + getter.Name, m.Name) && String.Equals (m.ReturnType, "void")); if (setter == null) { setter = classEntity.Methods.Find (m => m.IsSetterFor (getter)); } if (setter != null) { classEntity.Methods.Remove (setter); } this.Logger.WriteLine ("Converting " + getter.Name + " to property"); PropertyEntity property = new PropertyEntity (); property.Name = getter.Name; property.Type = getter.ReturnType; property.Summary = getter.Summary; property.MinAvailability = getter.MinAvailability; property.Static = getter.Static; property.Getter = getter; property.Setter = setter; classEntity.Properties.Add (property); } // Ensure that availability is set on entity. entity.AdjustAvailability (); }
/// <summary> /// Generates the specified entity. /// </summary> /// <param name = "classEntity">The class entity.</param> /// <param name = "propertyEntity">The property entity.</param> /// <param name = "implementation">if set to <c>true</c> generate the implementation.</param> public void Generate(ClassEntity classEntity, PropertyEntity propertyEntity, bool implementation = true, bool markedAsNew = false) { // Don't generate if required if (!propertyEntity.Generate) { return; } // Append static condition if needed this.AppendStartCondition (propertyEntity); // Append property comments this.AppendDocumentation (propertyEntity); // Append Obsolete attribute this.AppendObsoleteAttribute (propertyEntity); // Special case for delegates String type = propertyEntity.Type; if (String.Equals (propertyEntity.Name, "Delegate")) { type = "Id"; } this.Writer.WriteLineFormat (2, "{0}{1} {2}", GetKeywords (propertyEntity, implementation, markedAsNew), type, propertyEntity.Name); //String type32 = GetRealType (type, false); //String type64 = GetRealType (type, true); //bool useMixedInvocation = !String.Equals (type32, type64); // Append getter if (implementation) { this.Writer.WriteLineFormat (2, "{{"); // if (useMixedInvocation) // { // this.Writer.WriteLineFormat(3, "get {{"); //#if MIXED_MODE // this.Writer.WriteLineFormat(4, "if (ObjectiveCRuntime.Is64Bits)"); // this.Writer.WriteLineFormat(4, "{{"); // // this.Writer.WriteLineFormat(5, "return ({0}) ObjectiveCRuntime.SendMessage<{1}>({2}, \"{3}\");", type, GetRealType(type, true), propertyEntity.Static ? classEntity.Name + "Class" : "this", // "" + propertyEntity.Getter.Selector); // // this.Writer.WriteLineFormat(4, "}}"); // this.Writer.WriteLineFormat(4, "else"); // this.Writer.WriteLineFormat(4, "{{"); //#endif // this.Writer.WriteLineFormat(5, "return ({0}) ObjectiveCRuntime.SendMessage<{1}>({2}, \"{3}\");", type, GetRealType(type, false), propertyEntity.Static ? classEntity.Name + "Class" : "this", // "" + propertyEntity.Getter.Selector); //#if MIXED_MODE // this.Writer.WriteLineFormat(4, "}}"); //#endif // this.Writer.WriteLineFormat(3, "}}"); // } // else { this.Writer.WriteLineFormat (3, "get {{ return ObjectiveCRuntime.SendMessage<{0}>({1}, \"{2}\"); }}", type, propertyEntity.Static ? classEntity.Name + "." + classEntity.Name + "Class" : "this", "" + propertyEntity.Getter.Selector); } // Append setter if (propertyEntity.Setter != null) { // if (useMixedInvocation) // { // this.Writer.WriteLineFormat(3, "set {{"); //#if MIXED_MODE // this.Writer.WriteLineFormat(4, "if (ObjectiveCRuntime.Is64Bits)"); // this.Writer.WriteLineFormat(4, "{{"); // // this.Writer.WriteLineFormat(5, "ObjectiveCRuntime.SendMessage({0}, \"{1}\", ({2}) value);", propertyEntity.Static ? classEntity.Name + "Class" : "this", "" + propertyEntity.Setter.Selector, GetRealType(type, true)); // // this.Writer.WriteLineFormat(4, "}}"); // this.Writer.WriteLineFormat(4, "else"); // this.Writer.WriteLineFormat(4, "{{"); //#endif // this.Writer.WriteLineFormat(5, "ObjectiveCRuntime.SendMessage({0}, \"{1}\", ({2}) value);", propertyEntity.Static ? classEntity.Name + "Class" : "this", "" + propertyEntity.Setter.Selector, GetRealType(type, false)); //#if MIXED_MODE // this.Writer.WriteLineFormat(4, "}}"); //#endif // this.Writer.WriteLineFormat(3, "}}"); // } // else { this.Writer.WriteLineFormat (3, "set {{ ObjectiveCRuntime.SendMessage({0}, \"{1}\", value); }}", propertyEntity.Static ? classEntity.Name + "." + classEntity.Name + "Class" : "this", "" + propertyEntity.Setter.Selector); } } this.Writer.WriteLineFormat (2, "}}"); } else { this.Writer.WriteLineFormat (2, "{{"); // Append getter this.Writer.WriteLineFormat (3, "[ObjectiveCMessage(\"{0}\")]", propertyEntity.Getter.Selector); this.Writer.WriteLineFormat (3, "get;"); // Append setter if (propertyEntity.Setter != null) { this.Writer.WriteLineFormat (3, "[ObjectiveCMessage(\"{0}\")]", propertyEntity.Setter.Selector); this.Writer.WriteLineFormat (3, "set;"); } this.Writer.WriteLineFormat (2, "}}"); } // Append static condition if needed this.AppendEndCondition(propertyEntity); // Update statistics this.Statistics.Properties++; }
private static String GetKeywords(PropertyEntity propertyEntity, bool implementation, bool markedAsNew) { String keywords = String.Empty; if (!implementation) { return keywords; } keywords = "public "; if (markedAsNew) { keywords += "new "; } if (propertyEntity.Static) { keywords += "static "; } else if (!markedAsNew) { keywords += "virtual "; } return keywords; }
/// <summary> /// Parses the specified property element. /// </summary> /// <param name = "propertyElement">The property element.</param> /// <returns></returns> public PropertyEntity Parse(TypedEntity typedEntity, XElement propertyElement) { XElement nameElement = propertyElement.Element("h3"); String name = nameElement.TrimAll(); // Extract the declaration XElement signatureElement = (from el in propertyElement.Elements("div") where (String) el.Attribute("class") == "declaration" select el).FirstOrDefault(); // Extract the abstract XElement abstractElement = (from el in propertyElement.Elements("p") where (String) el.Attribute("class") == "abstract" select el).FirstOrDefault(); //// Extract discussion //XElement discussionElement = (from el in propertyElement.Elements("div") // where (String) el.Attribute("class") == "api discussion" // select el).FirstOrDefault(); // Get the availability XElement availabilityElement = (from el in propertyElement.Elements("div") where (String) el.Attribute("class") == "api availability" select el).FirstOrDefault(); String signature = signatureElement.TrimAll(); List<String> summary = new List<String>(); summary.Add(abstractElement.TrimAll()); //if (discussionElement != null) //{ // foreach (XElement paragraph in discussionElement.Elements("p")) // { // summary.Add(paragraph.TrimAll()); // } //} String minAvailability = availabilityElement.Elements("ul").Elements("li").FirstOrDefault().TrimAll(); minAvailability = CommentHelper.ExtractAvailability(minAvailability); // Extract property's attribute List<String> attributes = new List<String>(); int attributesStart = signature.IndexOf('('); int attributesEnd = signature.IndexOf(')'); if (attributesStart > 0 && attributesEnd > attributesStart) { String attributesAll = signature.Substring(attributesStart + 1, attributesEnd - attributesStart - 1); attributes.AddRange(attributesAll.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries).Select(attr => attr.Trim())); } int typeStart = attributesEnd > 0 ? (attributesEnd + 1) : "@property".Length; int typeEnd = signature.LastIndexOf(name); string returnType = (typeStart > 0 && typeEnd > typeStart) ? signature.Substring(typeStart, typeEnd - typeStart).Trim() : "MISSING"; // Is the property readonly ? bool readOnly = attributes.Contains("readonly"); // Is there an explicit getter String getterSelector = attributes.Find(a => a.Contains("getter")); if (getterSelector != null) { getterSelector = getterSelector.Substring(getterSelector.IndexOf('=') + 1); } else { getterSelector = name; } // Alter the name name = name.UpperCaseFirstLetter(); // Is there an explicit setter String setterSelector = attributes.Find(a => a.Contains("setter")); if (setterSelector != null) { setterSelector = setterSelector.Substring(setterSelector.IndexOf('=') + 1); } else { setterSelector = "set" + name + ":"; } bool isOut, isByRef, isBlock; String type = this.TypeManager.ConvertType(returnType, out isOut, out isByRef, out isBlock, this.Logger); PropertyEntity propertyEntity = new PropertyEntity(); propertyEntity.MinAvailability = minAvailability; propertyEntity.Name = getterSelector.UpperCaseFirstLetter(); propertyEntity.Static = false; propertyEntity.Summary = summary; propertyEntity.Type = type; propertyEntity.Getter = new MethodEntity(); propertyEntity.Getter.Signature = signature; propertyEntity.Getter.Selector = getterSelector; if (readOnly) { propertyEntity.Setter = null; } else { propertyEntity.Setter = new MethodEntity(); propertyEntity.Setter.Signature = signature; propertyEntity.Setter.Selector = setterSelector; } return propertyEntity; }
public PropertyEntity Parse(TypedEntity typedEntity, string name, IEnumerable<XElement> elements) { XElement declarationElement = (from el in elements where el.Name == "div" && el.Attribute("class") != null && el.Attribute("class").Value == "declaration_indent" select el).FirstOrDefault(); XElement discussionElement = (from el in elements where el.Name == "h5" && el.Value.Trim() == "Discussion" select el).FirstOrDefault(); XElement availabilityElement = (from el in elements let term = el.Descendants("dt").FirstOrDefault() let definition = el.Descendants("dd").FirstOrDefault() where el.Name == "dl" && term != null && term.Value.Trim() == "Availability" select definition).FirstOrDefault(); String signature = declarationElement.TrimAll(); // Extract abstract List<String> summary = new List<String>(); IEnumerable<XElement> abstractElements = elements.SkipWhile(el => el.Name != "p").TakeWhile(el => el.Name == "p"); foreach (XElement element in abstractElements) { String line = element.TrimAll(); if (!String.IsNullOrEmpty(line)) { summary.Add(line); } } // Extract discussion if (discussionElement != null) { IEnumerable<XElement> discussionElements = discussionElement.ElementsAfterSelf().TakeWhile(el => el.Name == "p"); foreach (XElement element in discussionElements) { String line = element.TrimAll(); if (!String.IsNullOrEmpty(line)) { summary.Add(line); } } } // Get the availability String minAvailability = "MISSING"; if (availabilityElement != null) { minAvailability = CommentHelper.ExtractAvailability(availabilityElement.TrimAll()); } // Extract property's attribute List<String> attributes = new List<String>(); int attributesStart = signature.IndexOf('('); int attributesEnd = signature.IndexOf(')'); if (attributesStart > 0 && attributesEnd > attributesStart) { String attributesAll = signature.Substring(attributesStart + 1, attributesEnd - attributesStart - 1); attributes.AddRange(attributesAll.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries).Select(attr => attr.Trim())); } int typeStart = attributesEnd > 0 ? (attributesEnd + 1) : "@property".Length; int typeEnd = signature.LastIndexOf(name); string returnType = (typeStart > 0 && typeEnd > typeStart) ? signature.Substring(typeStart, typeEnd - typeStart).Trim() : "MISSING"; // Is the property readonly ? bool readOnly = attributes.Contains("readonly"); // Is there an explicit getter String getterSelector = attributes.Find(a => a.Contains("getter")); if (getterSelector != null) { getterSelector = getterSelector.Substring(getterSelector.IndexOf('=') + 1); } else { getterSelector = name; } // Alter the name name = name.UpperCaseFirstLetter(); // Is there an explicit setter String setterSelector = attributes.Find(a => a.Contains("setter")); if (setterSelector != null) { setterSelector = setterSelector.Substring(setterSelector.IndexOf('=') + 1); } else { setterSelector = "set" + name + ":"; } bool isOut, isByRef, isBlock; String type = this.TypeManager.ConvertType(returnType, out isOut, out isByRef, out isBlock, this.Logger); PropertyEntity propertyEntity = new PropertyEntity(); propertyEntity.MinAvailability = minAvailability; propertyEntity.Name = getterSelector.UpperCaseFirstLetter(); propertyEntity.Static = false; propertyEntity.Summary = summary; propertyEntity.Type = type; propertyEntity.Getter = new MethodEntity(); propertyEntity.Getter.Signature = signature; propertyEntity.Getter.Selector = getterSelector; if (readOnly) { propertyEntity.Setter = null; } else { propertyEntity.Setter = new MethodEntity(); propertyEntity.Setter.Signature = signature; propertyEntity.Setter.Selector = setterSelector; } return propertyEntity; }
/// <summary> /// Parses the specified entity. /// </summary> /// <param name = "entity">The entity.</param> /// <param name = "reader">The reader.</param> public override void Parse(BaseEntity entity, TextReader reader) { ClassEntity classEntity = (ClassEntity)entity; if (classEntity == null) { throw new ArgumentException ("ClassEntity expected", "entity"); } using (XmlTextReader xmlTextReader = new XmlTextReader(reader)) { XElement root = XElement.Load (xmlTextReader); // Get the spec box XElement specElement = (from el in root.Descendants ("div") where (String)el.Attribute ("class") == "spec_sheet_info_box" select el).FirstOrDefault (); if (specElement != null) { // Inherits XElement inheritElement = (from el in specElement.Descendants ("td") let prev = el.ElementsBeforeSelf ("td").FirstOrDefault () where prev != null && (prev.Value.TrimAll () == "Inherits from:" || prev.Value.TrimAll () == "Inherits from:") select el).FirstOrDefault (); if (inheritElement != null) { string hierarchy = inheritElement.TrimAll (); string[] parents = hierarchy.Split (new[] {':'}, StringSplitOptions.RemoveEmptyEntries); classEntity.BaseType = parents [0].Trim (); } // Conforms To XElement conformsElements = (from el in specElement.Descendants ("td") let prev = el.ElementsBeforeSelf ("td").FirstOrDefault () where prev != null && (prev.Value.TrimAll () == "Conforms to:" || prev.Value.TrimAll () == "Conforms to:") select el).FirstOrDefault (); if (conformsElements != null) { List<String> protocols = new List<string> (); foreach (String protocol in conformsElements.TrimAll().Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries)) { if (protocol.Contains ("NSObject") || protocol.Contains ("NSProxy")) { continue; } protocols.Add (protocol.Trim ()); } classEntity.ConformsTo = String.Join (",", protocols.Distinct ().ToArray ()); } } // Functions this.ExtractFunctions (classEntity, root); // Methods this.ExtractMethods (classEntity, root); // Properties this.ExtractProperties (classEntity, root); // Constants this.ExtractConstants (classEntity, root); // Enumerations this.ExtractEnumerations (classEntity, root); } // Extract getter and search for setter List<String> notGetterMethods = this.Settings ["NotGetterMethods"].Split (new []{','}, StringSplitOptions.RemoveEmptyEntries).ToList (); List<MethodEntity> methodModels = new List<MethodEntity> (classEntity.Methods); foreach (MethodEntity methodModel in methodModels) { if (notGetterMethods.Contains (methodModel.Name) || !methodModel.IsGetter) { continue; } classEntity.Methods.Remove (methodModel); MethodEntity getter = methodModel; MethodEntity setter = classEntity.Methods.Find (m => String.Equals ("Set" + getter.Name, m.Name) && String.Equals (m.ReturnType, "void")); if (setter == null) { setter = classEntity.Methods.Find (m => m.IsSetterFor (getter)); } if (setter != null) { classEntity.Methods.Remove (setter); } PropertyEntity property = new PropertyEntity (); property.Name = getter.Name; property.Type = getter.ReturnType; property.Summary = getter.Summary; property.MinAvailability = getter.MinAvailability; property.Static = getter.Static; property.Getter = getter; property.Setter = setter; classEntity.Properties.Add (property); } // Ensure that availability is set on entity. entity.AdjustAvailability (); }
private PropertyEntity ExtractProperty(PropertyDeclaration propertyDeclaration) { PropertyEntity propertyEntity = new PropertyEntity (); propertyEntity.Name = propertyDeclaration.Name; propertyEntity.Static = (propertyDeclaration.Modifier & Modifiers.Static) == Modifiers.Static; // Get the method's comment IEnumerable<Comment> comments = this.GetDocumentationCommentsBefore (propertyDeclaration); AppendComment (propertyEntity, comments); // Extract getter MethodEntity getterEntity = new MethodEntity (); propertyEntity.Getter = getterEntity; // Extract signature from comments Comment signatureComment = comments.FirstOrDefault (c => CommentHelper.IsSignature (c.CommentText.Trim ())); if (signatureComment != null) { getterEntity.Signature = signatureComment.Trim ("Original signature is", "'", ";", "private"); } // Extract selector MethodSelectorExtractor extractor = new MethodSelectorExtractor (getterEntity.Signature); getterEntity.Selector = extractor.Extract (); // Parse the signature for return type MethodSignatureEnumerator signatureEnumerator = new MethodSignatureEnumerator (getterEntity.Signature); if (signatureEnumerator.MoveNext ()) { bool isOut, isByRef, isBlock; propertyEntity.Type = this.TypeManager.ConvertType (signatureEnumerator.Current.TrimAll (), out isOut, out isByRef, out isBlock, this.Logger); } else { propertyEntity.Type = "Id"; } if (propertyDeclaration.HasSetRegion) { MethodEntity setterEntity = new MethodEntity (); setterEntity.Selector = "MISSING"; MethodParameterEntity methodParameterEntity = new MethodParameterEntity (); methodParameterEntity.Name = "value"; methodParameterEntity.Type = propertyEntity.Type; setterEntity.Parameters.Add (methodParameterEntity); setterEntity.ReturnType = "void"; propertyEntity.Setter = setterEntity; } return propertyEntity; }
/// <summary> /// Appends the documentation. /// </summary> private void AppendDocumentation(PropertyEntity propertyEntity) { this.Writer.WriteLineFormat (2, "/// <summary>"); foreach (String line in propertyEntity.Summary) { this.Writer.WriteLineFormat (2, "/// <para>{0}</para>", line.EscapeAll ()); } this.Writer.WriteLineFormat (2, "/// <para>Original signature is '{0}'</para>", propertyEntity.Getter.Signature.EscapeAll ()); this.AppendAvailability (2, propertyEntity); this.Writer.WriteLineFormat (2, "/// </summary>"); }
private static void SynchronizeProperties(DataContext context, PageType pageType, Type type, IList<PropertyEntity> propertyEntities) { var propertyAttributeType = typeof(PropertyAttribute); var requiredAttributeType = typeof(RequiredAttribute); var properties = propertyEntities; var sortOrder = 0; foreach (var propertyInfo in type.GetProperties()) { var attributes = propertyInfo.GetCustomAttributes(true); var propertyAttribute = (PropertyAttribute)attributes.SingleOrDefault(propertyAttributeType.IsInstanceOfType); if (propertyAttribute != null) { var propertyName = propertyInfo.Name; var declaringType = propertyInfo.PropertyType; var propertyTypeId = PropertyType.GetPropertyTypeId(declaringType); if (!propertyAttribute.IsTypeValid(declaringType)) { var notSupportedException = new NotSupportedException(string.Format("The property attribute of '{0}' on pagetype '{1}' ({2}) does not support the propertytype!", propertyName, pageType.Name, type.FullName)); Logger.Write(notSupportedException, Logger.Severity.Critical); throw notSupportedException; } var required = attributes.Count(requiredAttributeType.IsInstanceOfType) > 0; sortOrder++; var property = properties.SingleOrDefault(p => p.Name == propertyName); if (property == null) { property = new PropertyEntity {Name = propertyName}; properties.Add(property); } property.PropertyTypeId = propertyTypeId; property.PageTypeId = pageType.PageTypeId; property.SortOrder = sortOrder; property.Header = propertyAttribute.Header; property.Required = required; // If generic and standard attribute, store generic type as parameter. Required for list types like CollectionProperty. if (declaringType.IsGenericType && propertyAttribute.GetType() == typeof(PropertyAttribute)) { var subType = declaringType.GetGenericArguments()[0]; property.Parameters = subType.FullName + ", " + subType.Assembly.GetName().Name; } else { property.Parameters = propertyAttribute.Parameters; } if (property.PropertyId == 0) { context.Add(property); } var propertyDefinition = Mapper.Map<PropertyEntity, PropertyDefinition>(property); propertyDefinition.TabGroup = propertyAttribute.TabGroup; pageType.Properties.Add(propertyDefinition); } } context.SaveChanges(); }
/// <summary> /// Parses the specified property element. /// </summary> /// <param name = "propertyElement">The property element.</param> /// <returns></returns> public PropertyEntity Parse(TypedEntity typedEntity, XElement propertyElement) { String name = propertyElement.Element ("name").Value; // Rebuild the signature from the documentation String returnType = propertyElement.Element ("type").TrimAll (); bool isStatic = (propertyElement.Attribute ("static").Value == "yes"); bool readable = (propertyElement.Attribute ("readable").Value == "yes"); bool writable = (propertyElement.Attribute ("writable").Value == "yes"); String accessor = String.Empty; if (propertyElement.Attribute("accessor") != null) { accessor = propertyElement.Attribute ("accessor").Value; } // Remove weak modifier if (returnType.StartsWith ("__weak")) { returnType = returnType.Replace ("__weak", String.Empty).TrimAll (); } // Extract brief description IEnumerable<XElement> abstractElements = propertyElement.Element ("briefdescription").Elements ("para"); // Extract for detailed description IEnumerable<XElement> detailsElements = (from el in propertyElement.Element ("detaileddescription").Elements ("para") where !el.Elements ("simplesect").Any () && el.Elements ("parameterlist").Any () && el.Elements ("xrefsect").Any () select el); // Add brief description List<String> summary = new List<String> (); foreach (XElement paragraph in abstractElements) { summary.Add (paragraph.TrimAll ()); } foreach (XElement paragraph in detailsElements) { summary.Add (paragraph.TrimAll ()); } // Recreate the signature StringBuilder signatureBuilder = new StringBuilder (); signatureBuilder.Append ("@property (nonatomic"); if (readable) { if (!writable) { signatureBuilder.Append (",readonly"); } } signatureBuilder.Append (","); signatureBuilder.Append (accessor); signatureBuilder.Append (") "); signatureBuilder.AppendFormat ("{0} {1};", returnType, name); String signature = signatureBuilder.ToString (); String getterSelector = name; // Alter the name name = name.UpperCaseFirstLetter (); String setterSelector = "set" + name + ":"; bool isOut, isByRef, isBlock; String type = this.TypeManager.ConvertType (returnType, out isOut, out isByRef, out isBlock, this.Logger); PropertyEntity propertyEntity = new PropertyEntity (); //propertyEntity.MinAvailability = minAvailability; propertyEntity.Name = getterSelector.UpperCaseFirstLetter (); propertyEntity.Static = isStatic; // Should always be false... propertyEntity.Summary = summary; propertyEntity.Type = type; propertyEntity.Getter = new MethodEntity (); propertyEntity.Getter.Signature = signature; propertyEntity.Getter.Selector = getterSelector; if (readable && !writable) { propertyEntity.Setter = null; } else { propertyEntity.Setter = new MethodEntity (); propertyEntity.Setter.Signature = signature; propertyEntity.Setter.Selector = setterSelector; } return propertyEntity; }