コード例 #1
0
ファイル: MonitorId.cs プロジェクト: urasandesu/Bondage
        public override int GetHashCode()
        {
            var hashCode = default(int);

            hashCode ^= Endpoint == null ? 0 : Endpoint.GetHashCode();
            hashCode ^= AssemblyQualifiedName.GetHashCode();
            return(hashCode);
        }
コード例 #2
0
ファイル: MessageQueueKey.cs プロジェクト: dox0/DotNet471RS3
        public override int GetHashCode()
        {
            if (String.IsNullOrEmpty(this.activityId))
            {
                return(AssemblyQualifiedName.GetHashCode() ^ this.operation.GetHashCode());
            }

            return(AssemblyQualifiedName.GetHashCode() ^ this.operation.GetHashCode() ^ this.activityId.GetHashCode());
        }
コード例 #3
0
        public void GetType_WrongAssemblyVersion_TypeReturned()
        {
            var typeName =
                "Silverback.Tests.Core.TestTypes.Messages.TestEventOne, " +
                "Silverback.Core.Tests, Version=123.123.123.123";

            var type = TypesCache.GetType(typeName);

            type !.AssemblyQualifiedName.Should().Be(typeof(TestEventOne).AssemblyQualifiedName);
        }
コード例 #4
0
        public void GetTypeFromHeader_WrongAssemblyVersion_TypeReturned()
        {
            var headers = new MessageHeaderCollection
            {
                {
                    "x-message-type",
                    "Silverback.Tests.Types.Domain.TestEventOne, Silverback.Tests.Common.Integration, Version=123.123.123.123"
                }
            };

            var type = SerializationHelper.GetTypeFromHeaders(headers);

            type.Should().NotBeNull();
            type !.AssemblyQualifiedName.Should().Be(typeof(TestEventOne).AssemblyQualifiedName);
        }
コード例 #5
0
ファイル: TypeName.cs プロジェクト: xenosl/ShuHai
        private TypeName(string fullyQualifiedName)
        {
            Ensure.Argument.NotNullOrEmpty(fullyQualifiedName, nameof(fullyQualifiedName));

            AssemblyQualifiedName = TrimName(fullyQualifiedName);
            _hashCode             = AssemblyQualifiedName.GetHashCode();

            ParseFullNameAndAssemblyNameFromAssemblyQualifiedName();

            ParseArrayRanksFromFullName(out int arrayBracketIndex);

            ParseDeclareNameAndGenericArgumentsFromFullName(arrayBracketIndex);

            ParseNamespaceAndNameFromDeclareName();
        }
コード例 #6
0
        private string?GetFullTypeName()
        {
            if (AssemblyQualifiedName is null)
            {
                return(null);
            }

            string?fullTypeName = null;

            var parts = AssemblyQualifiedName.Split(',');

            if (parts.Length > 0)
            {
                fullTypeName = parts[0];
            }

            return(fullTypeName);
        }
コード例 #7
0
ファイル: TypeName.cs プロジェクト: NeatWolf/ShuHaiFoundation
        private void ParseFullNameAndAssemblyNameFromAssemblyQualifiedName()
        {
            int delimiterIndex = GetAssemblyDelimiterIndex(AssemblyQualifiedName);

            if (delimiterIndex == 0)
            {
                throw new ArgumentException($"'{AssemblyQualifiedName}' is not a valid type name.");
            }

            if (delimiterIndex > 0)
            {
                FullName     = AssemblyQualifiedName.Substring(0, delimiterIndex).Trim();
                AssemblyName = AssemblyQualifiedName
                               .Substring(delimiterIndex + 1, AssemblyQualifiedName.Length - delimiterIndex - 1).Trim();
            }
            else
            {
                FullName     = AssemblyQualifiedName;
                AssemblyName = null;
            }
        }
