Exemplo n.º 1
0
 static void Main(string[] args)
 {
     GenericType<int>.GenericMethod();
     //GenericType<int>.GenericMethod<string>();
     GenericType<int> a = new GenericType<int>();
     a.GenericMethod<string>();
 }
 public TokenRequirements(Generic generic)
 {
     requirementsFor = generic.type;
     genericTypesNeeded = generic.typesNeeded;
     allowSymbols = generic.allowSymbols;
     allNum = generic.allDigits;
     allAlpha = generic.allAlpha;
     sizeMatters = generic.size != -1;
     requiresClosure = generic.requiresClosure;
     size = generic.size;
     genType = generic.genericType;
 }
Exemplo n.º 3
0
        public static int Create(GenericType Rate)
        {
            SqlCommand SQLCmd = new SqlCommand();
            SQLCmd.CommandType = CommandType.StoredProcedure;
            SQLCmd.CommandText = "CreateSalaryRate";
            SQLCmd.Parameters.Add("Name", SqlDbType.NVarChar, 100).Value = Rate.Name;
            SQLCmd.Parameters.Add("Id", SqlDbType.Int).Direction = ParameterDirection.Output;
            BaseDataAccess.OpenConnection(SQLCmd);
            BaseDataAccess.ExecuteNonSelect(SQLCmd);
            BaseDataAccess.CloseConnection();

            return Convert.ToInt32(SQLCmd.Parameters["Id"].Value);
        }
Exemplo n.º 4
0
 public IConfiguration DriverConfigurations <T>(GenericType <T> activeContextHandlerType) where T : IObserver <IActiveContext>
 {
     return(TangFactory.GetTang().NewConfigurationBuilder(
                DriverConfiguration.ConfigurationModule
                .Set(DriverConfiguration.OnDriverStarted, GenericType <ContextStackHandlers> .Class)
                .Set(DriverConfiguration.OnEvaluatorAllocated, GenericType <ContextStackHandlers> .Class)
                .Set(DriverConfiguration.OnContextActive, activeContextHandlerType)
                .Set(DriverConfiguration.OnTaskMessage, GenericType <HelloTaskMessageHandler> .Class)
                .Set(DriverConfiguration.OnTaskCompleted, GenericType <ContextStackHandlers> .Class)
                .Set(DriverConfiguration.OnContextClosed, GenericType <ContextStackHandlers> .Class)
                .Build())
            .Build());
 }
Exemplo n.º 5
0
        private static void TransformGeneric(GenericType type, Func <string, string> typeNameTransformer)
        {
            if (type == null)
            {
                return;
            }

            type.GenericTypeName = typeNameTransformer(type.GenericTypeName);
            foreach (var typeArg in type.Arguments)
            {
                TransformGeneric(typeArg, typeNameTransformer);
            }
        }
        private static void TransformGeneric(GenericType type, Func<string, string> typeNameTransformer)
        {
            if (type == null)
            {
                return;
            }

            type.GenericTypeName = typeNameTransformer(type.GenericTypeName);
            foreach (var typeArg in type.Arguments)
            {
                TransformGeneric(typeArg, typeNameTransformer);
            }
        }
