private ImmutableDictionary <string, FieldDoc> ExtractFields(Type type, NameInfo typeName, IncludeKind includeKind) { FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance); ImmutableDictionary <string, FieldDoc> dictionary = ImmutableDictionary <string, FieldDoc> .Empty; IEnumerable <ClassInfo> classes = typeName.AsClass; foreach (FieldInfo field in fields) { // Don't emit fields that were just inherited. if (field.DeclaringType != type) { continue; } // Skip compiler-generated fields, which are invisible to both // consumers of the assembly and to the assembly's creator. if (type.Name.StartsWith("<")) { continue; } NameFlags nameFlags = GetVisibilityNameFlags(field); NameInfo fieldName = new NameInfo(classes, field.Name, null, null, nameFlags); dictionary = dictionary.Add(field.Name, new FieldDoc(fieldName)); } return(dictionary); }
public ClassInfo(string name, IEnumerable <string> typeParameters, NameFlags flags) { Name = name ?? string.Empty; TypeParameters = new ReadOnlyCollection <string>(typeParameters != null ? typeParameters.ToArray() : new string[0]); Flags = flags; _stringified = Stringify(); }
public PropertyDoc(NameInfo name, MetaDoc meta = null, IEnumerable <ExceptionDoc> exceptions = null, NameFlags getterFlags = default, NameFlags setterFlags = default) { Name = name ?? throw new ArgumentNullException(nameof(name)); Meta = meta; Exceptions = exceptions.MakeImmutableList(); GetterFlags = getterFlags; SetterFlags = setterFlags; }
public EventDoc(NameInfo name, MetaDoc meta = null, IEnumerable <ExceptionDoc> exceptions = null, NameFlags adderFlags = default, NameFlags removerFlags = default) { Name = name ?? throw new ArgumentNullException(nameof(name)); Meta = meta; Exceptions = exceptions.MakeImmutableList(); AdderFlags = adderFlags; RemoverFlags = removerFlags; }
public NameInfo(IEnumerable <ClassInfo> classes, string name, IEnumerable <string> typeParameters, IEnumerable <ParamInfo> parameters, NameFlags flags) { Classes = new ReadOnlyCollection <ClassInfo>(classes != null ? classes.ToArray() : new ClassInfo[0]); Name = name ?? string.Empty; TypeParameters = new ReadOnlyCollection <string>(typeParameters != null ? typeParameters.ToArray() : new string[0]); Parameters = new ReadOnlyCollection <ParamInfo>(parameters != null ? parameters.ToArray() : new ParamInfo[0]); Flags = flags; _stringified = Stringify(true, false, true); }
private ImmutableDictionary <string, MethodDoc> ExtractMethods(Type type, NameInfo typeName, IncludeKind includeKind) { MethodInfo[] methods = type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance); ImmutableDictionary <string, MethodDoc> dictionary = ImmutableDictionary <string, MethodDoc> .Empty; IEnumerable <ClassInfo> classes = typeName.AsClass; foreach (MethodInfo method in methods) { // Don't emit methods that were just inherited. if (method.DeclaringType != type) { continue; } // Skip compiler-generated methods, which are invisible to both // consumers of the assembly and to the assembly's creator. if (method.Name.StartsWith("<")) { continue; } if (method.IsSpecialName) { continue; } NameFlags nameFlags = GetVisibilityNameFlags(method); List <TypeParameterDoc> typeParameters = null; if (method.IsGenericMethodDefinition) { Type[] genericArgs = method.GetGenericArguments(); typeParameters = genericArgs.Select(t => new TypeParameterDoc(t.Name, null)).ToList(); } string effectiveMethodName = method.Name; List <Tuple <ParamInfo, ParameterDoc> > parameters = GetParameters(method.GetParameters()); NameInfo methodName = new NameInfo(classes, method.Name, typeParameters?.Select(t => t.Name), parameters.Select(p => p.Item1), nameFlags); List <ParameterDoc> parameterDocs = parameters.Select(p => p.Item2).ToList(); dictionary = dictionary.Add(methodName.NameWithParameters, new MethodDoc(methodName, null, typeParameters, parameterDocs, null)); } return(dictionary); }
private ImmutableDictionary <string, MethodDoc> ExtractConstructors(Type type, NameInfo typeName, IncludeKind includeKind) { ConstructorInfo[] constructors = type.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance); ImmutableDictionary <string, MethodDoc> dictionary = ImmutableDictionary <string, MethodDoc> .Empty; IEnumerable <ClassInfo> classes = typeName.AsClass; foreach (ConstructorInfo constructor in constructors) { // Don't emit constructors that were just inherited. if (constructor.DeclaringType != type) { continue; } // Skip compiler-generated constructors, which are invisible to both // consumers of the assembly and to the assembly's creator. if (constructor.Name.StartsWith("<")) { continue; } NameFlags nameFlags = GetVisibilityNameFlags(constructor); List <TypeParameterDoc> typeParameters = null; string effectiveMethodName = constructor.Name; int backtickIndex = effectiveMethodName.IndexOf('`'); if (backtickIndex >= 0) { effectiveMethodName = effectiveMethodName.Substring(0, backtickIndex); } List <Tuple <ParamInfo, ParameterDoc> > parameters = GetParameters(constructor.GetParameters()); NameInfo methodName = new NameInfo(classes, effectiveMethodName, typeParameters?.Select(t => t.Name), parameters.Select(p => p.Item1), nameFlags); List <ParameterDoc> parameterDocs = parameters.Select(p => p.Item2).ToList(); dictionary = dictionary.Add(methodName.NameWithParameters, new MethodDoc(methodName, null, typeParameters, parameterDocs, null)); } return(dictionary); }
private static NameFlags GetVisibilityNameFlags(FieldInfo fieldInfo) { NameFlags nameFlags = 0; if (fieldInfo.IsLiteral) { nameFlags |= NameFlags.Const; } if (fieldInfo.IsInitOnly) { nameFlags |= NameFlags.ReadOnly; } if (fieldInfo.IsStatic) { nameFlags |= NameFlags.Static; } if (fieldInfo.IsAssembly) { nameFlags |= NameFlags.Internal; } if (fieldInfo.IsPrivate) { nameFlags |= NameFlags.Private; } if (fieldInfo.IsPublic) { nameFlags |= NameFlags.Public; } if (fieldInfo.IsFamily) { nameFlags |= NameFlags.Protected; } if (fieldInfo.IsFamilyOrAssembly) { nameFlags |= NameFlags.Protected | NameFlags.Internal; } if (fieldInfo.IsFamilyAndAssembly) { nameFlags |= NameFlags.Private | NameFlags.Protected; } return(nameFlags); }
// name-part ::= '#' NAME | "##" NAME | hashed-name // hashed-name ::= NAME | NAME '#' hashed-name private string ParseNamePart(out NameFlags flags) { switch (_lexer.Next()) { case NameTokenKind.Sharp: Expect(NameTokenKind.Name, "Missing ctor or other special name after '#'"); flags = NameFlags.SpecialName; if (_lexer.Token.Text == "ctor") { flags |= NameFlags.Constructor; } return("#" + _lexer.Token.Text); case NameTokenKind.DoubleSharp: Expect(NameTokenKind.Name, "Missing ctor or other special name after '##'"); flags = NameFlags.SpecialName; if (_lexer.Token.Text == "ctor") { flags |= NameFlags.ClassConstructor | NameFlags.Static; } return("##" + _lexer.Token.Text); case NameTokenKind.Name: string name = _lexer.Token.Text; flags = 0; while (_lexer.Next() == NameTokenKind.Sharp) { Expect(NameTokenKind.Name, "Missing namespace/interface name after '#'"); name = name + "#" + _lexer.Token.Text; flags = NameFlags.SpecialName | NameFlags.ExplicitInterfaceImplementation; } _lexer.Unget(); return(name); default: _lexer.Unget(); Expect(NameTokenKind.Name, "Missing class or method name"); flags = default; return(null); } }
private void ReceiveCallback(IAsyncResult result) { if (!m_listening) { return; } IPEndPoint remoteEP = null; byte[] buffer; try { buffer = m_client.EndReceive(result, ref remoteEP); } catch (ObjectDisposedException) { return; } catch (SocketException) { return; } // Process buffer if (buffer.Length > NameServicePacketHeader.Length) { NameServicePacketHeader header = new NameServicePacketHeader(buffer, 0); if (header.OpCode == NameServiceOperation.QueryRequest) { NameQueryRequest request = null; try { request = new NameQueryRequest(buffer, 0); } catch { } if (request != null) { if (request.Question.Type == NameRecordType.NB) { string name = NetBiosUtils.GetNameFromMSNetBiosName(request.Question.Name); NetBiosSuffix suffix = (NetBiosSuffix)request.Question.Name[15]; bool nameMatch = String.Equals(name, Environment.MachineName, StringComparison.OrdinalIgnoreCase); if (nameMatch && ((suffix == NetBiosSuffix.WorkstationService) || (suffix == NetBiosSuffix.FileServiceService))) { PositiveNameQueryResponse response = new PositiveNameQueryResponse(); response.Header.TransactionID = request.Header.TransactionID; response.Resource.Name = request.Question.Name; NameFlags nameFlags = new NameFlags(); response.Addresses.Add(m_serverAddress.GetAddressBytes(), nameFlags); byte[] responseBytes = response.GetBytes(); m_client.Send(responseBytes, responseBytes.Length, remoteEP); } } else // NBStat { NodeStatusResponse response = new NodeStatusResponse(); response.Header.TransactionID = request.Header.TransactionID; response.Resource.Name = request.Question.Name; NameFlags nameFlags = new NameFlags(); string name1 = NetBiosUtils.GetMSNetBiosName(Environment.MachineName, NetBiosSuffix.WorkstationService); string name2 = NetBiosUtils.GetMSNetBiosName(Environment.MachineName, NetBiosSuffix.FileServiceService); NameFlags nameFlags3 = new NameFlags(); nameFlags3.WorkGroup = true; string name3 = NetBiosUtils.GetMSNetBiosName(WorkgroupName, NetBiosSuffix.WorkstationService); response.Names.Add(name1, nameFlags); response.Names.Add(name2, nameFlags); response.Names.Add(name3, nameFlags3); byte[] responseBytes = response.GetBytes(); try { m_client.Send(responseBytes, responseBytes.Length, remoteEP); } catch (ObjectDisposedException) { } } } } } try { m_client.BeginReceive(ReceiveCallback, null); } catch (ObjectDisposedException) { } catch (SocketException) { } }
public PropertyDoc WithSetterFlags(NameFlags setterFlags) => new PropertyDoc(Name, Meta, Exceptions, GetterFlags, setterFlags);
public PropertyDoc WithGetterFlags(NameFlags getterFlags) => new PropertyDoc(Name, Meta, Exceptions, getterFlags, SetterFlags);
private ImmutableDictionary <string, PropertyDoc> ExtractProperties(Type type, NameInfo typeName, IncludeKind includeKind) { PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance); ImmutableDictionary <string, PropertyDoc> dictionary = ImmutableDictionary <string, PropertyDoc> .Empty; IEnumerable <ClassInfo> classes = typeName.AsClass; foreach (PropertyInfo property in properties) { // Don't emit properties that were just inherited. if (property.DeclaringType != type) { continue; } // Skip compiler-generated properties, which are invisible to both // consumers of the assembly and to the assembly's creator. if (type.Name.StartsWith("<")) { continue; } NameFlags getterFlags = GetVisibilityNameFlags(property.GetGetMethod()); NameFlags setterFlags = GetVisibilityNameFlags(property.GetSetMethod()); NameFlags nameFlags = (getterFlags | setterFlags) & (NameFlags.Static | NameFlags.Abstract | NameFlags.Virtual | NameFlags.New); if (property.Name.StartsWith("#")) { nameFlags |= NameFlags.SpecialName; } else if (property.Name.Contains("#")) { nameFlags |= NameFlags.ExplicitInterfaceImplementation; } if (((getterFlags | setterFlags) & NameFlags.AllVisibilities) >= NameFlags.Public) { nameFlags |= NameFlags.Public; } else if (((getterFlags | setterFlags) & NameFlags.AllVisibilities) >= NameFlags.Internal) { nameFlags |= NameFlags.Internal; } else if (((getterFlags | setterFlags) & NameFlags.AllVisibilities) >= NameFlags.Protected) { nameFlags |= NameFlags.Protected; } else if (((getterFlags | setterFlags) & NameFlags.AllVisibilities) >= NameFlags.Private) { nameFlags |= NameFlags.Private; } NameInfo propertyName = new NameInfo(classes, property.Name, null, null, nameFlags); dictionary = dictionary.Add(property.Name, new PropertyDoc(propertyName, getterFlags: getterFlags, setterFlags: setterFlags)); } return(dictionary); }
private ImmutableDictionary <string, EventDoc> ExtractEvents(Type type, NameInfo typeName, IncludeKind includeKind) { EventInfo[] events = type.GetEvents(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance); ImmutableDictionary <string, EventDoc> dictionary = ImmutableDictionary <string, EventDoc> .Empty; IEnumerable <ClassInfo> classes = typeName.AsClass; foreach (EventInfo @event in events) { // Don't emit events that were just inherited. if (@event.DeclaringType != type) { continue; } // Skip compiler-generated events, which are invisible to both // consumers of the assembly and to the assembly's creator. if (type.Name.StartsWith("<")) { continue; } NameFlags adderFlags = GetVisibilityNameFlags(@event.GetAddMethod()); NameFlags removerFlags = GetVisibilityNameFlags(@event.GetRemoveMethod()); NameFlags nameFlags = (adderFlags | removerFlags) & (NameFlags.Static | NameFlags.Abstract | NameFlags.Virtual | NameFlags.New); if (@event.Name.StartsWith("#")) { nameFlags |= NameFlags.SpecialName; } else if (@event.Name.Contains("#")) { nameFlags |= NameFlags.ExplicitInterfaceImplementation; } if (((adderFlags | removerFlags) & NameFlags.AllVisibilities) >= NameFlags.Public) { nameFlags |= NameFlags.Public; } else if (((adderFlags | removerFlags) & NameFlags.AllVisibilities) >= NameFlags.Internal) { nameFlags |= NameFlags.Internal; } else if (((adderFlags | removerFlags) & NameFlags.AllVisibilities) >= NameFlags.Protected) { nameFlags |= NameFlags.Protected; } else if (((adderFlags | removerFlags) & NameFlags.AllVisibilities) >= NameFlags.Private) { nameFlags |= NameFlags.Private; } NameInfo eventName = new NameInfo(classes, @event.Name, null, null, nameFlags); dictionary = dictionary.Add(@event.Name, new EventDoc(eventName, adderFlags: adderFlags, removerFlags: removerFlags)); } return(dictionary); }
public EventDoc WithRemoverFlags(NameFlags removerFlags) => new EventDoc(Name, Meta, Exceptions, AdderFlags, removerFlags);
public EventDoc WithAdderFlags(NameFlags adderFlags) => new EventDoc(Name, Meta, Exceptions, adderFlags, RemoverFlags);