コード例 #8
0
        private void ReadVersion2(XPathNavigator nav)
        {
            //read name
            var iter = nav.SelectSingleNode("/PropertyObject/Name");

            if (iter == null)
            {
                throw new XmlSchemaException("Property Object does not contain the proper xml.");
            }

            Name = iter.Value;

            //read display name
            iter = nav.SelectSingleNode("/PropertyObject/DisplayName");
            if (iter != null && String.IsNullOrEmpty(iter.Value) == false)
            {
                DisplayName = iter.Value;
            }
            else
            {
                DisplayName = Name;
            }

            iter = nav.SelectSingleNode("/PropertyObject/Description");
            if (iter != null && String.IsNullOrEmpty(iter.Value) == false)
            {
                Description = iter.Value;
            }
            else
            {
                Description = String.Empty;
            }

            //read if visible
            iter    = nav.SelectSingleNode("/PropertyObject/Visible");
            Visible = true; //default
            if (iter != null && String.IsNullOrEmpty(iter.Value) == false)
            {
                string visibleString = iter.Value;
                bool   tmpVisible;
                if (bool.TryParse(visibleString, out tmpVisible))
                {
                    Visible = tmpVisible;
                }
            }

            //read enum information
            iter = nav.SelectSingleNode("/PropertyObject/IsEnum");
            if (iter != null)
            {
                IsEnum = bool.Parse(iter.Value);
                if (IsEnum)
                {
                    iter = nav.SelectSingleNode("/PropertyObject/EnumInfo");
                    if (iter == null)
                    {
                        throw new XmlSchemaException("Property Object does not contain the proper xml.");
                    }

                    var dataReader = iter.ReadSubtree();
                    dataReader.MoveToContent();
                    dataReader.Read();

                    var serializer = TraceLab.Core.Serialization.XmlSerializerFactory.GetSerializer(typeof(EnumValueCollection), null);
                    EnumInfo = (EnumValueCollection)serializer.Deserialize(dataReader);
                    TypeDescriptor.AddProvider(new EnumValueDescriptionProvider(EnumInfo), EnumInfo);

                    AssemblyQualifiedName = EnumInfo.SourceEnum;
                    Type = AssemblyQualifiedName.Remove(AssemblyQualifiedName.IndexOf(','));
                }
            }

            if (!IsEnum)
            {
                //read data type
                iter = nav.SelectSingleNode("/PropertyObject/ValueType");
                if (iter == null)
                {
                    throw new XmlSchemaException("Property Object does not contain the proper xml.");
                }

                Type valueType = System.Type.GetType(TraceLabSDK.TypeHelper.ConvertOldTypeName(iter.Value));
                if (valueType == null)
                {
                    throw new InvalidOperationException(string.Format("Type {0} does not exist.", iter.Value));
                }

                AssemblyQualifiedName = valueType.GetTraceLabQualifiedName();
                Type = valueType.FullName;

                //read value
                iter = nav.SelectSingleNode("/PropertyObject/Value");
                if (iter == null)
                {
                    throw new XmlSchemaException("Property Object does not contain the proper xml.");
                }
                if (iter.GetAttribute("IsNull", "") != "True")
                {
                    var typeToDeserialize = valueType;
                    if (!string.IsNullOrWhiteSpace(m_actualValueTypeName))
                    {
                        typeToDeserialize = System.Type.GetType(TraceLabSDK.TypeHelper.ConvertOldTypeName(m_actualValueTypeName));
                    }

                    var dataReader = iter.ReadSubtree();
                    dataReader.MoveToContent();
                    dataReader.Read();
                    var serializer = TraceLab.Core.Serialization.XmlSerializerFactory.GetSerializer(typeToDeserialize, null);

                    Value = serializer.Deserialize(dataReader);
                }
                else
                {
                    Value = null;
                }
            }
        }