Exemplo n.º 7
0
 internal static XMLSerializableType GetRandom()
 {
     XMLSerializableType result = new()
     {
         Cyle = CycleA.GetRandom(),
         SimpleDataStructure1 = SimpleDataStructure1.GetRandom(),
         GenericInt           = new GenericType <int>()
         {
             TList = new List <int>()
             {
                 21, 22
             },
             TSet = new HashSet <int>()
             {
                 23, 24
             },
             TObject    = 42,
             Enumerable = new ArrayList()
             {
                 25, 26
             },
             TDictionary1 = new Dictionary <string, int>()
             {
                 { "key1", 27 }, { "key2", 28 }
             },
             TDictionary2 = new Dictionary <int, int>()
             {
                 { 29, 30 }, { 31, 32 }
             },
             TEnumerable = new List <int>()
             {
                 27, 28
             },
         },
         GenericSimpleDataStructure1 = new GenericType <SimpleDataStructure1>()
         {
             TList = new List <SimpleDataStructure1>()
             {
                 SimpleDataStructure1.GetRandom(), SimpleDataStructure1.GetRandom()
             },
             TSet = new HashSet <SimpleDataStructure1>()
             {
                 SimpleDataStructure1.GetRandom(), SimpleDataStructure1.GetRandom()
             },
             TDictionary1 = new Dictionary <string, SimpleDataStructure1>()
             {
                 { "key", null }
             },
             TDictionary2 = new Dictionary <int, SimpleDataStructure1>()
             {
                 { 5, SimpleDataStructure1.GetRandom() }, { default, SimpleDataStructure1.GetRandom() }
Exemplo n.º 8
0
        /// <summary>
        /// 获取成员转换函数信息
        /// </summary>
        /// <param name="type">成员类型</param>
        /// <param name="isCustom"></param>
        /// <returns>成员转换函数信息</returns>
        internal static MethodInfo GetMemberMethodInfo(Type type, ref bool isCustom)
        {
            MethodInfo methodInfo = JsonDeSerializer.GetDeSerializeMethod(type);

            if (methodInfo != null)
            {
                return(methodInfo);
            }
            if (type.IsArray)
            {
                return(GenericType.Get(type.GetElementType()).JsonDeSerializeArrayMethod.Method);
            }
            if (type.IsEnum)
            {
                if (type.IsDefined(typeof(FlagsAttribute), false))
                {
                    return((EnumGenericType.Get(type).JsonDeSerializeEnumFlagsDelegate).Method);
                }
                return((EnumGenericType.Get(type).JsonDeSerializeEnumDelegate).Method);
            }
            if (type.IsGenericType)
            {
                Type genericType = type.GetGenericTypeDefinition();
                if (genericType == typeof(Dictionary <,>))
                {
                    return(GenericType2.Get(type.GetGenericArguments()).JsonDeSerializeDictionaryMethod.Method);
                }
                if (genericType == typeof(Nullable <>))
                {
                    return(GetNullable(type).Method);
                }
                if (genericType == typeof(KeyValuePair <,>))
                {
                    return(GenericType2.Get(type.GetGenericArguments()).JsonDeSerializeKeyValuePairMethod.Method);
                }
            }
            if ((methodInfo = GetCustom(type)) != null)
            {
                isCustom = type.IsValueType;
                return(methodInfo);
            }
            if ((methodInfo = GetIEnumerableConstructor(type)) != null)
            {
                return(methodInfo);
            }
            if (type.IsValueType)
            {
                return(StructGenericType.Get(type).JsonDeSerializeStructMethod);
            }
            return(GenericType.Get(type).JsonDeSerializeTypeMethod);
        }
        /// <summary>
        /// Type reference entry.
        ///
        /// (namespace_reference '::')? type_name generic_types?
        /// </summary>
        /// <param name="context"></param>
        public override void EnterType_reference(KryptonParser.Type_referenceContext context)
        {
            // pass if we are a generic attribute reference.
            var attribute = context.generic_attribute_reference();

            if (attribute != null)
            {
                return;
            }

            var parent = _typeReferenceContainers.Peek();

            var name = context.type_name().GetText();
            var ns   = context.namespace_reference()?.GetText() ?? "";

            // if "this" is the namespace we are referencing the local context
            // setting the namespace to nothing will make us look through the active context first
            if (ns == LocalNamespaceToken)
            {
                ns = "";
            }

            var path          = ns.Split(new[] { NamespaceDelimiterToken }, StringSplitOptions.RemoveEmptyEntries);
            var activeContext = _contextStack.Peek();

            // Resolve the member reference
            if (!TryResolveMember(path, name, activeContext, out var member))
            {
                throw new KryptonParserException($"Unable to resolve type {ns} {name}");
            }

            IType type;

            // If we are a generic type...
            var generic = context.generic_types() != null;

            if (generic)
            {
                type = new GenericType(name);
                _typeReferenceContainers.Push((ITypeReferenceContainer)type);
            }
            else
            {
                type = new ConcreteType(name);
            }

            // Create a type reference and add it to our parent.
            var reference = new FormalTypeReference(type, member.Parent);

            parent.AddTypeReference(reference);
        }
Exemplo n.º 10
0
        public static TypeBase MakeGenericInstance(this GenericType genericType, TypeBase genericTemplateType)
        {
            // TODO cache generic instance that are using predefined hlsl types
            var newType = genericTemplateType.DeepClone();

            var genericParameters         = ((IGenerics)genericTemplateType).GenericParameters;
            var genericArguments          = ((IGenerics)newType).GenericArguments;
            var genericInstanceParameters = genericType.Parameters;

            var genericParameterTypes     = new TypeBase[genericParameters.Count];
            var genericBaseParameterTypes = new TypeBase[genericParameters.Count];

            // Look for parameter instance types
            for (int i = 0; i < genericInstanceParameters.Count; i++)
            {
                var genericInstanceParameter = genericInstanceParameters[i];
                if (genericInstanceParameter is TypeBase)
                {
                    var genericInstanceParameterType = (TypeBase)genericInstanceParameter;
                    genericParameterTypes[i]     = genericInstanceParameterType;
                    genericBaseParameterTypes[i] = TypeBase.GetBaseType(genericInstanceParameterType);
                    genericParameters[i]         = genericParameterTypes[i];
                    genericArguments.Add(genericInstanceParameterType);
                }
            }

            // Replace all references to template arguments to their respective generic instance types
            SearchVisitor.Run(
                newType,
                node =>
            {
                var typeInferencer = node as ITypeInferencer;
                if (typeInferencer != null && typeInferencer.TypeInference.Declaration is GenericDeclaration)
                {
                    var genericDeclaration = (GenericDeclaration)typeInferencer.TypeInference.Declaration;
                    var i         = genericDeclaration.Index;
                    var targeType = genericDeclaration.IsUsingBase ? genericBaseParameterTypes[i] : genericParameterTypes[i];

                    if (node is TypeBase)
                    {
                        return(targeType.ResolveType());
                    }
                }

                return(node);
            });


            return(newType);
        }
Exemplo n.º 11
0
        GenericType[] SetTokens(string[] tokenIds)
        {
           var types = new GenericType[tokenIds.Length];
            for (int i = 0; i < tokenIds.Length; i++)
            {
                var id = int.Parse(tokenIds[i]);
                if (id != -1)
                    types[i] = (GenericType)id;
                else
                    types = null;
            }
            return types;

        }
        public void Generic()
        {
            var expected = new TypeParts("GenericType", "ns123", new[]
            {
                new TypeParts("string", "sys"),
                new TypeParts("int"),
                new TypeParts("SomeOtherType", "ns4")
            }.ToImmutableArray);

            var actual = TypePartsParser.Default.Get(GenericType);

            Assert.Equal(expected, actual, TypePartsEqualityComparer.Default);
            Assert.Equal(GenericType.Replace(" ", ""), TypePartsFormatter.Default.Get(actual));
        }
Exemplo n.º 13
0
        public virtual MemberSymbol GetMember(string name)
        {
            if (memberTable.ContainsKey(name))
            {
                return(memberTable[name]);
            }

            if (GenericType?.GetMember(name) is MemberSymbol member)
            {
                return(member);
            }

            return(null);
        }
Exemplo n.º 14
0
        ///// <summary>
        ///// 引用类型解析调用函数信息集合
        ///// </summary>
        //private static readonly AutoCSer.Threading.LockDictionary<Type, MethodInfo> typeMethods = new AutoCSer.Threading.LockDictionary<Type, MethodInfo>();
        ///// <summary>
        ///// 引用类型对象解析函数信息
        ///// </summary>
        //private static readonly MethodInfo typeParseMethod = typeof(Parser).GetMethod("typeParse", BindingFlags.Instance | BindingFlags.NonPublic);
        ///// <summary>
        ///// 获取引用类型解析调用函数信息
        ///// </summary>
        ///// <param name="type">数据类型</param>
        ///// <returns>引用类型解析调用函数信息</returns>
        //public static MethodInfo GetType(Type type)
        //{
        //    MethodInfo method;
        //    if (typeMethods.TryGetValue(type, out method)) return method;
        //    //if (type.GetConstructor(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, nullValue<Type>.Array, null) == null) method = noConstructorMethod.MakeGenericMethod(type);
        //    //else
        //    method = typeParseMethod.MakeGenericMethod(type);
        //    typeMethods.Set(type, method);
        //    return method;
        //}
        /// <summary>
        /// 获取成员转换函数信息
        /// </summary>
        /// <param name="type">成员类型</param>
        /// <param name="isCustom"></param>
        /// <returns>成员转换函数信息</returns>
        internal static MethodInfo GetMemberMethodInfo(Type type, ref bool isCustom)
        {
            MethodInfo methodInfo = Parser.GetParseMethod(type);

            if (methodInfo != null)
            {
                return(methodInfo);
            }
            //if (type.IsArray) return GetArray(type.GetElementType());
            if (type.IsArray)
            {
                return(GenericType.Get(type.GetElementType()).XmlParseArrayMethod);
            }
            if (type.IsEnum)
            {
                return(GetEnum(type));
            }
            if (type.IsGenericType)
            {
                Type genericType = type.GetGenericTypeDefinition();
                if (genericType == typeof(Nullable <>))
                {
                    Type[] parameterTypes = type.GetGenericArguments();
                    //return parameterTypes[0].IsEnum ? GetNullableEnumParse(type, parameterTypes) : GetNullableParse(type, parameterTypes);
                    return(parameterTypes[0].IsEnum ? StructGenericType.Get(parameterTypes[0]).XmlParseNullableEnumMethod : StructGenericType.Get(parameterTypes[0]).XmlParseNullableMethod);
                }
                //if (genericType == typeof(KeyValuePair<,>)) return GetKeyValuePair(type);
                if (genericType == typeof(KeyValuePair <,>))
                {
                    return(GenericType2.Get(type.GetGenericArguments()).XmlParseKeyValuePairMethod);
                }
            }
            if ((methodInfo = GetCustom(type)) != null)
            {
                isCustom = type.IsValueType;
                return(methodInfo);
            }
            //if (type.IsAbstract || type.IsInterface) return typeParser.GetNoConstructorParser(type);
            if ((methodInfo = GetIEnumerableConstructor(type)) != null)
            {
                return(methodInfo);
            }
            if (type.IsValueType)
            {
                return(GetValueType(type));
            }
            //return GetType(type);
            return(GenericType.Get(type).XmlParseTypeMethod);
        }
Exemplo n.º 15
0
        public void TestGenerics()
        {
            // Create the open class<T> which contains a List<T>

            GenericType genericClassArg = new GenericType("T");

            Class openClass = new Class();

            openClass.Name      = "OpenClass";
            openClass.Namespace = "Namespace";
            openClass.DeclaredGenericArguments.Add(genericClassArg);

            TypeSpecifier listType = typeof(List <>);

            Assert.AreEqual(listType.GenericArguments.Count, 1);

            listType.GenericArguments[0] = genericClassArg;

            Method openMethod = new Method("OpenMethod");

            openMethod.ArgumentTypes.Add(listType);
            GraphUtil.ConnectExecPins(openMethod.EntryNode.InitialExecutionPin, openMethod.ReturnNode.ReturnPin);

            openClass.Methods.Add(openMethod);

            // Create the closed class which contains a List<string>

            Class closedClass = new Class();

            closedClass.Name      = "ClosedClass";
            closedClass.Namespace = "Namespace";

            TypeSpecifier closedListType = typeof(List <string>);

            Method closedMethod = new Method("ClosedMethod");

            closedMethod.ArgumentTypes.Add(closedListType);
            GraphUtil.ConnectExecPins(closedMethod.EntryNode.InitialExecutionPin, closedMethod.ReturnNode.ReturnPin);

            closedClass.Methods.Add(closedMethod);

            // Translate the classes

            ClassTranslator translator = new ClassTranslator();

            string openClassTranslated = translator.TranslateClass(openClass);

            string closedClassTranslated = translator.TranslateClass(closedClass);
        }
Exemplo n.º 16
0
        public void SetGenTypes(string genTyps)
        {
            var typeList = new List<GenericType[]>();
            var split = genTyps.Split(',');
            if (split.Length > 0)
            {
                GenericType[] types;
                foreach (var str in split)
                {
                    var eachType = str.Split('/');
                    types = new GenericType[eachType.Length];
                    if (eachType.Length > 0)
                    {
                        for (int i = 0; i < eachType.Length; i++)
                        {
                            var parse = int.Parse(eachType[i]);
                            types[i] = (GenericType)parse;
                        }
                    }
                    else
                    {
                        types = new GenericType[1];
                        types[0] = (GenericType)int.Parse(str);
                    }
                    typeList.Add(types);
                }
            }
            else
            {
                var anotherSplit = genTyps.Split('/');
                if (anotherSplit.Length > 0)
                {
                    GenericType[] gTypes = new GenericType[anotherSplit.Length];
                    for (int i = 0; i < anotherSplit.Length; i++)
                    {
                        var gType = (GenericType)int.Parse(anotherSplit[i]);
                        gTypes[i] = gType;
                    }
                    typeList.Add(gTypes);
                }
                else
                {
                    var lonelyType = new GenericType[1];
                    lonelyType[0] = (GenericType)int.Parse(genTyps);
                }
                typesNeeded = typeList.ToArray();
            }

        }
Exemplo n.º 17
0
        static ITypeContainer CreateABinaryContainerGeneric(
            Type SourceObjectType, byte[] SerializedObject)
        {
            Type g;

            if (!GenericContainersTypeCache.TryGetValue(SourceObjectType, out g))
            {
                Type[] typeArgs = { SourceObjectType };
                g = GenericType.MakeGenericType(typeArgs);
                GenericContainersTypeCache.Add(SourceObjectType, g);
            }
            object o = Activator.CreateInstance(g, SerializedObject);

            return(o as ITypeContainer);
        }
Exemplo n.º 18
0
        public void GenericTypeTest()
        {
            var input = new GenericType <GenericType <int, int>, int>();

            input.FieldOne          = new GenericType <int, int>();
            input.FieldOne.FieldOne = 500;
            input.FieldOne.FieldTwo = 300;
            input.FieldTwo          = 200;

            var output = SerializeDeserialize(input);

            Assert.AreEqual(input.FieldOne.FieldOne, output.FieldOne.FieldOne);
            Assert.AreEqual(input.FieldOne.FieldTwo, output.FieldOne.FieldTwo);
            Assert.AreEqual(input.FieldTwo, output.FieldTwo);
        }
Exemplo n.º 19
0
        private void BuildConstructor(GenericTemplate classType, System.Reflection.ConstructorInfo constructorInfo)
        {
            var args = constructorInfo.GetParameters().Select(
                x => new VarInfo(
                    x.Name,
                    x.ParameterType.FullName == null?
                    GenericType.Get(x.ParameterType.GenericParameterPosition):
                    storage.GetType(ConvertMSILNames(x.ParameterType))
                    )).ToList();

            if (args.All(x => x.Type != null))
            {
                classType.AddConstructor(args);
            }
        }
Exemplo n.º 20
0
        public ConfigurationModuleBuilder BindSetEntry <U, T>(GenericType <U> iface, IParam <T> opt)
            where U : Name <ISet <T> >
        {
            ConfigurationModuleBuilder c = DeepCopy();
            Type ifaceType = typeof(U);

            c.ProcessUse(opt);

            c.FreeParams.Add(ifaceType, opt);
            if (!SetOpts.Contains(opt))
            {
                c.SetOpts.Add(opt);
            }
            return(c);
        }
Exemplo n.º 21
0
        static ITypeContainer CreateATypeContainerGeneric(
            Type SourceObjectType)
        {
            Type g;

            if (!GenericContainersTypeCache.TryGetValue(SourceObjectType, out g))
            {
                Type[] typeArgs = { SourceObjectType };
                g = GenericType.MakeGenericType(typeArgs);
                GenericContainersTypeCache.Add(SourceObjectType, g);
            }
            object o = Activator.CreateInstance(g, SourceObjectType.AssemblyQualifiedName);

            return(o as ITypeContainer);
        }
Exemplo n.º 22
0
 protected override void Validate()
 {
     if (!BaseType.IsInterface)
     {
         throw new InvalidBindingException($"Factory type {BaseType.Name} is not an interface.");
     }
     else if (!GenericType.IsAssignableFrom(ImplementationType))
     {
         throw new InvalidBindingException($"{ImplementationType.Name} is not a subclass of the base type {GenericType.Name}.");
     }
     else if (ImplementationType.IsInterface || ImplementationType.IsAbstract)
     {
         throw new InvalidBindingException($"{ImplementationType.Name} cannot be instantiated, it is either an interface or abstract class.");
     }
 }
Exemplo n.º 23
0
        /// <summary>
        /// 获取成员转换函数信息
        /// </summary>
        /// <param name="type">成员类型</param>
        /// <param name="isCustom">成员类型</param>
        /// <returns>成员转换函数信息</returns>
        internal static MethodInfo GetMemberMethodInfo(Type type, ref bool isCustom)
        {
            MethodInfo methodInfo = Serializer.GetSerializeMethod(type);

            if (methodInfo != null)
            {
                return(methodInfo);
            }
            //if (type.IsArray) return GetArray(type.GetElementType());
            if (type.IsArray)
            {
                Type elementType = type.GetElementType();
                if (elementType.IsValueType && (!elementType.IsGenericType || elementType.GetGenericTypeDefinition() != typeof(Nullable <>)))
                {
                    return(StructGenericType.Get(elementType).JsonSerializeStructArrayMethod);
                }
                return(GenericType.Get(elementType).JsonSerializeArrayMethod);
            }
            //if (type.IsEnum) return GetEnum(type);
            if (type.IsEnum)
            {
                return(GenericType.Get(type).JsonSerializeEnumToStringMethod);
            }
            if (type.IsGenericType)
            {
                Type genericType = type.GetGenericTypeDefinition();
                if (genericType == typeof(Dictionary <,>))
                {
                    return(GetDictionary(type));
                }
                //if (genericType == typeof(Nullable<>)) return GetNullable(type);
                if (genericType == typeof(Nullable <>))
                {
                    return(StructGenericType.Get(type.GetGenericArguments()[0]).JsonSerializeNullableMethod);
                }
                //if (genericType == typeof(KeyValuePair<,>)) return GetKeyValuePair(type);
                if (genericType == typeof(KeyValuePair <,>))
                {
                    return(GenericType2.Get(type.GetGenericArguments()).JsonSerializeKeyValuePairMethod);
                }
            }
            if ((methodInfo = GetCustom(type)) != null)
            {
                isCustom = type.IsValueType;
                return(methodInfo);
            }
            return(GetIEnumerable(type) ?? GetType(type));
        }
Exemplo n.º 24
0
        public ConfigurationModuleBuilder BindConstructor <T, U>(GenericType <T> clazz, GenericType <U> constructor)
            where U : IExternalConstructor <T>
        {
            ConfigurationModuleBuilder c = DeepCopy();

            try
            {
                c.B.BindConstructor <T, U>(clazz, constructor);
            }
            catch (BindException e)
            {
                Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);
                Utilities.Diagnostics.Exceptions.Throw(new ClassHierarchyException("Error in BindConstructor: ", e), LOGGER);
            }
            return(c);
        }
Exemplo n.º 25
0
        static ITypeContainer CreateATypeConverterContainerGeneric(
            Type SourceObjectType, Type SerializationType, object SerializedObject)
        {
            KeyValuePair <Type, Type> k = new KeyValuePair <Type, Type>(SerializationType, SourceObjectType);
            Type g;

            if (!GenericContainersTypeCache.TryGetValue(k, out g))
            {
                Type[] typeArgs = { SerializationType, SourceObjectType };
                g = GenericType.MakeGenericType(typeArgs);
                GenericContainersTypeCache.Add(k, g);
            }
            object o = Activator.CreateInstance(g, SerializedObject);

            return(o as ITypeContainer);
        }
Exemplo n.º 26
0
        public ConfigurationModuleBuilder BindList <U, T>(GenericType <U> iface, IList <string> impl)
            where U : Name <IList <T> >
        {
            ConfigurationModuleBuilder c = DeepCopy();

            try
            {
                ICsInternalConfigurationBuilder b = (ICsInternalConfigurationBuilder)c.B;
                b.BindList(typeof(U), impl);
            }
            catch (BindException ex)
            {
                Utilities.Diagnostics.Exceptions.CaughtAndThrow(new ClassHierarchyException("Error in BindList: " + ex), Level.Error, LOGGER);
            }
            return(c);
        }
Exemplo n.º 27
0
        /// <inheritdoc />
        public override void Visit(GenericType genericType)
        {
            Write(genericType.Name).Write("<");
            for (int i = 0; i < genericType.Parameters.Count; i++)
            {
                var parameter = genericType.Parameters[i];
                if (i > 0)
                {
                    Write(",").WriteSpace();
                }

                VisitDynamic(parameter);
            }

            Write(">");
        }
Exemplo n.º 28
0
 public override void Visit(GenericType type)
 {
     if (IsTextureType(type))
     {
         Write("Texture");
     }
     else if (IsBufferType(type))
     {
         Write("Buffer");
     }
     else
     {
         base.Visit(type);
     }
     ProcessInitialValueStatus = false;
 }
Exemplo n.º 29
0
        public ConfigurationModuleBuilder BindNamedParameter <U, T>(GenericType <U> name, string value)
            where U : Name <T>
        {
            ConfigurationModuleBuilder c = DeepCopy();

            try
            {
                c.B.BindNamedParameter <U, T>(name, value);
            }
            catch (BindException e)
            {
                Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);
                Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new ClassHierarchyException("Error in BindNamedParameter: ", e), LOGGER);
            }
            return(c);
        }
Exemplo n.º 30
0
        public ConfigurationModuleBuilder BindImplementation <U, T>(GenericType <U> iface, GenericType <T> impl)
            where T : U
        {
            ConfigurationModuleBuilder c = DeepCopy();

            try
            {
                c.B.BindImplementation(iface, impl);
            }
            catch (BindException e)
            {
                Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);
                Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new ClassHierarchyException("Error in BindImplementation: ", e), LOGGER);
            }
            return(c);
        }
