コード例 #1
0
 public static void EnsurePropertyExists(this ProjectRootElement project, string name, string value)
 {
     var existing = project.Properties.Where(
         p => p.Name == name && string.IsNullOrEmpty(p.Condition) && string.IsNullOrEmpty(p.Parent.Condition))
         .FirstOrDefault();
     if (existing == null)
         project.AddProperty(name, value);
 }
コード例 #2
0
        public static QueryProperty Where(this Query query, string expression)
        {
            var property = new WhereQueryProperty(query);
            property.AddOperator(new QueryOperator("$where", string.Format("\" {0} \"", expression)));

            query.AddProperty(property);

            return property;
        }
コード例 #3
0
        public static void AddProperties(this IDictionary<string, object> parms, object o, string prefix = "")
        {
            Debug.Assert(parms != null);
            if (o == null)
                return;

            foreach (var p in o.GetType().GetRuntimeProperties())
                parms.AddProperty(p, o, prefix);
        }
コード例 #4
0
        /// <summary>
        /// Well... I am not super happy with this implementation but
        /// the Congress API allows searching on a subset of the properties json return type.
        /// http://tryit.sunlightfoundation.com/congress
        /// i.e. to search the database you provide an object prototype
        /// this method will receurse an object instance
        /// find all proeprties marked as searchable and add them to a dictionary
        /// said dictionary is then used to construct the correct query string such like this
        /// congress.api.sunlightfoundation.com/bills?query=health&history.house_passage_result=pass&history.senate_passage_result=fail 
        /// which would be all bills passed by the house but rejected by the senate
        /// </summary>
        /// <param name="parms"></param>
        /// <param name="o"></param>
        /// <param name="prefix"></param>
        public static void AddSearchableProperties(this IDictionary<string, object> parms, object o, string prefix = "")
        {
            Debug.Assert(parms != null);
            if (o == null)
                return;

            foreach (var p in o.GetType().GetRuntimeProperties().Where(p => p.GetCustomAttribute<SearchablePropertyAttribute>() != null))
                parms.AddProperty(p, o, prefix);
        }
コード例 #5
0
 /// <summary>
 /// Adds a rewritable property to the <paramref name="typeDef">target type</paramref>.
 /// </summary>
 /// <param name="typeDef">The target type that will hold the newly-created property.</param>
 /// <param name="propertyName">The name of the property itself.</param>
 /// <param name="propertyType">The <see cref="System.Type"/> instance that describes the property type.</param>
 public static void AddProperty(this TypeDefinition typeDef, string propertyName, Type propertyType)
 {
     var module = typeDef.Module;
     var typeRef = module.Import(propertyType);
     typeDef.AddProperty(propertyName, typeRef);
 }
コード例 #6
0
        /// <summary>
        /// Adds a rewritable property to the <paramref name="typeDef">target type</paramref>.
        /// </summary>
        /// <param name="typeDef">The target type that will hold the newly-created property.</param>
        /// <param name="propertyName">The name of the property itself.</param>
        /// <param name="propertyType">The <see cref="TypeReference"/> instance that describes the property type.</param>
        public static void AddProperty(this TypeDefinition typeDef, string propertyName,
            TypeReference propertyType)
        {
            #region Add the backing field
            string fieldName = string.Format("__{0}_backingField", propertyName);
            FieldDefinition actualField = new FieldDefinition(fieldName,
                propertyType, FieldAttributes.Private);

            typeDef.Fields.Add(actualField);
            #endregion

            FieldReference backingField = actualField;
            if (typeDef.GenericParameters.Count > 0)
                backingField = GetBackingField(fieldName, typeDef, propertyType);

            var getterName = string.Format("get_{0}", propertyName);
            var setterName = string.Format("set_{0}", propertyName);

            const MethodAttributes attributes = MethodAttributes.Public | MethodAttributes.HideBySig |
                                                MethodAttributes.SpecialName | MethodAttributes.NewSlot |
                                                MethodAttributes.Virtual;

            ModuleDefinition module = typeDef.Module;
            TypeReference voidType = module.Import(typeof(void));

            // Implement the getter and the setter
            MethodDefinition getter = AddPropertyGetter(propertyType, getterName, attributes, backingField);
            MethodDefinition setter = AddPropertySetter(propertyType, attributes, backingField, setterName, voidType);

            typeDef.AddProperty(propertyName, propertyType, getter, setter);
        }