コード例 #9
0
        public override void Generate(StreamWriter sw, string indent, CodeGenerationOptions opt, GenerationInfo gen_info)
        {
            opt.ContextTypes.Push(this);
            gen_info.TypeRegistrations.Add(new KeyValuePair <string, string>(RawJniName, AssemblyQualifiedName));
            bool is_enum = base_symbol != null && base_symbol.FullName == "Java.Lang.Enum";

            if (is_enum)
            {
                gen_info.Enums.Add(RawJniName.Replace('/', '.') + ":" + Namespace + ":" + JavaSimpleName);
            }
            StringBuilder sb = new StringBuilder();

            foreach (ISymbol isym in Interfaces)
            {
                GenericSymbol gs  = isym as GenericSymbol;
                InterfaceGen  gen = (gs == null ? isym : gs.Gen) as InterfaceGen;
                if (gen != null && gen.IsConstSugar)
                {
                    continue;
                }
                if (sb.Length > 0)
                {
                    sb.Append(", ");
                }
                sb.Append(opt.GetOutputName(isym.FullName));
            }

            string obj_type = null;

            if (base_symbol != null)
            {
                GenericSymbol gs = base_symbol as GenericSymbol;
                obj_type = gs != null && gs.IsConcrete ? gs.GetGenericType(null) : opt.GetOutputName(base_symbol.FullName);
            }

            sw.WriteLine("{0}// Metadata.xml XPath class reference: path=\"{1}\"", indent, MetadataXPathReference);

            if (this.IsDeprecated)
            {
                sw.WriteLine("{0}[ObsoleteAttribute (@\"{1}\")]", indent, this.DeprecatedComment);
            }
            sw.WriteLine("{0}[global::Android.Runtime.Register (\"{1}\", DoNotGenerateAcw=true{2})]", indent, RawJniName, this.AdditionalAttributeString());
            if (this.TypeParameters != null && this.TypeParameters.Any())
            {
                sw.WriteLine("{0}{1}", indent, TypeParameters.ToGeneratedAttributeString());
            }
            string inherits = "";

            if (inherits_object && obj_type != null)
            {
                inherits = ": " + obj_type;
            }
            if (sb.Length > 0)
            {
                if (string.IsNullOrEmpty(inherits))
                {
                    inherits = ": ";
                }
                else
                {
                    inherits += ", ";
                }
            }
            sw.WriteLine("{0}{1} {2}{3}{4}partial class {5} {6}{7} {{",
                         indent,
                         Visibility,
                         needs_new ? "new " : String.Empty,
                         IsAbstract ? "abstract " : String.Empty,
                         IsFinal ? "sealed " : String.Empty,
                         Name,
                         inherits,
                         sb.ToString());
            sw.WriteLine();

            var seen = new HashSet <string> ();

            GenFields(sw, indent + "\t", opt, seen);
            bool haveNested = false;

            foreach (var iface in GetAllImplementedInterfaces()
                     .Except(BaseGen == null
                                                ? new InterfaceGen[0]
                                                : BaseGen.GetAllImplementedInterfaces())
                     .Where(i => i.Fields.Count > 0))
            {
                if (!haveNested)
                {
                    sw.WriteLine();
                    sw.WriteLine("{0}\tpublic static class InterfaceConsts {{", indent);
                    haveNested = true;
                }
                sw.WriteLine();
                sw.WriteLine("{0}\t\t// The following are fields from: {1}", indent, iface.JavaName);
                iface.GenFields(sw, indent + "\t\t", opt, seen);
            }

            if (haveNested)
            {
                sw.WriteLine("{0}\t}}\n", indent);
            }

            foreach (GenBase nest in NestedTypes)
            {
                if (BaseGen != null && BaseGen.ContainsNestedType(nest))
                {
                    if (nest is ClassGen)
                    {
                        (nest as ClassGen).needs_new = true;
                    }
                }
                nest.Generate(sw, indent + "\t", opt, gen_info);
                sw.WriteLine();
            }

            if (HasClassHandle)
            {
                bool requireNew = false;
                for (var bg = BaseGen; bg != null && bg is XmlClassGen; bg = bg.BaseGen)
                {
                    if (bg.HasClassHandle)
                    {
                        requireNew = true;
                        break;
                    }
                }

                opt.CodeGenerator.WriteClassHandle(this, sw, indent, opt, requireNew);
            }

            GenConstructors(sw, indent + "\t", opt);

            GenProperties(sw, indent + "\t", opt);
            GenMethods(sw, indent + "\t", opt);

            if (IsAbstract)
            {
                GenerateAbstractMembers(sw, indent + "\t", opt);
            }

            bool is_char_seq = false;

            foreach (ISymbol isym in Interfaces)
            {
                if (isym is GenericSymbol)
                {
                    GenericSymbol gs = isym as GenericSymbol;
                    if (gs.IsConcrete)
                    {
                        // FIXME: not sure if excluding default methods is a valid idea...
                        foreach (Method m in gs.Gen.Methods.Where(m => !m.IsInterfaceDefaultMethod && !m.IsStatic))
                        {
                            if (m.IsGeneric)
                            {
                                m.GenerateExplicitIface(sw, indent + "\t", opt, gs);
                            }
                        }
                    }
                }
                else if (isym.FullName == "Java.Lang.ICharSequence")
                {
                    is_char_seq = true;
                }
            }

            if (is_char_seq)
            {
                GenCharSequenceEnumerator(sw, indent + "\t", opt);
            }

            sw.WriteLine(indent + "}");

            if (!AssemblyQualifiedName.Contains('/'))
            {
                foreach (InterfaceExtensionInfo nestedIface in GetNestedInterfaceTypes())
                {
                    nestedIface.Type.GenerateExtensionsDeclaration(sw, indent, opt, nestedIface.DeclaringType);
                }
            }

            if (IsAbstract)
            {
                sw.WriteLine();
                GenerateInvoker(sw, indent, opt);
            }
            opt.ContextTypes.Pop();
        }