Exemplo n.º 31
0
 protected virtual void Visit(GenericType <ObjectType> type)
 {
     if (IsTextureType(type))
     {
         Write("Texture");
     }
     else if (IsBufferType(type))
     {
         Write("Buffer");
     }
     else
     {
         Visit((GenericType)type);
     }
     ProcessInitialValueStatus = false;
 }
Exemplo n.º 32
0
        public ConfigurationModuleBuilder BindNamedParameter <U, T>(GenericType <U> iface, GenericType <T> impl)
            where U : Name <T>
        {
            ConfigurationModuleBuilder c = DeepCopy();

            try
            {
                c.B.BindNamedParameter <U, T, T>(iface, impl);
            }
            catch (BindException e)
            {
                Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);
                Utilities.Diagnostics.Exceptions.Throw(new ClassHierarchyException("Error in BindNamedParameter: ", e), LOGGER);
            }
            return(c);
        }
Exemplo n.º 33
0
        ///// <summary>
        ///// object转换调用委托信息集合
        ///// </summary>
        //private static readonly AutoCSer.Threading.LockDictionary<Type, Action<Serializer, object>> objectMethods = new AutoCSer.Threading.LockDictionary<Type, Action<Serializer, object>>();
        ///// <summary>
        ///// 字典转换函数信息
        ///// </summary>
        //private static readonly MethodInfo serializeObjectMethod = typeof(Serializer).GetMethod("serializeObject", BindingFlags.Static | BindingFlags.NonPublic);
        ///// <summary>
        ///// 获取object转换调用委托信息
        ///// </summary>
        ///// <param name="type">真实类型</param>
        ///// <returns>object转换调用委托信息</returns>
        //public static Action<Serializer, object> GetObject(Type type)
        //{
        //    Action<Serializer, object> method;
        //    if (objectMethods.TryGetValue(type, out method)) return method;
        //    method = (Action<Serializer, object>)Delegate.CreateDelegate(typeof(Action<Serializer, object>), serializeObjectMethod.MakeGenericMethod(type));
        //    objectMethods.Set(type, method);
        //    return method;
        //}
        ///// <summary>
        ///// 数组转换调用函数信息集合
        ///// </summary>
        //private static readonly AutoCSer.Threading.LockDictionary<Type, MethodInfo> arrayMethods = new AutoCSer.Threading.LockDictionary<Type, MethodInfo>();
        ///// <summary>
        ///// 字典转换函数信息
        ///// </summary>
        //private static readonly MethodInfo arrayMethod = typeof(Serializer).GetMethod("array", BindingFlags.Instance | BindingFlags.NonPublic);
        ///// <summary>
        ///// 获取数组转换委托调用函数信息
        ///// </summary>
        ///// <param name="type">数组类型</param>
        ///// <returns>数组转换委托调用函数信息</returns>
        //public static MethodInfo GetArray(Type type)
        //{
        //    MethodInfo method;
        //    if (arrayMethods.TryGetValue(type, out method)) return method;
        //    arrayMethods.Set(type, method = arrayMethod.MakeGenericMethod(type));
        //    return method;
        //}
        ///// <summary>
        ///// 字典转换调用函数信息集合
        ///// </summary>
        //private static readonly AutoCSer.Threading.LockDictionary<Type, MethodInfo> dictionaryMethods = new AutoCSer.Threading.LockDictionary<Type, MethodInfo>();
        ///// <summary>
        ///// 字典转换函数信息
        ///// </summary>
        //private static readonly MethodInfo dictionaryMethod = typeof(Serializer).GetMethod("dictionary", BindingFlags.Instance | BindingFlags.NonPublic);
        ///// <summary>
        ///// 字符串字典转换函数信息
        ///// </summary>
        //private static readonly MethodInfo stringDictionaryMethod = typeof(Serializer).GetMethod("stringDictionary", BindingFlags.Instance | BindingFlags.NonPublic);
        /// <summary>
        /// 获取字典转换委托调用函数信息
        /// </summary>
        /// <param name="type">枚举类型</param>
        /// <returns>字典转换委托调用函数信息</returns>
        public static MethodInfo GetDictionary(Type type)
        {
            Type[] types = type.GetGenericArguments();
            if (types[0] == typeof(string))
            {
                return(GenericType.Get(types[1]).JsonSerializeStringDictionaryMethod);
            }
            return(GenericType2.Get(types).JsonSerializeDictionaryMethod);

            //MethodInfo method;
            //if (dictionaryMethods.TryGetValue(type, out method)) return method;
            //Type[] types = type.GetGenericArguments();
            //if (types[0] == typeof(string)) method = stringDictionaryMethod.MakeGenericMethod(types[1]);
            //else method = dictionaryMethod.MakeGenericMethod(types);
            //dictionaryMethods.Set(type, method);
            //return method;
        }