コード例 #7
0
 public static PropertyStatement Property(this ClassStatement classStatement, string name)
 {
     var propertyStatement = new PropertyStatement(name);
     classStatement.AddProperty(propertyStatement);
     return propertyStatement;
 }
コード例 #8
0
        public static void AddChangedRow(this Excel.Worksheet sheet, Excel.Range changedRange)
        {
            Excel.Range columnRange = null;
            Excel.Range primaryKeyColumnRange = null;
            Excel.Range primaryKeyValueRange = null;
            Excel.Range rowValueRange = null;
            Excel.Range sheetCellsRange = null;
            Excel.Range rowsRange = null;
            Excel.Range colsRange = null;
            Excel.CustomProperty uncommittedChangesProperty = null;
            object rowValue = string.Empty;
            string rowValueDataType = string.Empty;
            string primaryKey = string.Empty;
            string primaryKeyDataType = string.Empty;
            object primaryKeyValue = string.Empty;
            string columnName = string.Empty;
            string xmlString = string.Empty;

            try
            {
                primaryKey = sheet.PrimaryKey();
                columnRange = sheet.Range["A1:CV1"];
                sheetCellsRange = sheet.Cells;
                primaryKeyColumnRange = columnRange.Find(primaryKey, LookAt: Excel.XlLookAt.xlWhole);

                rowsRange = changedRange.Rows;
                colsRange = rowsRange.Columns;
                foreach (Excel.Range row in rowsRange)
                {
                    if (primaryKeyColumnRange != null)
                    {
                        int rowNum = row.Row;
                        int colNum = primaryKeyColumnRange.Column;
                        primaryKeyValueRange = sheetCellsRange[rowNum, colNum] as Excel.Range;

                        if (primaryKeyValueRange != null)
                        {
                            primaryKeyValue = primaryKeyValueRange.Value;
                            primaryKeyDataType = primaryKeyValue.GetType().ToString();

                            foreach (Excel.Range col in colsRange)
                            {
                                colNum = col.Column;
                                columnName = sheet.ColumnName(colNum);
                                rowValueRange = sheetCellsRange[rowNum, col.Column] as Excel.Range;
                                if (rowValueRange != null)
                                {
                                    rowValue = rowValueRange.Value;
                                    rowValueDataType = rowValue.GetType().ToString();

                                    xmlString += "<row key=\"" + primaryKeyValue.ToString() + "\" ";
                                    xmlString += "keydatatype=\"" + primaryKeyDataType + "\" ";
                                    xmlString += "column=\"" + columnName + "\" ";
                                    xmlString += "columndatatype=\"" + rowValueDataType + "\">";
                                    xmlString += rowValue.ToString();
                                    xmlString += "</row>";

                                }
                            }
                        }
                    }
                }

                uncommittedChangesProperty = sheet.GetProperty("UncommittedChanges");
                if (uncommittedChangesProperty == null)
                {
                    uncommittedChangesProperty = sheet.AddProperty("UncommittedChanges", xmlString);
                }
                else
                {
                    uncommittedChangesProperty.Value = uncommittedChangesProperty.Value + xmlString;
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
            finally
            {
                if (uncommittedChangesProperty != null) Marshal.ReleaseComObject(uncommittedChangesProperty);
                if (colsRange != null) Marshal.ReleaseComObject(colsRange);
                if (rowsRange != null) Marshal.ReleaseComObject(rowsRange);
                if (sheetCellsRange != null) Marshal.ReleaseComObject(sheetCellsRange);
                if (rowValueRange != null) Marshal.ReleaseComObject(rowValueRange);
                if (primaryKeyValueRange != null) Marshal.ReleaseComObject(primaryKeyValueRange);
                if (primaryKeyColumnRange != null) Marshal.ReleaseComObject(primaryKeyColumnRange);
            }
        }
コード例 #9
0
        public static void AddChangedRow(this Excel.Worksheet sheet, int col, int row)
        {
            Excel.Range columnRange = null;
            Excel.Range primaryKeyColumnRange = null;
            Excel.Range primaryKeyValueRange = null;
            Excel.Range rowValueRange = null;
            Excel.Range sheetCellRange = null;
            Excel.CustomProperty uncommittedChangesProperty = null;
            string primaryKey = string.Empty;
            string primaryKeyDataType = string.Empty;
            object primaryKeyValue = string.Empty;
            string columnName = string.Empty;
            object rowValue = string.Empty;
            string rowValueDataType = string.Empty;

            try
            {
                primaryKey = sheet.PrimaryKey();
                columnRange = sheet.Range["A1:CV1"];
                sheetCellRange = sheet.Cells;
                rowValueRange = sheetCellRange[row, col] as Excel.Range;
                primaryKeyColumnRange = columnRange.Find(primaryKey);

                if (primaryKeyColumnRange != null)
                {
                    primaryKeyValueRange = sheetCellRange[row, primaryKeyColumnRange.Column] as Excel.Range;
                    if (primaryKeyValueRange != null)
                    {
                        primaryKeyValue = primaryKeyValueRange.Value;
                        primaryKeyDataType = primaryKeyValue.GetType().ToString();
                    }
                }

                columnName = sheet.ColumnName(col);
                if (rowValueRange != null)
                {
                    rowValue = rowValueRange.Value;
                    rowValueDataType = rowValue.GetType().ToString();
                }

                string xmlString = "<row key=\"" + primaryKeyValue.ToString() + "\" ";
                xmlString += "keydatatype=\"" + primaryKeyDataType + "\" ";
                xmlString += "column=\"" + columnName + "\" ";
                xmlString += "columndatatype=\"" + rowValueDataType + "\">";
                xmlString += rowValue.ToString();
                xmlString += "</row>";
                xmlString = stripNonValidXMLCharacters(xmlString);

                uncommittedChangesProperty = sheet.GetProperty("UncommittedChanges");
                if (uncommittedChangesProperty == null)
                {
                    uncommittedChangesProperty = sheet.AddProperty("UncommittedChanges", xmlString);
                }
                else
                {
                    uncommittedChangesProperty.Value = uncommittedChangesProperty.Value + xmlString;
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
            finally
            {

            }
        }
コード例 #10
0
ファイル: DoxType.cs プロジェクト: codaxy/dox
        /// <summary>
        /// Updating the Base-Type information of an Dox.Type object.
        /// In first pars step, the type has just the BaseType reference
        /// identifier. In this step the identifier got replaced by the 
        /// related BaseType name.
        /// </summary>
        /// <param name="type">
        /// A <see cref="Codaxy.Dox.Type"/>
        /// </param>
        /// <param name="baseType">
        /// A <see cref="Codaxy.Dox.Type"/>
        /// </param>
        public static void UpdateBaseType(this Codaxy.Dox.Type type, Codaxy.Dox.Type baseType)
        {
            if (type.BaseTypes != null)
            foreach (String baseRef in type.BaseTypes)
            {
                if (baseRef.Equals(baseType.RefId))			// found
                {
                    // Methods
                    if (baseType.Methods != null){
                        if (type.Methods ==  null)
                            type.Methods = new List<Method>(baseType.Methods);
                        else
                            foreach (Method method in baseType.Methods)
                                    type.AddMethod(method);
                    }
                    // Properties
                    if (baseType.Properties != null){
                        if (type.Properties ==  null)
                            type.Properties = new List<Property>(baseType.Properties);
                        else
                            foreach (Property property in baseType.Properties)
                                    type.AddProperty(property);
                    }
                    // Fields
                    if (baseType.Fields != null){
                        if (type.Fields ==  null)
                            type.Fields = new List<Field>(baseType.Fields);
                        else
                            foreach (Field field in baseType.Fields)
                                    type.AddFiled(field);
                    }
                    // Events
                    if (baseType.Events != null){
                        if (type.Events ==  null)
                            type.Events = new List<Event>(baseType.Events);
                        else
                            foreach (Event _event in baseType.Events)
                                    type.AddEvent(_event);
                    }

                    type.BaseTypes.Remove(baseRef);
                    type.BaseTypes.Add(baseType.Name);
                    break;
                }
            }
        }