コード例 #10
0
        public override void Generate(StreamWriter sw, string indent, CodeGenerationOptions opt, GenerationInfo gen_info)
        {
            opt.ContextTypes.Push(this);
            // interfaces don't nest, so generate as siblings
            foreach (GenBase nest in NestedTypes)
            {
                nest.Generate(sw, indent, opt, gen_info);
                sw.WriteLine();
            }

            var staticMethods = Methods.Where(m => m.IsStatic);

            if (Fields.Any() || staticMethods.Any())
            {
                string name = hasManagedName
                                        ? Name.Substring(1) + "Consts"
                                        : Name.Substring(1);
                sw.WriteLine("{0}[Register (\"{1}\"{2}, DoNotGenerateAcw=true)]", indent, RawJniName, this.AdditionalAttributeString());
                sw.WriteLine("{0}public abstract class {1} : Java.Lang.Object {{", indent, name);
                sw.WriteLine();
                sw.WriteLine("{0}\tinternal {1} ()", indent, name);
                sw.WriteLine("{0}\t{{", indent);
                sw.WriteLine("{0}\t}}", indent);

                var  seen          = new HashSet <string> ();
                bool needsClassRef = GenFields(sw, indent + "\t", opt, seen) || staticMethods.Any();
                foreach (var iface in GetAllImplementedInterfaces().OfType <InterfaceGen>())
                {
                    sw.WriteLine();
                    sw.WriteLine("{0}\t// The following are fields from: {1}", indent, iface.JavaName);
                    bool v = iface.GenFields(sw, indent + "\t", opt, seen);
                    needsClassRef = needsClassRef || v;
                }

                foreach (var m in Methods.Where(m => m.IsStatic))
                {
                    opt.CodeGenerator.WriteMethod(m, sw, indent + "\t", opt, this, true);
                }

                if (needsClassRef)
                {
                    sw.WriteLine();
                    opt.CodeGenerator.WriteClassHandle(this, sw, indent + "\t", opt, name);
                }

                sw.WriteLine("{0}}}", indent, Name);
                sw.WriteLine();

                if (!hasManagedName)
                {
                    sw.WriteLine("{0}[Register (\"{1}\"{2}, DoNotGenerateAcw=true)]", indent, RawJniName, this.AdditionalAttributeString());
                    sw.WriteLine("{0}[global::System.Obsolete (\"Use the '{1}' type. This type will be removed in a future release.\")]", indent, name);
                    sw.WriteLine("{0}public abstract class {1}Consts : {1} {{", indent, name);
                    sw.WriteLine();
                    sw.WriteLine("{0}\tprivate {1}Consts ()", indent, name);
                    sw.WriteLine("{0}\t{{", indent);
                    sw.WriteLine("{0}\t}}", indent);
                    sw.WriteLine("{0}}}", indent);
                    sw.WriteLine();
                }
            }

            if (IsConstSugar)
            {
                return;
            }

            GenerateDeclaration(sw, indent, opt);
            if (!AssemblyQualifiedName.Contains('/'))
            {
                GenerateExtensionsDeclaration(sw, indent, opt, null);
            }
            GenerateInvoker(sw, indent, opt);
            GenerateEventHandler(sw, indent, opt);
            opt.ContextTypes.Pop();
        }
コード例 #11
0
ファイル: TypeName.cs プロジェクト: NeatWolf/ShuHaiFoundation
 public override int GetHashCode()
 {
     return(AssemblyQualifiedName.GetHashCode());
 }
コード例 #12
0
 public override int GetHashCode()
 {
     System.Diagnostics.Contracts.Contract.Assert(HasName);
     return(AssemblyQualifiedName.GetHashCode());
 }