Exemplo n.º 34
0
        public ConfigurationModuleBuilder BindSetEntry <U, V, T>(GenericType <U> iface, GenericType <V> impl)
            where U : Name <ISet <T> >
            where V : T
        {
            ConfigurationModuleBuilder c = DeepCopy();

            try
            {
                c.B.BindSetEntry <U, V, T>(iface, impl);
            }
            catch (BindException ex)
            {
                Utilities.Diagnostics.Exceptions.Caught(ex, Level.Error, LOGGER);
                var e = new ClassHierarchyException("Error in BindSetEntry: " + ex);
                Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
            }
            return(c);
        }
Exemplo n.º 35
0
        public ConfigurationModuleBuilder BindSetEntry <U, T>(GenericType <U> iface, string impl)
            where U : Name <ISet <T> >
        {
            ConfigurationModuleBuilder c = DeepCopy();

            try
            {
                ICsInternalConfigurationBuilder b = (ICsInternalConfigurationBuilder)c.B;
                b.BindSetEntry(typeof(U), impl);
            }
            catch (BindException ex)
            {
                Utilities.Diagnostics.Exceptions.Caught(ex, Level.Error, LOGGER);
                var e = new ClassHierarchyException("Error in BindSetEntry: " + ex);
                Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
            }
            return(c);
        }
