private void AppendIndexParameters(StringBuilder sb, MethodBase mtd, TypeNames options) { sb.Append("["); // grab the parameter infos ParameterInfo[] pi = mtd.GetParameters(); // if there are any parms... if (pi.Length != 0) { // for each one... for (int i = 0; i < pi.Length; i++) { // setup the proper spacing and/or separation if (i == 0) { sb.Append(" "); } else { sb.Append(", "); } // get the type and the name AppendTypeName(sb, pi[i].ParameterType, options); sb.Append(" "); sb.Append(pi[i].Name); } sb.Append(" "); } sb.Append("]"); }
string GetVariableDeclaration(SqlType sqlType, bool suppressSize, int?length) { string result = null; if (typeNames == null) { typeNames = new NLite.Data.Schema.Script.Generator.SqlServerScriptGenerator().typeNames; } if (!suppressSize) { result = typeNames.Get(sqlType.DbType); } else if (sqlType.Length > 0 || sqlType.Precision > 0 || sqlType.Scale > 0) { result = typeNames.Get(sqlType.DbType, sqlType.Length, sqlType.Precision, sqlType.Scale); } else { result = typeNames.Get(sqlType.DbType); } if (result == null) { throw new InvalidCastException(string.Format(Res.CastTypeInvalid, sqlType)); } return(result); }
internal void AddTypeName(string typeName, Assembly assem) { // lock is held when this is called Assert.NotNull(typeName, assem); Debug.Assert(typeName.IndexOf(Type.Delimiter) == -1); // This is the simple name, not the full name if (!_typeNames.ContainsKey(assem)) { _typeNames[assem] = new TypeNames(assem, _fullName); } _typeNames[assem].AddTypeName(typeName); string normalizedTypeName = ReflectionUtils.GetNormalizedTypeName(typeName); if (_dict.ContainsKey(normalizedTypeName)) { // A similarly named type, namespace, or module already exists. Type newType = LoadType(assem, GetFullChildName(typeName)); object existingValue = _dict[normalizedTypeName]; TypeTracker existingTypeEntity = existingValue as TypeTracker; if (existingTypeEntity == null) { // Replace the existing namespace or module with the new type Debug.Assert(existingValue is NamespaceTracker); _dict[normalizedTypeName] = MemberTracker.FromMemberInfo(newType); } else { // Unify the new type with the existing type _dict[normalizedTypeName] = TypeGroup.UpdateTypeEntity(existingTypeEntity, ReflectionCache.GetTypeTracker(newType)); } return; } }
public void WriteComponent <T>(int maxCapacity) { string shortName = typeof(T).Name; int repeatCount = 1; while (_types.ContainsValue(shortName)) { shortName = $"{typeof(T).Name}_{repeatCount++}"; } _types.Add(typeof(T), shortName); _writer.Write(nameof(EntryType.ComponentType)); _writer.WriteSpace(); _writer.Write(shortName); _writer.WriteSpace(); _writer.WriteLine(TypeNames.Get(typeof(T))); if (maxCapacity != _worldMaxCapacity && !typeof(T).GetTypeInfo().IsFlagType()) { _writer.Write(nameof(EntryType.ComponentMaxCapacity)); _writer.WriteSpace(); _writer.Write(shortName); _writer.WriteSpace(); _writer.Stream.WriteLine(maxCapacity); } }
public override string ToString() { if (operation == BlockOperation.Comment) { return(" // " + (string)parameter); } else if (operation == BlockOperation.MarkLabel) { return(" " + ((BlockLabel)parameter).Name + ":"); } else if (operation == BlockOperation.DeclareLocal) { return(" local " + TypeNames.GetName(((BlockLocal)parameter).Type)); } else if (operation == BlockOperation.BeginScope) { return(" {"); } else if (operation == BlockOperation.EndScope) { return(" }"); } else { throw new Exception(); } }
/// <summary> /// 任意类型处理 /// </summary> /// <param name="type">类型</param> private void getFullName(Type type) { string value; if (!IsXml && TypeNames.TryGetValue(type, out value)) { NameStream.WriteNotNull(value); } else if (type.IsGenericParameter) { NameStream.SimpleWriteNotNull(type.Name); } else if (type.IsArray) { Array(type, true); } else if (type.IsGenericType) { GenericFullName(type); } else { Type reflectedType = type.ReflectedType; if (reflectedType == null) { NameStream.WriteNotNull(type.Namespace); NameStream.Write('.'); NameStream.SimpleWriteNotNull(type.Name); } else { this.ReflectedType(type, reflectedType); } } }
public static object Convert(object o, Type type) { if ((o != null) && type.IsAssignableFrom(o.GetType())) { return(o); } else if (type == typeof(bool)) { return(ToBool(o)); } else if (type == typeof(double)) { return(ToDouble(o)); } else if (type == typeof(int)) { return(ToInt(o)); } else if (type == typeof(string)) { return(ToString(o)); } else if (type.IsArray) { return(ToArray(o, type)); } else { throw new NotImplementedException( "No conversion to " + TypeNames.GetName(type) + " from " + TypeNames.GetName(o.GetType())); } }
public static object GetMember(object obj, string member, object[] parametersHint, bool throwIfUndefined) { if (obj is IScope) { // FIXME - shouldn't be using exceptions for this try { return(((IScope)obj).GetName(member)); } catch { } } MemberInfo memberInfo = FindMember(obj, member, parametersHint); if (memberInfo == null) { if (throwIfUndefined) { throw new Exception("can't find getable member " + TextEscape.Quote(member) + " in " + TypeNames.GetName(obj.GetType())); } else { return(null); } } if (memberInfo is MethodInfo) { return(new ClrObjectMethodBinding(obj, (MethodInfo)memberInfo)); } else if (memberInfo is PropertyInfo) { return(((PropertyInfo)memberInfo).GetValue(obj, null)); } else if (memberInfo is FieldInfo) { object fieldValue = ((FieldInfo)memberInfo).GetValue(obj); if (fieldValue is Method) { fieldValue = new ObjectMethodBinding(obj, (Method)fieldValue); } return(fieldValue); } else { throw new Exception("can't get " + TypeNames.GetName(memberInfo.GetType())); } }
public ObjectViewHeader GetHeader(object obj) { Array array = (Array)obj; return(new ObjectViewHeader(TypeNames.GetName(obj.GetType()), array.Length > 0, false)); }
public ObjectViewHeader GetHeader(object obj) { IList list = (IList)obj; return(new ObjectViewHeader(TypeNames.GetName(obj.GetType()), list.Count > 0, true)); }
protected override void AppendTypeName(StringBuilder sb, Type cls, TypeNames options) { sb.Append("<span title=\""); base.AppendTypeName(sb, cls, TypeNames.Long); sb.Append("\">"); base.AppendTypeName(sb, cls, options); sb.Append("</span>"); }
public ObjectViewHeader GetHeader(object obj) { IDictionary dictionary = (IDictionary)obj; return(new ObjectViewHeader(TypeNames.GetName(obj.GetType()), dictionary.Count > 0, true)); }
protected virtual bool NodeIsValid(Node node) { if (node == null || node.Name == "(apps)") { return(false); } if (TypeNames != null && !TypeNames.Contains(node.NodeType.Name)) { return(false); } var contentNode = node as GenericContent; try { if (!ShowHiddenPages && ((contentNode != null) && contentNode.Hidden)) { return(false); } } catch (InvalidOperationException) { //"Invalid property access attempt" //The user has only See permission for this node. Changing to Admin account does not //help either, because the node is 'head only' and accessing any of its properties //will throw an invalidoperation exception anyway. return(false); } if (ExpandToContext) { var pathCollection = GetPathCollection(PortalContext.Current.Page.Path).ToList(). Union(GetPathCollection(ContextNode.Path)). Union(GetPathCollection(PortalContext.Current.ContextNodePath)). ToArray(); foreach (var path in pathCollection) { if (node.Path.Equals(path) || IsSiblingPath(path, node.Path)) { return(true); } } if (GetContextChildren) { var parentPath = RepositoryPath.GetParentPath(node.Path); if (parentPath.Equals(PortalContext.Current.ContextNodePath) || parentPath.Equals(ContextNode.Path)) { return(true); } } return(false); } return(true); }
/// <summary> /// Initiate an instance of ExtendedTypeDefinition with the type name /// </summary> /// <param name="typeName"></param> public ExtendedTypeDefinition(string typeName) : this() { if (String.IsNullOrEmpty(typeName)) { throw PSTraceSource.NewArgumentNullException("typeName"); } TypeNames.Add(typeName); }
public override ParseTree Parse(Lexer lexer, ParserState state) { int start = lexer.Position; if (type == null) { throw new Exception(); } if (state.RuntimeState.Runtime.TraceParser) { state.RuntimeState.Runtime.ParseTrace.Enter(this, lexer.CurrentSource(), "User defined node " + TypeNames.GetName(type)); } object instance = NewNode.New(state.RuntimeState, type, null); object parseMethod = MemberNode.GetMember(instance, "Parse", true); object result = CallNode.Call(state.RuntimeState, parseMethod, new object[] { lexer }); if (result == null) { result = ParseTree.Yes; } else if (result is bool) { if ((bool)result) { result = ParseTree.Yes; } else { result = ParseTree.No; } } if (state.RuntimeState.Runtime.TraceParser) { if (result == ParseTree.No) { state.RuntimeState.Runtime.ParseTrace.No(this, lexer.SourceFrom(start)); } else { state.RuntimeState.Runtime.ParseTrace.Yes(this, lexer.SourceFrom(start)); } } return((ParseTree)result); }
public void Update(Vehicle vehicle, DateTime now, decimal pricePerMinute) { TotalVehicles += 1; TotalMembers += 1; TotalWheels += vehicle.NumberOfWheels; TotalCost += (decimal)Math.Round((now - vehicle.CheckinTime).TotalMinutes) * pricePerMinute; TotalUnitsUsed += vehicle.Units; if (!ColorNames.ContainsKey(vehicle.VehicleColorId)) { ColorNames[vehicle.VehicleColorId] = vehicle.Color.Name; } if (!TypeNames.ContainsKey(vehicle.VehicleTypeId)) { TypeNames[vehicle.VehicleTypeId] = vehicle.Type.Type; } // Vehicle Color statistics if (!ColorStatistics.ContainsKey(vehicle.VehicleColorId)) { ColorStatistics[vehicle.VehicleColorId] = 1; } else { ColorStatistics[vehicle.VehicleColorId] += 1; } // Vehicle Type statistics if (!TypeStatistics.ContainsKey(vehicle.VehicleTypeId)) { TypeStatistics[vehicle.VehicleTypeId] = 1; } else { TypeStatistics[vehicle.VehicleTypeId] += 1; } // Vehicle Type & Color statistics if (!TypeColorStatistics.ContainsKey(vehicle.VehicleTypeId)) { TypeColorStatistics[vehicle.VehicleTypeId] = new Dictionary <int, int>(); } var tcs = TypeColorStatistics[vehicle.VehicleTypeId]; if (!tcs.ContainsKey(vehicle.VehicleColorId)) { tcs[vehicle.VehicleColorId] = 1; } else { tcs[vehicle.VehicleColorId] += 1; } }
public static object Not(object a) { if (a is bool) { return(!((bool)a)); } else { throw new NotImplementedException( "No not operator for " + TypeNames.GetName(a.GetType())); } }
public static object Multiply(object a, object b) { if (a is int) { return((int)a * ConvertNode.ToInt(b)); } else { throw new NotImplementedException( "No multiply operator for " + TypeNames.GetName(a.GetType()) + " and " + (b == null ? "null" : TypeNames.GetName(b.GetType()))); } }
private static Exceptionless.Models.Data.StackFrame GenerateStackFrame() { return(new Exceptionless.Models.Data.StackFrame { DeclaringNamespace = Namespaces.Random(), DeclaringType = TypeNames.Random(), Name = MethodNames.Random(), Parameters = new ParameterCollection { new Parameter { Type = "String", Name = "path" } } }); }
/// <summary> /// 根据类型获取代码名称 /// </summary> /// <param name="type">类型</param> /// <returns>代码名称</returns> public static string GetFullName(Type type) { string value; if (TypeNames.TryGetValue(type, out value)) { return(value); } if (type.IsGenericParameter) { return(type.Name); } return(new TypeNameBuilder().GetTypeFullName(type)); }
public StackFrame GenerateStackFrame() { return(new StackFrame { DeclaringNamespace = Namespaces.Random(), DeclaringType = TypeNames.Random(), Name = MethodNames.Random(), Parameters = new ParameterCollection { new Parameter { Type = "String", Name = "path" } } }); }
public ObjectViewHeader GetHeader(object obj) { if (obj == null) { return(new ObjectViewHeader("null", false, false)); } Type type = obj.GetType(); string description = string.Format("({0}) 0x{1:x}", TypeNames.GetName(type), obj.GetHashCode()); bool hasContents = GetFields(type).Length > 0; return(new ObjectViewHeader(description, hasContents, false)); }
public static bool SetMember(object obj, string member, object v, bool throwIfUndefined) { if (obj is IScope) { // FIXME - shouldn't be using exceptions for this try { ((IScope)obj).SetName(member, v); return(true); } catch { return(false); } } MemberInfo memberInfo = FindMember(obj, member, null); if (memberInfo == null) { if (throwIfUndefined) { throw new Exception("can't find setable " + member + " in " + obj.GetType()); } else { return(false); } } if (memberInfo is PropertyInfo) { ((PropertyInfo)memberInfo).SetValue(obj, v, null); } else if (memberInfo is FieldInfo) { ((FieldInfo)memberInfo).SetValue(obj, v); } else { throw new Exception("can't set " + TypeNames.GetName(memberInfo.GetType())); } return(true); }
private void ExportStruct(StreamWriter writer, Type type) { writer.WriteLine("Public Type {0}", type.Name); BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance; FieldInfo[] fields = type.GetFields(bindingFlags); foreach (FieldInfo field in fields) { StringBuilder declaration = new StringBuilder(); Type fieldType; string typeName; MarshalAsAttribute marshalAs = (MarshalAsAttribute)Attribute.GetCustomAttribute(field, typeof(MarshalAsAttribute), false); if (marshalAs != null) { fieldType = GetUnmanagedType(marshalAs.Value); } else { fieldType = field.FieldType; } if (!TypeNames.TryGetValue(fieldType, out typeName)) { typeName = fieldType.Name; } if (marshalAs != null && marshalAs.SizeConst > 0) { if (typeName == "String") { writer.WriteLine("\t{0} As {1} * {2}", field.Name, typeName, marshalAs.SizeConst); } else { writer.WriteLine("\t{0}({1}) As {2}", field.Name, marshalAs.SizeConst, typeName); } } else { writer.WriteLine("\t{0} As {1}", field.Name, typeName); } } writer.WriteLine("End Type"); }
public static bool ToBool(object o) { if (o == null) { return(false); } else if (o is bool) { return((bool)o); } else { throw new NotImplementedException( "No conversion to bool from " + TypeNames.GetName(o.GetType())); } }
/// <summary> /// Constructor for the ExtendedTypeDefinition /// </summary> /// <param name="typeName"></param> /// <param name="viewDefinitions"></param> public ExtendedTypeDefinition(string typeName, IEnumerable <FormatViewDefinition> viewDefinitions) : this() { if (String.IsNullOrEmpty(typeName)) { throw PSTraceSource.NewArgumentNullException("typeName"); } if (viewDefinitions == null) { throw PSTraceSource.NewArgumentNullException("viewDefinitions"); } TypeNames.Add(typeName); foreach (FormatViewDefinition definition in viewDefinitions) { FormatViewDefinition.Add(definition); } }
public void QualifiedNames(string qualifiedName, string moduleName, string typeName, ObjectType objectType) { TypeNames.DeconstructQualifiedName(qualifiedName, out var parts); parts.ModuleName.Should().Be(moduleName); switch (objectType) { case ObjectType.Instance: case ObjectType.Type: parts.MemberNames[0].Should().Be(typeName); break; default: parts.MemberNames.Should().BeEmpty(); break; } parts.ObjectType.Should().Be(objectType); }
private void ExportStruct(StreamWriter writer, Type type) { writer.WriteLine("typedef struct"); writer.WriteLine("{"); BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance; FieldInfo[] fields = type.GetFields(bindingFlags); foreach (FieldInfo field in fields) { StringBuilder declaration = new StringBuilder(); Type fieldType; string typeName; string arrayDeclaration; MarshalAsAttribute marshalAs = (MarshalAsAttribute)Attribute.GetCustomAttribute(field, typeof(MarshalAsAttribute), false); if (marshalAs != null) { fieldType = GetUnmanagedType(marshalAs.Value); } else { fieldType = field.FieldType; } if (!TypeNames.TryGetValue(fieldType, out typeName)) { typeName = fieldType.Name; } if (marshalAs != null && marshalAs.SizeConst > 0) { arrayDeclaration = string.Format("[{0}]", marshalAs.SizeConst); } else { arrayDeclaration = null; } writer.WriteLine("\t{0} {1}{2};", typeName, field.Name, arrayDeclaration); } writer.WriteLine("}} {0};", type.Name); }
public void Apply(Schema model, SchemaFilterContext context) { if (!IsBaseOrSubtype(context.SystemType)) { return; } if (context.SystemType == typeof(TBaseType)) { model.Discriminator = "$type"; model.Properties.Add( "$type", new Schema { Enum = TypeNames.Cast <object>().ToArray(), Type = "string" }); if (model.Required == null) { model.Required = new List <string>(); } model.Required.Add("$type"); foreach (var identifierType in SubTypes) { try { context.SchemaRegistry.GetOrRegister(identifierType); } catch (ArgumentException e) { throw new InvalidOperationException($"Cannot included {identifierType} in schema - see inner exception for details", e); } } } else { var schema = new Schema { Properties = model.Properties, Type = model.Type, Required = model.Required }; model.AllOf = new[] { context.SchemaRegistry.GetOrRegister(typeof(TBaseType)), schema }; model.Extensions["x-ms-client-name"] = context.SystemType.FriendlyId(); model.Extensions["x-ms-discriminator-value"] = context.SystemType.FriendlyId(); model.Properties = null; model.Required = null; model.Type = null; } }
private string GetMethodParamDeclaration(ParameterInfo param) { Type type = param.ParameterType.IsArray ? param.ParameterType.GetElementType() : param.ParameterType; bool isByRef = type.IsByRef || param.IsRetval || param.IsOut; if (type.IsByRef) { type = type.GetElementType(); } if (type.IsSubclassOf(typeof(Enum))) { type = typeof(int); } StringBuilder declaration = new StringBuilder(); string typeName; if (!TypeNames.TryGetValue(type, out typeName)) { typeName = type.Name; } if (type == typeof(StringBuilder)) { declaration.Append(typeName); } else if (isByRef) { declaration.AppendFormat("{0}*", typeName); } else { declaration.AppendFormat("const {0}", typeName); } declaration.AppendFormat(" {0}", param.Name); if (param.ParameterType.IsArray) { declaration.Append("[]"); } return(declaration.ToString()); }
/// <summary> /// Retrieve the return type of the method. note that we can only do so /// on a normal method, not on a ctor. to detect the difference, we check</summary> /// that the parameter is an instanceof MethodInfo.<param name="sb"></param> /// <param name="mi"></param> /// <param name="options"></param> protected virtual void AppendMethodReturnType( StringBuilder sb, MethodInfo mi, TypeNames options ) { AppendTypeName(sb, mi.ReturnType, options); sb.Append(" "); }
/// <summary> /// Retrieves the type of the field, checking for an array type /// </summary> /// <param name="sb"></param> /// <param name="f"></param> /// <param name="options"></param> protected virtual void AppendFieldType( StringBuilder sb, FieldInfo f, TypeNames options ) { // get the base type of the field from the fieldinfo AppendTypeName(sb, f.FieldType, options); sb.Append(" "); }
protected override void AppendTypeName( StringBuilder sb, Type cls, TypeNames options ) { sb.Append("<span title=\""); base.AppendTypeName(sb, cls, TypeNames.Long); sb.Append("\">"); base.AppendTypeName(sb, cls, options); sb.Append("</span>"); }
internal void AddTypeName(string typeName, Assembly assem) { // lock is held when this is called Assert.NotNull(typeName, assem); Debug.Assert(typeName.IndexOf(Type.Delimiter) == -1); // This is the simple name, not the full name if (!_typeNames.ContainsKey(assem)) { _typeNames[assem] = new TypeNames(assem, _fullName); } _typeNames[assem].AddTypeName(typeName); string normalizedTypeName = ReflectionUtils.GetNormalizedTypeName(typeName); if (_dict.ContainsKey(normalizedTypeName)) { // A similarly named type, namespace, or module already exists. Type newType = LoadType(assem, GetFullChildName(typeName)); if (newType != null) { object existingValue = _dict[normalizedTypeName]; TypeTracker existingTypeEntity = existingValue as TypeTracker; if (existingTypeEntity == null) { // Replace the existing namespace or module with the new type Debug.Assert(existingValue is NamespaceTracker); _dict[normalizedTypeName] = MemberTracker.FromMemberInfo(newType); } else { // Unify the new type with the existing type _dict[normalizedTypeName] = TypeGroup.UpdateTypeEntity(existingTypeEntity, ReflectionCache.GetTypeTracker(newType)); } } } }
string GetVariableDeclaration(SqlType sqlType, bool suppressSize, int? length) { string result = null; if (typeNames == null) typeNames = new NLite.Data.Schema.Script.Generator.AccessScriptGenerator().typeNames; if (!suppressSize) result = typeNames.Get(sqlType.DbType); else if (sqlType.Length > 0 || sqlType.Precision > 0 || sqlType.Scale > 0) result = typeNames.Get(sqlType.DbType, sqlType.Length, sqlType.Precision, sqlType.Scale); else result = typeNames.Get(sqlType.DbType); if (result == null) throw new InvalidCastException(string.Format(Res.CastTypeInvalid, sqlType)); return result; }
private void AppendIndexParameters( StringBuilder sb, MethodBase mtd, TypeNames options ) { sb.Append("["); // grab the parameter infos ParameterInfo[] pi = mtd.GetParameters(); // if there are any parms... if (pi.Length != 0) { // for each one... for (int i = 0; i < pi.Length; i++) { // setup the proper spacing and/or separation if (i == 0) sb.Append(" "); else sb.Append(", "); // get the type and the name AppendTypeName(sb, pi[i].ParameterType, options); sb.Append(" "); sb.Append(pi[ i ].Name); } sb.Append(" "); } sb.Append("]"); }
protected virtual void AppendTypeName( StringBuilder sb, Type cls, TypeNames options ) { Type baseVar = GetUnderlyingType(cls); String name = null; if ((options & TypeNames.PkgNames) == TypeNames.PkgNames) name = baseVar.FullName; else name = baseVar.Name; if ((options & TypeNames.AbbrPrimitives) == TypeNames.AbbrPrimitives && PrimitiveName(baseVar) != null) name = PrimitiveName(baseVar); if ((options & TypeNames.AbbrPkgNames) == TypeNames.AbbrPkgNames) { int lastPeriod = name.LastIndexOf( '.' ); if (lastPeriod != -1) { String pfx = name.Substring( 0, lastPeriod ); if (pfx.Equals( "System" )) name = name.Substring( lastPeriod + 1 ); } name = AbbreviateName(name, "System.Collections", "S.C"); name = AbbreviateName(name, "System.Security", "S.S"); name = AbbreviateName(name, "System", "S"); name = AbbreviateName(name, "Microsoft", "M"); } sb.Append(name); AppendArrayBrackets(sb, cls); }