Exemplo n.º 36
0
        protected virtual void Visit(GenericType <ObjectType> type)
        {
            var typeName = type.Name.Text;

            if (typeName.Contains("Texture"))
            {
                Write("Texture");
            }
            else if (typeName.Contains("Buffer"))
            {
                Write("Buffer");
            }
            else
            {
                Visit((GenericType)type);
            }
            ProcessInitialValueStatus = false;
        }
Exemplo n.º 37
0
 public Generic(string encoded)
 {
     base.type = TokenType.Generic;
     var split = encoded.Split(':');
     var enumInt = int.Parse(split[0]);
     if (split[1] == "-1")
         identifier = string.Empty;
     else
     {
         identifier = split[1];
         if (identifier == "all")
             allAlpha = true;
     }
     isCompound = bool.Parse(split[2]);
     if (split[3] != "-1")
     {
         SetGenTypes(split[3]);
     }
     this.genericType = (GenericType)enumInt;
     requiresClosure = bool.Parse(split[4]);
     size = int.Parse(split[5]);
     allowSymbols = bool.Parse(split[6]);
 }
Exemplo n.º 38
0
 public void Method(GenericType<GenericType<int>> value)
 {
 }
Exemplo n.º 39
0
 public void Method(GenericType<ComplexType> value)
 {
 }
        public void op_JsonSerialize_object_whenGenericValueType(string expected)
        {
            var example = new GenericType<int>
                              {
                                  Value = 123
                              };

            var actual = example.JsonSerialize();

            Assert.Equal(expected, actual);
        }
        public void op_JsonSerialize_object_whenGenericReferenceTypeNull(string expected)
        {
            var example = new GenericType<AbsoluteUri>
                              {
                                  Value = null
                              };

            var actual = example.JsonSerialize();

            Assert.Equal(expected, actual);
        }
        public void op_JsonSerialize_object_whenGenericNullableTypeDefault(string expected)
        {
            var example = new GenericType<int?>();

            var actual = example.JsonSerialize();

            Assert.Equal(expected, actual);
        }
Exemplo n.º 43
0
 public static void Update(GenericType Type)
 {
     SqlCommand SQLCmd = new SqlCommand();
     SQLCmd.CommandType = CommandType.StoredProcedure;
     SQLCmd.CommandText = "UpdateTransportType";
     SQLCmd.Parameters.Add("Id", SqlDbType.Int).Value = Type.Id;
     SQLCmd.Parameters.Add("Name", SqlDbType.NVarChar, 100).Value = Type.Name;
     BaseDataAccess.OpenConnection(SQLCmd);
     BaseDataAccess.ExecuteNonSelect(SQLCmd);
     BaseDataAccess.CloseConnection();
 }
Exemplo n.º 44
0
 public Result(Statement statement, string answer, GenericType type)
 {
     
 }
Exemplo n.º 45
0
        /// <summary>
        /// Checks the spacing of the tokens within the given generic type token.
        /// </summary>
        /// <param name="root">The document root.</param>
        /// <param name="generic">The generic type token to check.</param>
        private void CheckGenericSpacing(DocumentRoot root, GenericType generic)
        {
            Param.AssertNotNull(root, "root");
            Param.AssertNotNull(generic, "generic");

            // Make sure it contains at least one token.
            if (generic.ChildTokens.Count > 0)
            {
                for (Node<CsToken> tokenNode = generic.ChildTokens.First; tokenNode != null; tokenNode = tokenNode.Next)
                {
                    if (this.Cancel)
                    {
                        break;
                    }

                    // Check whether this token is a generic and if so parse the tokens within
                    // the generic statement.
                    if (tokenNode.Value.CsTokenClass == CsTokenClass.GenericType)
                    {
                        this.CheckGenericSpacing(root, tokenNode.Value as GenericType);
                    }

                    if (!tokenNode.Value.Generated)
                    {
                        switch (tokenNode.Value.CsTokenType)
                        {
                            case CsTokenType.Comma:
                                this.CheckSemicolonAndComma(root, generic.ChildTokens, tokenNode);
                                break;

                            case CsTokenType.OpenParenthesis:
                                this.CheckOpenParen(root, generic.ChildTokens, tokenNode);
                                break;

                            case CsTokenType.CloseParenthesis:
                                this.CheckCloseParen(root, generic.ChildTokens, tokenNode);
                                break;

                            case CsTokenType.OpenSquareBracket:
                                this.CheckOpenSquareBracket(root, generic.ChildTokens, tokenNode);
                                break;

                            case CsTokenType.CloseSquareBracket:
                                this.CheckCloseSquareBracket(root, generic.ChildTokens, tokenNode, true);
                                break;

                            case CsTokenType.WhiteSpace:
                                this.CheckWhitespace(root, tokenNode);
                                break;

                            case CsTokenType.OpenGenericBracket:
                                this.CheckGenericTokenOpenBracket(root, tokenNode);
                                break;

                            case CsTokenType.CloseGenericBracket:
                                this.CheckGenericTokenCloseBracket(root, tokenNode);
                                break;

                            case CsTokenType.PreprocessorDirective:
                                this.CheckPreprocessorSpacing(root, tokenNode.Value);
                                break;

                            case CsTokenType.OperatorSymbol:
                                OperatorSymbol symbol = tokenNode.Value as OperatorSymbol;
                                if (symbol.SymbolType == OperatorType.MemberAccess ||
                                    symbol.SymbolType == OperatorType.QualifiedAlias)
                                {
                                    this.CheckMemberAccessSymbol(root, generic.ChildTokens, tokenNode);
                                }
                                else
                                {
                                    goto default;
                                }

                                break;

                            case CsTokenType.Other:
                            case CsTokenType.EndOfLine:
                                // Ignore these.
                                break;

                            default:
                                // There shouldn't be anything else within a generic type token.
                                Debug.Assert(false);
                                break;
                        }
                    }
                }
            }
        }
Exemplo n.º 46
0
 public Variable(string variableName, string value, GenericType type)
 {
     this.type = type;
     this.variableName = variableName;
     this.value = value;
 }
        private static GenericType ParseGenericType(string normalizedName)
        {
            var curArg = new StringBuilder();
            GenericType root = null;
            GenericType curType = null;

            // Func< Func<Func<int,int>,bool> >
            // Func`1< Func`2< Func`2<System.Int32,System.Int32>, System.Boolean> >
            // Func<int,bool,int>
            for (var i = 0; i < normalizedName.Length; i++)
            {
                if (normalizedName[i] == '<')
                {
                    if (curType == null)
                    {
                        curType = new GenericType(curArg.ToString(), null);
                        root = curType;
                    }
                    else
                    {
                        var newGeneric = new GenericType(curArg.ToString(), curType);
                        curType.Arguments.Add(newGeneric);
                        curType = newGeneric;
                    }
                    curArg.Length = 0;
                }
                else if (normalizedName[i] == '>')
                {
                    if (curArg.Length > 0)
                    {
                        curType.Arguments.Add(new GenericType(TypeMapper.ShortToFull(curArg.ToString()), null));
                    }

                    if (curType.Parent != null)
                    {
                        curType = curType.Parent;
                    }
                    curArg.Length = 0;
                }
                else if (normalizedName[i] == ',')
                {
                    if (curArg.Length > 0)
                    {
                        curType.Arguments.Add(new GenericType(TypeMapper.ShortToFull(curArg.ToString()), null));
                    }
                    curArg.Length = 0;
                }
                else
                {
                    curArg.Append(normalizedName[i]);
                }
            }
            return root;
        }
            public GenericType(string typeName, GenericType parent)
            {
                this.GenericTypeName = typeName;

                var idx = typeName.IndexOf('`');
                if (idx != -1)
                {
                    this.GenericTypeName = typeName.Substring(0, idx);
                }
                this.Parent = parent;
            }
 private static void FormatExpandedGeneric(StringBuilder sb, GenericType type)
 {
     sb.Append(type.GenericTypeName);
     if (type.Arguments.Count > 0)
     {
         sb.AppendFormat("`{0}", type.Arguments.Count);
         sb.Append("<");
         for (var i = 0; i < type.Arguments.Count; i++)
         {
             var curGen = type.Arguments[i];
             if (curGen.Arguments.Count > 0)
             {
                 FormatExpandedGeneric(sb, curGen);
             }
             else
             {
                 sb.Append(curGen.GenericTypeName);
             }
             if (i != type.Arguments.Count - 1)
             {
                 sb.Append(',');
             }
         }
         sb.Append(">");
     }
 }